libutil++  1.9.3
 All Classes Functions Variables
HTTPRequest.h
1 /*
2 ** libutil++
3 ** $Id: HTTPRequest.h 1783 2016-11-27 19:17:46Z sella $
4 ** Copyright (c) 2011-2016 Digital Genesis, LLC. All Rights Reserved.
5 ** Released under the LGPL Version 2.1 License.
6 ** http://www.digitalgenesis.com
7 */
8 
9 #ifndef __libutilxx__sella__server__HTTPRequest_H__
10 #define __libutilxx__sella__server__HTTPRequest_H__
11 
12 #include "../../common.h"
13 #include "ServerException.h"
14 
15 #include <memory>
16 #include <string>
17 #include <vector>
18 
19 /* Forward declarations */
20 typedef struct magic_set *magic_t;
21 
22 namespace sella {
23  namespace server {
24  class HTTPRequest;
25  class HTTP;
26  class HTTPConnection;
27  }
28 }
29 
32  public:
33  static const std::string ContentTypeDefault; /* application/octet-stream - RFC 2616 7.2.1 */
34 
35  public:
36  friend class HTTPConnection;
37 
38  enum Method { None, Options, Get, Head, Post, Put, Delete, Trace, Connect, Patch, Extension };
39  enum AcceptType { HTML, Plain, JSON, JSONP, XML, XHTML_XML, CSV, PNG, GIF, JPEG, Icon, Any, Text_Any, Text, Application_Any, Application, Image_Any, Image, Audio_Any, Audio, Other };
40 
41  HTTPRequest(const HTTP &http) throw ();
42  virtual ~HTTPRequest() throw ();
43 
44  void parse(const std::string &buffer) throw (ServerException);
45  void appendBody(const std::string &data) throw (ServerException);
46  void appendBody(const std::vector<char> &data) throw (ServerException);
47 
48  Method getMethod(bool useOverride = true) const throw ();
49  const std::string& getMethodRaw(bool useOverride = true) const throw ();
50  Method getMethodOverride(void) const throw ();
51  const std::string& getMethodOverrideRaw(void) const throw ();
52  const std::string& getURI(void) const throw ();
53  const std::string& getPath(void) const throw ();
54  const std::string& getExtension(void) const throw ();
55  const std::string& getQuery(void) const throw ();
56  const std::string& getVersion(void) const throw ();
57  const std::string& getHost(void) const throw ();
58  const std::string& getUserAgent(void) const throw ();
59  const std::string& getAuthorization(void) const throw ();
60  bool getAuthorizationCredentials(std::string &username, std::string &password) const throw ();
61  const std::vector<std::string>& getAccept(void) const throw ();
62  AcceptType getAcceptType(AcceptType fallback = Other) const throw ();
63  const std::vector<std::string>& getHeaders() const throw ();
64  std::string getHeader(const std::string &header) const throw (ServerException);
65  const std::string getBody(void) const throw ();
66  const std::vector<char>& getContent(void) const throw ();
67 
68  bool isContinue(void) const throw ();
69  bool isChunked(void) const throw ();
70  bool isAcceptGzip(void) const throw ();
71  bool isAcceptDeflate(void) const throw ();
72  bool isBasicAuthorization(void) const throw ();
73 
74  bool hasHeader(const std::string &header) const throw (ServerException);
75 
76  bool empty(void) const throw ();
77  void clear(void) throw ();
78 
79  std::string str(void) const throw ();
80  void print(void) const throw ();
81 
82  protected:
83  std::string getFullpath(const std::string &file = std::string()) throw (ServerException);
84  std::string getMIMEType(const std::string &file, const std::string &fallback = std::string()) const throw (ServerException);
85  std::string getMIMEType(const std::string &buffer, size_t size, const std::string &fallback = std::string()) const throw (ServerException);
86 
87  bool isDirectory(const std::string &path) const throw ();
88  bool isFile(const std::string &file) const throw ();
89 
90  void magic_open(magic_t &magic) const throw (ServerException);
91  void magic_close(magic_t &magic) const throw ();
92 
93  private:
94  const HTTP &http;
95  Method method;
96  std::string methodRaw;
97  Method methodOverride;
98  std::string methodOverrideRaw;
99  std::string uri;
100  std::string path;
101  std::string extension;
102  std::string query;
103  std::string version;
104  std::vector<std::string> headers;
105 
106  std::string host;
107  std::string userAgent;
108  std::vector<std::string> accept;
109  std::vector<std::string> acceptCharset;
110  std::vector<std::string> acceptEncoding;
111  std::vector<std::string> acceptLanguage;
112  std::string transferEncoding;
113  std::string authorization;
114  std::string connection;
115  std::string cacheControl;
116  std::string expect;
117  std::string contentType;
118  unsigned long long contentLength;
119 
120  std::vector<char> content;
121 };
122 
123 #endif
124 
125 /*
126 ** vim: noet ts=3 sw=3
127 */
Definition: String.cpp:34