summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/miniwebserver.cpp20
-rw-r--r--util/miniwebserver.h1
2 files changed, 20 insertions, 1 deletions
diff --git a/util/miniwebserver.cpp b/util/miniwebserver.cpp
index 4b4a1ad70f7..77c44dfc396 100644
--- a/util/miniwebserver.cpp
+++ b/util/miniwebserver.cpp
@@ -20,6 +20,8 @@
#include "stdafx.h"
#include "miniwebserver.h"
+#include <pcrecpp.h>
+
namespace mongo {
MiniWebServer::MiniWebServer() {
@@ -167,7 +169,23 @@ namespace mongo {
::send(s, response.c_str(), response.size(), 0);
}
-
+
+ string MiniWebServer::getHeader( const char * req , string wanted ){
+ const char * headers = strstr( req , "\n" );
+ if ( ! headers )
+ return "";
+ pcrecpp::StringPiece input( headers + 1 );
+
+ string name;
+ string val;
+ pcrecpp::RE re("([\\w\\-]+): (.*?)\r?\n");
+ while ( re.Consume( &input, &name, &val) ){
+ if ( name == wanted )
+ return val;
+ }
+ return "";
+ }
+
void MiniWebServer::run() {
SockAddr from;
while ( 1 ) {
diff --git a/util/miniwebserver.h b/util/miniwebserver.h
index d41935bd49f..ac2872276e4 100644
--- a/util/miniwebserver.h
+++ b/util/miniwebserver.h
@@ -42,6 +42,7 @@ namespace mongo {
protected:
string parseURL( const char * buf );
string parseMethod( const char * headers );
+ string getHeader( const char * headers , string name );
void parseParams( map<string,string> & params , string query );
static const char *body( const char *buf );