9 #ifndef __libutilxx__sella__server__HTTPConnection_H__
10 #define __libutilxx__sella__server__HTTPConnection_H__
12 #include "../../common.h"
13 #include "../net/SocketException.h"
14 #include "../net/TCPSocket.h"
15 #include "../net/SecureTCPSocket.h"
16 #include "../util/Time.h"
18 #include "HTTPRequest.h"
19 #include "ServerException.h"
34 typedef std::shared_ptr<HTTPConnection> shared;
36 static const timeval ReceiveTimeoutDefault;
37 static const std::string MIMEFallback;
38 static const std::string ContentTypeDefault;
40 enum Compression : uint8_t { None, Gzip, Deflate };
43 HTTPConnection(
const HTTP &http, sella::net::TCPSocket::shared &socket, timeval tv = ReceiveTimeoutDefault)
throw ();
46 static const HTTPConnection::shared shared_ptr(
const HTTP &http, sella::net::TCPSocket::shared &socket, timeval tv = ReceiveTimeoutDefault)
throw ();
48 const HTTPRequest& getRequest(
void)
throw (ServerException);
49 struct timespec getRuntime(void) const throw ();
50 bool isUsable(
void)
const throw ();
51 bool isSecure(
void)
const throw ();
53 void response(
const std::string &body,
const std::string &contentType = ContentTypeDefault,
bool close =
true)
throw (ServerException);
54 void response(
const std::vector<char> &content,
const std::string &contentType,
bool close =
true)
throw (ServerException);
55 void error(
int code,
const std::string &detail = std::string(),
const std::string &contentType = ContentTypeDefault)
throw (ServerException);
56 void error(
int code,
const std::vector<char> &content,
const std::string &contentType = ContentTypeDefault)
throw (ServerException);
58 void methodOptions(
void)
throw (ServerException);
59 void methodGet(
void)
throw (ServerException);
60 void methodHead(
void)
throw (ServerException);
61 void methodPost(
void)
throw (ServerException);
62 void methodPut(
void)
throw (ServerException);
63 void methodDelete(
void)
throw (ServerException);
64 void methodTrace(
void)
throw (ServerException);
65 void methodConnect(
void)
throw (ServerException);
66 void methodPatch(
void)
throw (ServerException);
71 const char* getSSLLibraryVersion(
void)
const throw ();
72 const char* getActiveProtocol(
void)
const throw ();
73 const char* getActiveCipher(
void)
const throw ();
75 std::string getContentType(HTTPRequest::AcceptType type,
const std::string &fallback = std::string())
const throw ();
77 void clear(
void)
throw ();
81 sella::net::TCPSocket::shared socket;
82 struct timespec start;
85 void response(
int code,
const std::string &body,
const std::string &contentType = ContentTypeDefault,
bool close =
true)
throw (ServerException);
86 void response(
int code,
const std::vector<char> &content,
const std::string &contentType,
bool close =
true)
throw (ServerException);
88 void sendStatusLine(
int code,
const std::string &detail = std::string())
throw (sella::net::SocketException);
89 void sendHeaders(
size_t size,
const std::string &contentType = ContentTypeDefault,
bool close =
true, Compression compression = None)
throw (sella::net::SocketException);
90 void sendBody(
const std::string &body)
throw (sella::net::SocketException);
91 void sendContent(
const std::vector<char> &content)
throw (sella::net::SocketException);
93 void read(std::string &buffer)
throw (ServerException);
94 void chunker(
void)
throw (ServerException);
96 Compression getCompressionType(
const std::string &body,
const std::string &contentType)
const throw ();
97 Compression getCompressionType(
const std::vector<char> &content,
const std::string &contentType)
const throw ();
99 const std::string buildHeaders(
size_t contentSize,
const std::string &contentType = ContentTypeDefault,
bool close =
true,
bool useAllow =
false, Compression compression = None,
const std::string &transferEncoding = std::string())
throw ();
101 void getFileContent(
const std::string &file, std::vector<char> &content, std::string &contentType)
throw (ServerException);
102 size_t getFileSize(std::ifstream &ifile)
throw (ServerException);
103 std::string getErrorBody(
int code,
const std::string &detail = std::string(),
const std::string &callback = std::string())
throw ();