MongoDB  2.7.0
miniwebserver.h
1 // miniwebserver.h
2 
3 /* Copyright 2009 10gen Inc.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #pragma once
19 
20 #include "mongo/pch.h"
21 
22 #include "mongo/db/jsobj.h"
23 #include "mongo/util/net/listen.h"
24 #include "mongo/util/net/message.h"
25 #include "mongo/util/net/message_port.h"
26 
27 namespace mongo {
28 
29  class MiniWebServer : public Listener {
30  public:
31  MiniWebServer(const string& name, const string &ip, int _port);
32  virtual ~MiniWebServer() {}
33 
34  virtual void doRequest(
35  const char *rq, // the full request
36  string url,
37  // set these and return them:
38  string& responseMsg,
39  int& responseCode,
40  vector<string>& headers, // if completely empty, content-type: text/html will be added
41  const SockAddr &from
42  ) = 0;
43 
44  // --- static helpers ----
45 
46  static void parseParams( BSONObj & params , string query );
47 
48  static string parseURL( const char * buf );
49  static string parseMethod( const char * headers );
50  static string getHeader( const char * headers , const std::string& name );
51  static const char *body( const char *buf );
52 
53  static string urlDecode(const char* s);
54  static string urlDecode(const std::string& s) {return urlDecode(s.c_str());}
55 
56  private:
57  void accepted(boost::shared_ptr<Socket> psocket, long long connectionId );
58  static bool fullReceive( const char *buf );
59  };
60 
61 } // namespace mongo
BSON classes.
wrapped around os representation of network address
Definition: sock.h:93
Definition: miniwebserver.h:29
Definition: listen.h:35
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary representa...
Definition: bsonobj.h:77