Added more tests. Tweaks.
Receiving an http request/response will now return errors like HttpHeaderTooBig, instead of the type being set to that. Added fr::Socket::status_to_string for converting status values into English strings.
This commit is contained in:
@@ -27,9 +27,6 @@ namespace fr
|
||||
};
|
||||
enum RequestStatus
|
||||
{
|
||||
ParseError = 0,
|
||||
HttpHeaderTooBig = 1,
|
||||
HttpBodyTooBig = 2,
|
||||
Continue = 100,
|
||||
SwitchingProtocols = 101,
|
||||
Ok = 200,
|
||||
@@ -100,9 +97,9 @@ namespace fr
|
||||
*
|
||||
* @param data The request/response to parse
|
||||
* @param datasz The length of data in bytes
|
||||
* @return True if more data is needed, false if finished.
|
||||
* @return NotEnoughData if parse needs to be called again. Success on success, other on error.
|
||||
*/
|
||||
virtual bool parse(const char *data, size_t datasz)=0;
|
||||
virtual fr::Socket::Status parse(const char *data, size_t datasz)=0;
|
||||
|
||||
/*!
|
||||
* Constructs a HTTP request/response to send.
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace fr
|
||||
* @param datasz The length of data in bytes
|
||||
* @return True if more data is needed, false if finished.
|
||||
*/
|
||||
bool parse(const char *data, size_t datasz) override;
|
||||
fr::Socket::Status parse(const char *data, size_t datasz) override;
|
||||
|
||||
/*!
|
||||
* Constructs a Http Request, ready to send.
|
||||
@@ -44,6 +44,7 @@ namespace fr
|
||||
* Parses the request header.
|
||||
*
|
||||
* @param header_end_pos The position in 'body' of the end of the header
|
||||
* @return True on success, false on failure
|
||||
*/
|
||||
bool parse_header(int64_t header_end_pos);
|
||||
|
||||
|
||||
@@ -24,13 +24,14 @@ namespace fr
|
||||
virtual ~HttpResponse() = default;
|
||||
|
||||
/*!
|
||||
* Parse a HTTP response.
|
||||
* Parse a raw request or response from a string
|
||||
* into the object.
|
||||
*
|
||||
* @param data The HTTP response to parse
|
||||
* @param data The request/response to parse
|
||||
* @param datasz The length of data in bytes
|
||||
* @return True if more data is needed, false if finished.
|
||||
* @return NotEnoughData if parse needs to be called again. Success on success, other on error.
|
||||
*/
|
||||
bool parse(const char *data, size_t datasz) override;
|
||||
fr::Socket::Status parse(const char *data, size_t datasz) override;
|
||||
|
||||
/*!
|
||||
* Constructs a HttpResponse, ready to send.
|
||||
|
||||
@@ -84,6 +84,8 @@ namespace fr
|
||||
*/
|
||||
int32_t get_socket_descriptor() const override
|
||||
{
|
||||
if(!ssl_socket_descriptor)
|
||||
return -1;
|
||||
return ssl_socket_descriptor->fd;
|
||||
}
|
||||
|
||||
@@ -104,7 +106,7 @@ namespace fr
|
||||
*/
|
||||
inline bool connected() const final
|
||||
{
|
||||
return ssl_socket_descriptor->fd > -1;
|
||||
return ssl_socket_descriptor && ssl_socket_descriptor->fd > -1;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace fr
|
||||
* @param socket The socket to send through
|
||||
* @return Status indicating if the send succeeded or not.
|
||||
*/
|
||||
virtual Socket::Status send(Socket *socket) = 0;
|
||||
virtual Socket::Status send(Socket *socket) = 0; //TODO: RETURN PROPER VALUE FROM HTTP PARSE
|
||||
|
||||
/*!
|
||||
* Overrideable receive, to allow
|
||||
|
||||
@@ -29,7 +29,11 @@ namespace fr
|
||||
HandshakeFailed = 8,
|
||||
VerificationFailed = 9,
|
||||
MaxPacketSizeExceeded = 10,
|
||||
NotEnoughData = 11
|
||||
NotEnoughData = 11,
|
||||
ParseError = 12,
|
||||
HttpHeaderTooBig = 13,
|
||||
HttpBodyTooBig = 14,
|
||||
//Remember to update status_to_string if more are added
|
||||
};
|
||||
|
||||
enum IP
|
||||
@@ -215,6 +219,16 @@ namespace fr
|
||||
{
|
||||
return max_receive_size;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Converts an fr::Socket::Status value to a printable string
|
||||
*
|
||||
* Throws an std::logic_error if status is out of range.
|
||||
*
|
||||
* @param status Status value to convert
|
||||
* @return A string form version
|
||||
*/
|
||||
static const std::string &status_to_string(fr::Socket::Status status);
|
||||
protected:
|
||||
|
||||
/*!
|
||||
|
||||
Reference in New Issue
Block a user