Commit 7de9be42 authored by James Allenby's avatar James Allenby
Browse files

Several changes

parent e90ea9c2
#ifndef HTTPCOMMON_H
#define HTTPCOMMON_H
namespace HTTP
{
enum class Method {
GET,
HEAD,
POST,
PUT,
DELETE,
CONNECT,
OPTIONS,
TRACE
};
// RFC7231 Section 8.2
enum class Code {
// Informational 1xx
HTTP_100, // 100 Continue
HTTP_101, // 101 Switching Protocols
// Successful 2xx
HTTP_200, // 200 OK
HTTP_201, // 201 Created
HTTP_202, // 202 Accepted
HTTP_203, // 203 Non-Authoritative Information
HTTP_204, // 204 No Content
HTTP_205, // 205 Reset Content
// Redirection 3xx
HTTP_300, // 300 Multiple Choices
HTTP_301, // 301 Moved Permanently
HTTP_302, // 302 Found
HTTP_303, // 303 See Other
HTTP_305, // 305 Use Proxy
HTTP_306, // 306 (Unused)
HTTP_307, // 307 Temporary Redirect
// Client Error 4xx
HTTP_400, // 400 Bad Request
HTTP_402, // 402 Payment Required
HTTP_403, // 403 Forbidden
HTTP_404, // 404 Not Found
HTTP_405, // 405 Method Not Allowed
HTTP_406, // 406 Not Acceptable
HTTP_408, // 408 Request Timeout
HTTP_409, // 409 Conflict
HTTP_410, // 410 Gone
HTTP_411, // 411 Length Required
HTTP_413, // 413 Payload Too Large
HTTP_414, // 414 URI Too Long
HTTP_415, // 415 Unsupported Media Type
HTTP_417, // 417 Expectation Failed
HTTP_426, // 426 Upgrade Required
// Server Error 5xx
HTTP_500, // 500 Internal Server Error
HTTP_501, // 501 Not Implemented
HTTP_502, // 502 Bad Gateway
HTTP_503, // 503 Service Unavailable
HTTP_504, // 504 Gateway Timeout
HTTP_505, // 505 HTTP Version Not Supported
};
}
#endif // HTTPCOMMON_H
......@@ -3,12 +3,14 @@
#include <string>
#include "httpcommon.h"
namespace HTTPResponse
{
struct HTTPResponse
{
std::string http_version;
std::string status_code;
HTTP::Code status_code;
std::string reason_phrase;
};
}
......
......@@ -11,24 +11,15 @@
#include <sys/socket.h>
#include <netinet/in.h>
enum class HTTPMethod {
GET,
HEAD,
POST,
PUT,
DELETE,
CONNECT,
OPTIONS,
TRACE
};
#include "httpcommon.h"
struct HTTPRequest
{
HTTPMethod method;
HTTP::Method method;
std::string uri;
std::string http_version;
std::vector<std::string> fields;
std::string payload;
std::string message;
};
int ConvertToHTTPRequest(std::string input, HTTPRequest* output = nullptr)
......@@ -84,21 +75,21 @@ int ConvertToHTTPRequest(std::string input, HTTPRequest* output = nullptr)
std::string method_string = start_line.substr(0, method_end_position);
if (method_string == "GET")
output->method = HTTPMethod::GET;
output->method = HTTP::Method::GET;
else if (method_string == "HEAD")
output->method = HTTPMethod::HEAD;
output->method = HTTP::Method::HEAD;
else if (method_string == "POST")
output->method = HTTPMethod::POST;
output->method = HTTP::Method::POST;
else if (method_string == "PUT")
output->method = HTTPMethod::PUT;
output->method = HTTP::Method::PUT;
else if (method_string == "DELETE")
output->method = HTTPMethod::DELETE;
output->method = HTTP::Method::DELETE;
else if (method_string == "CONNECT")
output->method = HTTPMethod::CONNECT;
output->method = HTTP::Method::CONNECT;
else if (method_string == "OPTIONS")
output->method = HTTPMethod::OPTIONS;
output->method = HTTP::Method::OPTIONS;
else if (method_string == "TRACE")
output->method = HTTPMethod::TRACE;
output->method = HTTP::Method::TRACE;
else
{
std::cerr << "Unknown request method" << std::endl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment