virtual void doRequest( const char *rq, // the full request string url, // set these and return them: string& responseMsg, int& responseCode, vector<string>& headers, // if completely empty, content-type: text/html will be added const SockAddr &from ) { //out() << "url [" << url << "]" << endl; if ( url.size() > 1 ) { if ( ! allowed( rq , headers, from ) ){ responseCode = 401; responseMsg = "not allowed\n"; return; } handleRESTRequest( rq , url , responseMsg , responseCode , headers ); return; } responseCode = 200; stringstream ss; ss << "<html><head><title>"; string dbname; { stringstream z; z << "mongodb " << getHostName() << ':' << mongo::cmdLine.port << ' '; dbname = z.str(); } ss << dbname << "</title></head><body><h2>" << dbname << "</h2><p>\n<pre>"; doUnlockedStuff(ss); int n = 2000; Timer t; while ( 1 ) { if ( !dbMutex.info().isLocked() ) { { readlock lk(""); ss << "time to get dblock: " << t.millis() << "ms\n"; doLockedStuff(ss); } break; } sleepmillis(1); if ( --n < 0 ) { ss << "\n<b>timed out getting dblock</b>\n"; break; } } ss << "</pre></body></html>"; responseMsg = ss.str(); // we want to return SavedContext from before the authentication was performed if ( ! allowed( rq , headers, from ) ){ responseCode = 401; responseMsg = "not allowed\n"; return; } }
virtual void doRequest( const char *rq, // the full request string url, // set these and return them: string& responseMsg, int& responseCode, vector<string>& headers, // if completely empty, content-type: text/html will be added const SockAddr &from ) { //out() << "url [" << url << "]" << endl; if ( url.size() > 1 ) { if ( url.find( "/_status" ) == 0 ){ if ( ! allowed( rq , headers, from ) ){ responseCode = 401; responseMsg = "not allowed\n"; return; } generateServerStatus( url , responseMsg ); responseCode = 200; return; } if ( ! cmdLine.rest ){ responseCode = 403; responseMsg = "rest is not enabled. use --rest to turn on"; return; } if ( ! allowed( rq , headers, from ) ){ responseCode = 401; responseMsg = "not allowed\n"; return; } handleRESTRequest( rq , url , responseMsg , responseCode , headers ); return; } responseCode = 200; stringstream ss; ss << "<html><head><title>"; string dbname; { stringstream z; z << "mongodb " << getHostName() << ':' << mongo::cmdLine.port << ' '; dbname = z.str(); } ss << dbname << "</title></head><body><h2>" << dbname << "</h2><p>\n<pre>"; doUnlockedStuff(ss); { Timer t; readlocktry lk( "" , 2000 ); if ( lk.got() ){ ss << "time to get dblock: " << t.millis() << "ms\n"; doLockedStuff(ss); } else { ss << "\n<b>timed out getting dblock</b>\n"; } } ss << "</pre></body></html>"; responseMsg = ss.str(); // we want to return SavedContext from before the authentication was performed if ( ! allowed( rq , headers, from ) ){ responseCode = 401; responseMsg = "not allowed\n"; return; } }