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:
parent
93ec4fa999
commit
7c9dee579f
@ -245,7 +245,7 @@ namespace fr
|
|||||||
* @param filename The filename, or file extention to find the mime type of
|
* @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.
|
* @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:
|
protected:
|
||||||
/*!
|
/*!
|
||||||
@ -302,8 +302,7 @@ namespace fr
|
|||||||
RequestStatus status;
|
RequestStatus status;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::unordered_map<std::string, std::string> mime_types;
|
|
||||||
void load_mimetypes();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,7 @@ namespace fr
|
|||||||
HandshakeFailed = 8,
|
HandshakeFailed = 8,
|
||||||
VerificationFailed = 9,
|
VerificationFailed = 9,
|
||||||
MaxPacketSizeExceeded = 10,
|
MaxPacketSizeExceeded = 10,
|
||||||
|
NotEnoughData = 11
|
||||||
};
|
};
|
||||||
|
|
||||||
enum IP
|
enum IP
|
||||||
@ -97,6 +98,20 @@ namespace fr
|
|||||||
*/
|
*/
|
||||||
virtual Status receive_raw(void *data, size_t data_size, size_t &received) = 0;
|
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
|
* Send a packet through the socket
|
||||||
*
|
*
|
||||||
@ -127,21 +142,6 @@ namespace fr
|
|||||||
*/
|
*/
|
||||||
Status receive_all(void *dest, size_t buffer_size);
|
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.
|
* Calls the shutdown syscall on the socket.
|
||||||
* So you can receive data but not send.
|
* So you can receive data but not send.
|
||||||
|
|||||||
1396
src/Http.cpp
1396
src/Http.cpp
File diff suppressed because it is too large
Load Diff
@ -23,7 +23,13 @@ namespace fr
|
|||||||
if(!header_ended)
|
if(!header_ended)
|
||||||
{
|
{
|
||||||
//Check to see if this request data contains the end of the header
|
//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");
|
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;
|
header_ended = header_end != std::string::npos;
|
||||||
|
|
||||||
//If the header end has not been found, return true, indicating that we need more data.
|
//If the header end has not been found, return true, indicating that we need more data.
|
||||||
@ -37,9 +43,8 @@ namespace fr
|
|||||||
return false;
|
return false;
|
||||||
body.clear();
|
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
|
//If we've got the whole request, parse the POST if it exists
|
||||||
@ -70,9 +75,7 @@ namespace fr
|
|||||||
|
|
||||||
//Read in headers
|
//Read in headers
|
||||||
for(; line < header_lines.size(); line++)
|
for(; line < header_lines.size(); line++)
|
||||||
{
|
|
||||||
parse_header_line(header_lines[line]);
|
parse_header_line(header_lines[line]);
|
||||||
}
|
|
||||||
|
|
||||||
//Store content length value if it exists
|
//Store content length value if it exists
|
||||||
auto length_header_iter = header_data.find("content-length");
|
auto length_header_iter = header_data.find("content-length");
|
||||||
@ -124,7 +127,7 @@ namespace fr
|
|||||||
request += post_string;
|
request += post_string;
|
||||||
|
|
||||||
//Add in the body
|
//Add in the body
|
||||||
request += body + "\r\n";
|
request += body;
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
@ -132,6 +135,8 @@ namespace fr
|
|||||||
void HttpRequest::parse_post_body()
|
void HttpRequest::parse_post_body()
|
||||||
{
|
{
|
||||||
auto post_begin = body.find_first_not_of("\r\n");
|
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)
|
if(post_begin != std::string::npos)
|
||||||
{
|
{
|
||||||
auto post = parse_argument_list(body.substr(post_begin, body.size() - post_begin));
|
auto post = parse_argument_list(body.substr(post_begin, body.size() - post_begin));
|
||||||
|
|||||||
@ -15,7 +15,13 @@ namespace fr
|
|||||||
if(!header_ended)
|
if(!header_ended)
|
||||||
{
|
{
|
||||||
//Check to see if this request data contains the end of the header
|
//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");
|
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;
|
header_ended = header_end != std::string::npos;
|
||||||
|
|
||||||
//If the header end has not been found, return true, indicating that we need more data.
|
//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.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)
|
if(body.size() > content_length)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user