Bug fixes

Fixed HTTP Request receive expecting more bytes than there actually is, and so waiting for more bytes when there is none.
This commit is contained in:
Fred Nicolson 2017-07-12 16:53:34 +01:00
parent 93ec4fa999
commit 7c9dee579f
5 changed files with 730 additions and 724 deletions

View File

@ -245,7 +245,7 @@ namespace fr
* @param filename The filename, or file extention to find the mime type of
* @return The mime type. Returns 'application/octet-stream' if it couldn't be found.
*/
const std::string &get_mimetype(const std::string &filename);
const static std::string &get_mimetype(const std::string &filename);
protected:
/*!
@ -302,8 +302,7 @@ namespace fr
RequestStatus status;
private:
static std::unordered_map<std::string, std::string> mime_types;
void load_mimetypes();
};
}

View File

@ -27,6 +27,7 @@ namespace fr
HandshakeFailed = 8,
VerificationFailed = 9,
MaxPacketSizeExceeded = 10,
NotEnoughData = 11
};
enum IP
@ -97,6 +98,20 @@ namespace fr
*/
virtual Status receive_raw(void *data, size_t data_size, size_t &received) = 0;
/*!
* Gets the socket descriptor.
*
* @return The socket descriptor.
*/
virtual int32_t get_socket_descriptor() const = 0;
/*!
* Checks to see if we're connected to a socket or not
*
* @return True if it's connected. False otherwise.
*/
virtual bool connected() const =0;
/*!
* Send a packet through the socket
*
@ -127,21 +142,6 @@ namespace fr
*/
Status receive_all(void *dest, size_t buffer_size);
/*!
* Checks to see if we're connected to a socket or not
*
* @return True if it's connected. False otherwise.
*/
virtual bool connected() const =0;
/*!
* Gets the socket descriptor.
*
* @return The socket descriptor.
*/
virtual int32_t get_socket_descriptor() const = 0;
/*!
* Calls the shutdown syscall on the socket.
* So you can receive data but not send.

File diff suppressed because it is too large Load Diff

View File

@ -23,7 +23,13 @@ namespace fr
if(!header_ended)
{
//Check to see if this request data contains the end of the header
uint16_t header_end_size = 4;
auto header_end = body.find("\r\n\r\n");
if(header_end == std::string::npos)
{
header_end = body.find("\n\n");
header_end_size = 2;
}
header_ended = header_end != std::string::npos;
//If the header end has not been found, return true, indicating that we need more data.
@ -37,9 +43,8 @@ namespace fr
return false;
body.clear();
}
content_length += 2; //The empty line between header and data
body += request.substr(header_end, request.size() - header_end);
body += request.substr(header_end + header_end_size, request.size() - header_end - header_end_size);
}
//If we've got the whole request, parse the POST if it exists
@ -70,9 +75,7 @@ namespace fr
//Read in headers
for(; line < header_lines.size(); line++)
{
parse_header_line(header_lines[line]);
}
//Store content length value if it exists
auto length_header_iter = header_data.find("content-length");
@ -124,7 +127,7 @@ namespace fr
request += post_string;
//Add in the body
request += body + "\r\n";
request += body;
return request;
}
@ -132,6 +135,8 @@ namespace fr
void HttpRequest::parse_post_body()
{
auto post_begin = body.find_first_not_of("\r\n");
if(post_begin == std::string::npos)
post_begin = body.find_first_not_of("\n");
if(post_begin != std::string::npos)
{
auto post = parse_argument_list(body.substr(post_begin, body.size() - post_begin));

View File

@ -15,7 +15,13 @@ namespace fr
if(!header_ended)
{
//Check to see if this request data contains the end of the header
uint16_t header_end_size = 4;
auto header_end = body.find("\r\n\r\n");
if(header_end == std::string::npos)
{
header_end = body.find("\n\n");
header_end_size = 2;
}
header_ended = header_end != std::string::npos;
//If the header end has not been found, return true, indicating that we need more data.
@ -29,7 +35,7 @@ namespace fr
body.clear();
}
body += response_data.substr(header_end + 4, response_data.size() - header_end - 4);
body += response_data.substr(header_end + header_end_size, response_data.size() - header_end - header_end_size);
}
if(body.size() > content_length)