Changed Request::remote_endpoint_address to std::string. Modified parse_request too keep case of header parameters.
This commit is contained in:
parent
5f34b5db5e
commit
2177e330b7
4 changed files with 20 additions and 23 deletions
|
|
@ -57,7 +57,7 @@ int main() {
|
|||
//Responds with request-information
|
||||
server.resource["^/info$"]["GET"]=[](HttpServer::Response& response, shared_ptr<HttpServer::Request> request) {
|
||||
stringstream content_stream;
|
||||
content_stream << "<h1>Request from " << request->remote_endpoint_address.to_string() << " (" << request->remote_endpoint_port << ")</h1>";
|
||||
content_stream << "<h1>Request from " << request->remote_endpoint_address << " (" << request->remote_endpoint_port << ")</h1>";
|
||||
content_stream << request->method << " " << request->path << " HTTP/" << request->http_version << "<br>";
|
||||
for(auto& header: request->header) {
|
||||
content_stream << header.first << ": " << header.second << "<br>";
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ int main() {
|
|||
//Responds with request-information
|
||||
server.resource["^/info$"]["GET"]=[](HttpsServer::Response& response, shared_ptr<HttpsServer::Request> request) {
|
||||
stringstream content_stream;
|
||||
content_stream << "<h1>Request from " << request->remote_endpoint_address.to_string() << " (" << request->remote_endpoint_port << ")</h1>";
|
||||
content_stream << "<h1>Request from " << request->remote_endpoint_address << " (" << request->remote_endpoint_port << ")</h1>";
|
||||
content_stream << request->method << " " << request->path << " HTTP/" << request->http_version << "<br>";
|
||||
for(auto& header: request->header) {
|
||||
content_stream << header.first << ": " << header.second << "<br>";
|
||||
|
|
|
|||
|
|
@ -121,11 +121,11 @@ namespace SimpleWeb {
|
|||
|
||||
std::istream content;
|
||||
|
||||
std::unordered_map<std::string, std::string> header;
|
||||
std::unordered_multimap<std::string, std::string> header;
|
||||
|
||||
std::smatch path_match;
|
||||
|
||||
boost::asio::ip::address remote_endpoint_address;
|
||||
std::string remote_endpoint_address;
|
||||
unsigned short remote_endpoint_port;
|
||||
|
||||
private:
|
||||
|
|
@ -135,7 +135,7 @@ namespace SimpleWeb {
|
|||
|
||||
void read_remote_endpoint_data(socket_type& socket) {
|
||||
try {
|
||||
remote_endpoint_address=socket.lowest_layer().remote_endpoint().address();
|
||||
remote_endpoint_address=socket.lowest_layer().remote_endpoint().address().to_string();
|
||||
remote_endpoint_port=socket.lowest_layer().remote_endpoint().port();
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
|
|
@ -266,14 +266,15 @@ namespace SimpleWeb {
|
|||
parse_request(request, request->content);
|
||||
|
||||
//If content, read that as well
|
||||
if(request->header.count("Content-Length")>0) {
|
||||
const auto it=request->header.find("Content-Length");
|
||||
if(it!=request->header.end()) {
|
||||
//Set timeout on the following boost::asio::async-read or write function
|
||||
std::shared_ptr<boost::asio::deadline_timer> timer;
|
||||
if(timeout_content>0)
|
||||
timer=set_timeout_on_socket(socket, timeout_content);
|
||||
|
||||
boost::asio::async_read(*socket, request->streambuf,
|
||||
boost::asio::transfer_exactly(stoull(request->header["Content-Length"])-num_additional_bytes),
|
||||
boost::asio::transfer_exactly(stoull(it->second)-num_additional_bytes),
|
||||
[this, socket, request, timer]
|
||||
(const boost::system::error_code& ec, size_t /*bytes_transferred*/) {
|
||||
if(timeout_content>0)
|
||||
|
|
@ -306,7 +307,8 @@ namespace SimpleWeb {
|
|||
if(line[value_start]==' ')
|
||||
value_start++;
|
||||
|
||||
request->header[line.substr(0, param_end)]=line.substr(value_start, line.size()-value_start-1);
|
||||
std::string key=line.substr(0, param_end);
|
||||
request->header.insert(std::make_pair(key, line.substr(value_start, line.size()-value_start-1)));
|
||||
|
||||
getline(stream, line);
|
||||
param_end=line.find(':');
|
||||
|
|
|
|||
|
|
@ -34,14 +34,11 @@ public:
|
|||
|
||||
if(request->header.size()!=2)
|
||||
return 0;
|
||||
if(request->header.count("TestHeader")==0)
|
||||
auto header_it=request->header.find("TestHeader");
|
||||
if(header_it==request->header.end() || header_it->second!="test")
|
||||
return 0;
|
||||
if(request->header["TestHeader"]!="test")
|
||||
return 0;
|
||||
|
||||
if(request->header.count("TestHeader2")==0)
|
||||
return 0;
|
||||
if(request->header["TestHeader2"]!="test2")
|
||||
header_it=request->header.find("TestHeader2");
|
||||
if(header_it==request->header.end() || header_it->second!="test2")
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
|
|
@ -90,15 +87,13 @@ public:
|
|||
|
||||
if(response->header.size()!=2)
|
||||
return 0;
|
||||
if(response->header.count("TestHeader")==0)
|
||||
return 0;
|
||||
if(response->header["TestHeader"]!="test")
|
||||
return 0;
|
||||
|
||||
if(response->header.count("TestHeader2")==0)
|
||||
return 0;
|
||||
if(response->header["TestHeader2"]!="test2")
|
||||
return 0;
|
||||
auto header_it=response->header.find("TestHeader");
|
||||
if(header_it==response->header.end() || header_it->second!="test")
|
||||
return 0;
|
||||
header_it=response->header.find("TestHeader2");
|
||||
if(header_it==response->header.end() || header_it->second!="test2")
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue