2 #include <ail/string.hpp>
3 #include <ail/zlib.hpp>
4 #include <theodwalha/reply.hpp>
6 http_reply::http_reply():
18 void http_reply::not_found()
21 description
= "Not Found";
24 void http_reply::forbidden()
27 description
= "Forbidden";
30 bool http_reply::get_packet(std::string
& packet
)
34 Date: Tue, 18 Aug 2009 03:14:21 GMT
35 Server: Apache/2.2.11 (Debian) PHP/5.2.9-4 with Suhosin-Patch
36 X-Powered-By: PHP/5.2.9-4
38 Content-Encoding: gzip
40 Keep-Alive: timeout=15, max=100
41 Connection: Keep-Alive
42 Content-Type: text/html
45 std::string
const delimiter
= "\r\n";
47 packet
= std::string();
51 case http_protocol::version_1_1
:
55 case http_protocol::version_1_0
:
60 std::cout
<< "Invalid protocol version specific in the HTTP reply" << std::endl
;
64 packet
+= " " + ail::number_to_string(code
) + " " + description
+ delimiter
;
69 std::string compressed_content
;
70 ail::compress_gzip(content
, compressed_content
);
71 content
= compressed_content
;
73 catch(ail::exception
& exception
)
75 std::cout
<< exception
.get_message() << std::endl
;
77 packet
+= "Content-Encoding: gzip" + delimiter
;
80 packet
+= "Content-Length: " + ail::number_to_string(content
.size()) + delimiter
;
84 packet
+= "Keep-Alive: timeout=" + ail::number_to_string(keep_alive_timeout
) + ", max=" + ail::number_to_string(keep_alive_max
) + delimiter
;
85 packet
+= "Connection: Keep-Alive" + delimiter
;
88 packet
+= "Content-Type: " + content_type
;
90 packet
+= delimiter
+ delimiter
;