Removed unneeded code from http component
This commit is contained in:
parent
7f63a84295
commit
2acad805b3
@ -136,7 +136,7 @@ private:
|
|||||||
boost::array<char, 8192> buffer_;
|
boost::array<char, 8192> buffer_;
|
||||||
|
|
||||||
/// The incoming request.
|
/// The incoming request.
|
||||||
request request_;
|
Request request_;
|
||||||
|
|
||||||
/// The parser for the incoming request.
|
/// The parser for the incoming request.
|
||||||
request_parser request_parser_;
|
request_parser request_parser_;
|
||||||
|
@ -38,24 +38,10 @@ struct reply
|
|||||||
enum status_type
|
enum status_type
|
||||||
{
|
{
|
||||||
ok = 200,
|
ok = 200,
|
||||||
created = 201,
|
|
||||||
accepted = 202,
|
|
||||||
no_content = 204,
|
|
||||||
multiple_choices = 300,
|
|
||||||
moved_permanently = 301,
|
|
||||||
moved_temporarily = 302,
|
|
||||||
not_modified = 304,
|
|
||||||
bad_request = 400,
|
bad_request = 400,
|
||||||
unauthorized = 401,
|
internal_server_error = 500
|
||||||
forbidden = 403,
|
|
||||||
not_found = 404,
|
|
||||||
internal_server_error = 500,
|
|
||||||
not_implemented = 501,
|
|
||||||
bad_gateway = 502,
|
|
||||||
service_unavailable = 503
|
|
||||||
} status;
|
} status;
|
||||||
|
|
||||||
/// The headers to be included in the reply.
|
|
||||||
std::vector<header> headers;
|
std::vector<header> headers;
|
||||||
|
|
||||||
/// The content to be sent in the reply.
|
/// The content to be sent in the reply.
|
||||||
@ -74,36 +60,10 @@ namespace status_strings {
|
|||||||
|
|
||||||
const std::string ok =
|
const std::string ok =
|
||||||
"HTTP/1.0 200 OK\r\n";
|
"HTTP/1.0 200 OK\r\n";
|
||||||
const std::string created =
|
|
||||||
"HTTP/1.0 201 Created\r\n";
|
|
||||||
const std::string accepted =
|
|
||||||
"HTTP/1.0 202 Accepted\r\n";
|
|
||||||
const std::string no_content =
|
|
||||||
"HTTP/1.0 204 No Content\r\n";
|
|
||||||
const std::string multiple_choices =
|
|
||||||
"HTTP/1.0 300 Multiple Choices\r\n";
|
|
||||||
const std::string moved_permanently =
|
|
||||||
"HTTP/1.0 301 Moved Permanently\r\n";
|
|
||||||
const std::string moved_temporarily =
|
|
||||||
"HTTP/1.0 302 Moved Temporarily\r\n";
|
|
||||||
const std::string not_modified =
|
|
||||||
"HTTP/1.0 304 Not Modified\r\n";
|
|
||||||
const std::string bad_request =
|
const std::string bad_request =
|
||||||
"HTTP/1.0 400 Bad Request\r\n";
|
"HTTP/1.0 400 Bad Request\r\n";
|
||||||
const std::string unauthorized =
|
|
||||||
"HTTP/1.0 401 Unauthorized\r\n";
|
|
||||||
const std::string forbidden =
|
|
||||||
"HTTP/1.0 403 Forbidden\r\n";
|
|
||||||
const std::string not_found =
|
|
||||||
"HTTP/1.0 404 Not Found\r\n";
|
|
||||||
const std::string internal_server_error =
|
const std::string internal_server_error =
|
||||||
"HTTP/1.0 500 Internal Server Error\r\n";
|
"HTTP/1.0 500 Internal Server Error\r\n";
|
||||||
const std::string not_implemented =
|
|
||||||
"HTTP/1.0 501 Not Implemented\r\n";
|
|
||||||
const std::string bad_gateway =
|
|
||||||
"HTTP/1.0 502 Bad Gateway\r\n";
|
|
||||||
const std::string service_unavailable =
|
|
||||||
"HTTP/1.0 503 Service Unavailable\r\n";
|
|
||||||
|
|
||||||
boost::asio::const_buffer to_buffer(reply::status_type status)
|
boost::asio::const_buffer to_buffer(reply::status_type status)
|
||||||
{
|
{
|
||||||
@ -111,38 +71,12 @@ boost::asio::const_buffer to_buffer(reply::status_type status)
|
|||||||
{
|
{
|
||||||
case reply::ok:
|
case reply::ok:
|
||||||
return boost::asio::buffer(ok);
|
return boost::asio::buffer(ok);
|
||||||
case reply::created:
|
|
||||||
return boost::asio::buffer(created);
|
|
||||||
case reply::accepted:
|
|
||||||
return boost::asio::buffer(accepted);
|
|
||||||
case reply::no_content:
|
|
||||||
return boost::asio::buffer(no_content);
|
|
||||||
case reply::multiple_choices:
|
|
||||||
return boost::asio::buffer(multiple_choices);
|
|
||||||
case reply::moved_permanently:
|
|
||||||
return boost::asio::buffer(moved_permanently);
|
|
||||||
case reply::moved_temporarily:
|
|
||||||
return boost::asio::buffer(moved_temporarily);
|
|
||||||
case reply::not_modified:
|
|
||||||
return boost::asio::buffer(not_modified);
|
|
||||||
case reply::bad_request:
|
case reply::bad_request:
|
||||||
return boost::asio::buffer(bad_request);
|
return boost::asio::buffer(bad_request);
|
||||||
case reply::unauthorized:
|
|
||||||
return boost::asio::buffer(unauthorized);
|
|
||||||
case reply::forbidden:
|
|
||||||
return boost::asio::buffer(forbidden);
|
|
||||||
case reply::not_found:
|
|
||||||
return boost::asio::buffer(not_found);
|
|
||||||
case reply::internal_server_error:
|
case reply::internal_server_error:
|
||||||
return boost::asio::buffer(internal_server_error);
|
return boost::asio::buffer(internal_server_error);
|
||||||
case reply::not_implemented:
|
|
||||||
return boost::asio::buffer(not_implemented);
|
|
||||||
case reply::bad_gateway:
|
|
||||||
return boost::asio::buffer(bad_gateway);
|
|
||||||
case reply::service_unavailable:
|
|
||||||
return boost::asio::buffer(service_unavailable);
|
|
||||||
default:
|
default:
|
||||||
return boost::asio::buffer(internal_server_error);
|
return boost::asio::buffer(bad_request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,81 +109,16 @@ std::vector<boost::asio::const_buffer> reply::to_buffers()
|
|||||||
namespace stock_replies {
|
namespace stock_replies {
|
||||||
|
|
||||||
const char ok[] = "";
|
const char ok[] = "";
|
||||||
const char created[] =
|
|
||||||
"<html>"
|
|
||||||
"<head><title>Created</title></head>"
|
|
||||||
"<body><h1>201 Created</h1></body>"
|
|
||||||
"</html>";
|
|
||||||
const char accepted[] =
|
|
||||||
"<html>"
|
|
||||||
"<head><title>Accepted</title></head>"
|
|
||||||
"<body><h1>202 Accepted</h1></body>"
|
|
||||||
"</html>";
|
|
||||||
const char no_content[] =
|
|
||||||
"<html>"
|
|
||||||
"<head><title>No Content</title></head>"
|
|
||||||
"<body><h1>204 Content</h1></body>"
|
|
||||||
"</html>";
|
|
||||||
const char multiple_choices[] =
|
|
||||||
"<html>"
|
|
||||||
"<head><title>Multiple Choices</title></head>"
|
|
||||||
"<body><h1>300 Multiple Choices</h1></body>"
|
|
||||||
"</html>";
|
|
||||||
const char moved_permanently[] =
|
|
||||||
"<html>"
|
|
||||||
"<head><title>Moved Permanently</title></head>"
|
|
||||||
"<body><h1>301 Moved Permanently</h1></body>"
|
|
||||||
"</html>";
|
|
||||||
const char moved_temporarily[] =
|
|
||||||
"<html>"
|
|
||||||
"<head><title>Moved Temporarily</title></head>"
|
|
||||||
"<body><h1>302 Moved Temporarily</h1></body>"
|
|
||||||
"</html>";
|
|
||||||
const char not_modified[] =
|
|
||||||
"<html>"
|
|
||||||
"<head><title>Not Modified</title></head>"
|
|
||||||
"<body><h1>304 Not Modified</h1></body>"
|
|
||||||
"</html>";
|
|
||||||
const char bad_request[] =
|
const char bad_request[] =
|
||||||
"<html>"
|
"<html>"
|
||||||
"<head><title>Bad Request</title></head>"
|
"<head><title>Bad Request</title></head>"
|
||||||
"<body><h1>400 Bad Request</h1></body>"
|
"<body><h1>400 Bad Request</h1></body>"
|
||||||
"</html>";
|
"</html>";
|
||||||
const char unauthorized[] =
|
|
||||||
"<html>"
|
|
||||||
"<head><title>Unauthorized</title></head>"
|
|
||||||
"<body><h1>401 Unauthorized</h1></body>"
|
|
||||||
"</html>";
|
|
||||||
const char forbidden[] =
|
|
||||||
"<html>"
|
|
||||||
"<head><title>Forbidden</title></head>"
|
|
||||||
"<body><h1>403 Forbidden</h1></body>"
|
|
||||||
"</html>";
|
|
||||||
const char not_found[] =
|
|
||||||
"<html>"
|
|
||||||
"<head><title>Not Found</title></head>"
|
|
||||||
"<body><h1>404 Not Found</h1></body>"
|
|
||||||
"</html>";
|
|
||||||
const char internal_server_error[] =
|
const char internal_server_error[] =
|
||||||
"<html>"
|
"<html>"
|
||||||
"<head><title>Internal Server Error</title></head>"
|
"<head><title>Internal Server Error</title></head>"
|
||||||
"<body><h1>500 Internal Server Error</h1></body>"
|
"<body><h1>500 Internal Server Error</h1></body>"
|
||||||
"</html>";
|
"</html>";
|
||||||
const char not_implemented[] =
|
|
||||||
"<html>"
|
|
||||||
"<head><title>Not Implemented</title></head>"
|
|
||||||
"<body><h1>501 Not Implemented</h1></body>"
|
|
||||||
"</html>";
|
|
||||||
const char bad_gateway[] =
|
|
||||||
"<html>"
|
|
||||||
"<head><title>Bad Gateway</title></head>"
|
|
||||||
"<body><h1>502 Bad Gateway</h1></body>"
|
|
||||||
"</html>";
|
|
||||||
const char service_unavailable[] =
|
|
||||||
"<html>"
|
|
||||||
"<head><title>Service Unavailable</title></head>"
|
|
||||||
"<body><h1>503 Service Unavailable</h1></body>"
|
|
||||||
"</html>";
|
|
||||||
|
|
||||||
std::string to_string(reply::status_type status)
|
std::string to_string(reply::status_type status)
|
||||||
{
|
{
|
||||||
@ -257,36 +126,10 @@ std::string to_string(reply::status_type status)
|
|||||||
{
|
{
|
||||||
case reply::ok:
|
case reply::ok:
|
||||||
return ok;
|
return ok;
|
||||||
case reply::created:
|
|
||||||
return created;
|
|
||||||
case reply::accepted:
|
|
||||||
return accepted;
|
|
||||||
case reply::no_content:
|
|
||||||
return no_content;
|
|
||||||
case reply::multiple_choices:
|
|
||||||
return multiple_choices;
|
|
||||||
case reply::moved_permanently:
|
|
||||||
return moved_permanently;
|
|
||||||
case reply::moved_temporarily:
|
|
||||||
return moved_temporarily;
|
|
||||||
case reply::not_modified:
|
|
||||||
return not_modified;
|
|
||||||
case reply::bad_request:
|
case reply::bad_request:
|
||||||
return bad_request;
|
return bad_request;
|
||||||
case reply::unauthorized:
|
|
||||||
return unauthorized;
|
|
||||||
case reply::forbidden:
|
|
||||||
return forbidden;
|
|
||||||
case reply::not_found:
|
|
||||||
return not_found;
|
|
||||||
case reply::internal_server_error:
|
case reply::internal_server_error:
|
||||||
return internal_server_error;
|
return internal_server_error;
|
||||||
case reply::not_implemented:
|
|
||||||
return not_implemented;
|
|
||||||
case reply::bad_gateway:
|
|
||||||
return bad_gateway;
|
|
||||||
case reply::service_unavailable:
|
|
||||||
return service_unavailable;
|
|
||||||
default:
|
default:
|
||||||
return internal_server_error;
|
return internal_server_error;
|
||||||
}
|
}
|
||||||
|
@ -22,19 +22,15 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#define HTTP_REQUEST_HPP
|
#define HTTP_REQUEST_HPP
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <list>
|
||||||
#include "header.h"
|
#include "header.h"
|
||||||
|
|
||||||
namespace http {
|
namespace http {
|
||||||
|
|
||||||
/// A request received from a client.
|
/// A request received from a client.
|
||||||
struct request
|
struct Request
|
||||||
{
|
{
|
||||||
std::string method;
|
|
||||||
std::string uri;
|
std::string uri;
|
||||||
int http_version_major;
|
|
||||||
int http_version_minor;
|
|
||||||
std::vector<header> headers;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
namespace http {
|
namespace http {
|
||||||
|
|
||||||
struct reply;
|
struct reply;
|
||||||
struct request;
|
struct Request;
|
||||||
|
|
||||||
/// The common handler for all incoming requests.
|
/// The common handler for all incoming requests.
|
||||||
template<typename GraphT>
|
template<typename GraphT>
|
||||||
@ -47,7 +47,7 @@ public:
|
|||||||
explicit request_handler(SearchEngine<EdgeData, GraphT> * s) : sEngine(s){}
|
explicit request_handler(SearchEngine<EdgeData, GraphT> * s) : sEngine(s){}
|
||||||
|
|
||||||
/// Handle a request and produce a reply.
|
/// Handle a request and produce a reply.
|
||||||
void handle_request(const request& req, reply& rep){
|
void handle_request(const Request& req, reply& rep){
|
||||||
try {
|
try {
|
||||||
std::string request(req.uri);
|
std::string request(req.uri);
|
||||||
std::string command;
|
std::string command;
|
||||||
@ -152,7 +152,7 @@ public:
|
|||||||
rep.headers[2].value = "attachment; filename=\"route.kml\"";
|
rep.headers[2].value = "attachment; filename=\"route.kml\"";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
rep = reply::stock_reply(reply::not_found);
|
rep = reply::stock_reply(reply::bad_request);
|
||||||
return;
|
return;
|
||||||
} catch(std::exception& e)
|
} catch(std::exception& e)
|
||||||
{
|
{
|
||||||
|
@ -27,7 +27,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
|
|
||||||
namespace http {
|
namespace http {
|
||||||
|
|
||||||
struct request;
|
struct Request;
|
||||||
|
|
||||||
/// Parser for incoming requests.
|
/// Parser for incoming requests.
|
||||||
class request_parser
|
class request_parser
|
||||||
@ -44,7 +44,7 @@ public:
|
|||||||
/// data is required. The InputIterator return value indicates how much of the
|
/// data is required. The InputIterator return value indicates how much of the
|
||||||
/// input has been consumed.
|
/// input has been consumed.
|
||||||
template <typename InputIterator>
|
template <typename InputIterator>
|
||||||
boost::tuple<boost::tribool, InputIterator> parse(request& req,
|
boost::tuple<boost::tribool, InputIterator> parse(Request& req,
|
||||||
InputIterator begin, InputIterator end)
|
InputIterator begin, InputIterator end)
|
||||||
{
|
{
|
||||||
while (begin != end)
|
while (begin != end)
|
||||||
@ -59,7 +59,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
/// Handle the next character of input.
|
/// Handle the next character of input.
|
||||||
boost::tribool consume(request& req, char input);
|
boost::tribool consume(Request& req, char input);
|
||||||
|
|
||||||
/// Check if a byte is an HTTP character.
|
/// Check if a byte is an HTTP character.
|
||||||
static bool is_char(int c);
|
static bool is_char(int c);
|
||||||
@ -117,7 +117,7 @@ void request_parser::reset()
|
|||||||
state_ = method_start;
|
state_ = method_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::tribool request_parser::consume(request& req, char input)
|
boost::tribool request_parser::consume(Request& req, char input)
|
||||||
{
|
{
|
||||||
switch (state_)
|
switch (state_)
|
||||||
{
|
{
|
||||||
@ -129,7 +129,6 @@ boost::tribool request_parser::consume(request& req, char input)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
state_ = method;
|
state_ = method;
|
||||||
req.method.push_back(input);
|
|
||||||
return boost::indeterminate;
|
return boost::indeterminate;
|
||||||
}
|
}
|
||||||
case method:
|
case method:
|
||||||
@ -144,7 +143,6 @@ boost::tribool request_parser::consume(request& req, char input)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
req.method.push_back(input);
|
|
||||||
return boost::indeterminate;
|
return boost::indeterminate;
|
||||||
}
|
}
|
||||||
case uri_start:
|
case uri_start:
|
||||||
@ -216,8 +214,6 @@ boost::tribool request_parser::consume(request& req, char input)
|
|||||||
case http_version_slash:
|
case http_version_slash:
|
||||||
if (input == '/')
|
if (input == '/')
|
||||||
{
|
{
|
||||||
req.http_version_major = 0;
|
|
||||||
req.http_version_minor = 0;
|
|
||||||
state_ = http_version_major_start;
|
state_ = http_version_major_start;
|
||||||
return boost::indeterminate;
|
return boost::indeterminate;
|
||||||
}
|
}
|
||||||
@ -228,7 +224,6 @@ boost::tribool request_parser::consume(request& req, char input)
|
|||||||
case http_version_major_start:
|
case http_version_major_start:
|
||||||
if (is_digit(input))
|
if (is_digit(input))
|
||||||
{
|
{
|
||||||
req.http_version_major = req.http_version_major * 10 + input - '0';
|
|
||||||
state_ = http_version_major;
|
state_ = http_version_major;
|
||||||
return boost::indeterminate;
|
return boost::indeterminate;
|
||||||
}
|
}
|
||||||
@ -244,7 +239,6 @@ boost::tribool request_parser::consume(request& req, char input)
|
|||||||
}
|
}
|
||||||
else if (is_digit(input))
|
else if (is_digit(input))
|
||||||
{
|
{
|
||||||
req.http_version_major = req.http_version_major * 10 + input - '0';
|
|
||||||
return boost::indeterminate;
|
return boost::indeterminate;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -254,7 +248,6 @@ boost::tribool request_parser::consume(request& req, char input)
|
|||||||
case http_version_minor_start:
|
case http_version_minor_start:
|
||||||
if (is_digit(input))
|
if (is_digit(input))
|
||||||
{
|
{
|
||||||
req.http_version_minor = req.http_version_minor * 10 + input - '0';
|
|
||||||
state_ = http_version_minor;
|
state_ = http_version_minor;
|
||||||
return boost::indeterminate;
|
return boost::indeterminate;
|
||||||
}
|
}
|
||||||
@ -270,7 +263,6 @@ boost::tribool request_parser::consume(request& req, char input)
|
|||||||
}
|
}
|
||||||
else if (is_digit(input))
|
else if (is_digit(input))
|
||||||
{
|
{
|
||||||
req.http_version_minor = req.http_version_minor * 10 + input - '0';
|
|
||||||
return boost::indeterminate;
|
return boost::indeterminate;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -293,19 +285,12 @@ boost::tribool request_parser::consume(request& req, char input)
|
|||||||
state_ = expecting_newline_3;
|
state_ = expecting_newline_3;
|
||||||
return boost::indeterminate;
|
return boost::indeterminate;
|
||||||
}
|
}
|
||||||
else if (!req.headers.empty() && (input == ' ' || input == '\t'))
|
|
||||||
{
|
|
||||||
state_ = header_lws;
|
|
||||||
return boost::indeterminate;
|
|
||||||
}
|
|
||||||
else if (!is_char(input) || is_ctl(input) || is_tspecial(input))
|
else if (!is_char(input) || is_ctl(input) || is_tspecial(input))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
req.headers.push_back(header());
|
|
||||||
req.headers.back().name.push_back(input);
|
|
||||||
state_ = header_name;
|
state_ = header_name;
|
||||||
return boost::indeterminate;
|
return boost::indeterminate;
|
||||||
}
|
}
|
||||||
@ -326,7 +311,6 @@ boost::tribool request_parser::consume(request& req, char input)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
state_ = header_value;
|
state_ = header_value;
|
||||||
req.headers.back().value.push_back(input);
|
|
||||||
return boost::indeterminate;
|
return boost::indeterminate;
|
||||||
}
|
}
|
||||||
case header_name:
|
case header_name:
|
||||||
@ -341,7 +325,6 @@ boost::tribool request_parser::consume(request& req, char input)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
req.headers.back().name.push_back(input);
|
|
||||||
return boost::indeterminate;
|
return boost::indeterminate;
|
||||||
}
|
}
|
||||||
case space_before_header_value:
|
case space_before_header_value:
|
||||||
@ -366,7 +349,6 @@ boost::tribool request_parser::consume(request& req, char input)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
req.headers.back().value.push_back(input);
|
|
||||||
return boost::indeterminate;
|
return boost::indeterminate;
|
||||||
}
|
}
|
||||||
case expecting_newline_2:
|
case expecting_newline_2:
|
||||||
|
Loading…
Reference in New Issue
Block a user