30 Commits

Author SHA1 Message Date
Fred Nicolson
5b2b92835e
Add support for chunked HTTP response parsing 2019-11-25 16:29:06 +00:00
Fred Nicolson
32767786af
Moving enums to enum classes 2019-05-01 17:06:09 +01:00
Fred Nicolson
c23a77d4cc
Cleaned up code. Updated documentation. 2019-04-30 17:29:03 +01:00
Fred Nicolson
6814219cbb
Bug fixes. fr::Socket::send_raw now behaves like receive_raw.
Added missing virtual destructors in abstract classes.
2019-03-21 16:24:22 +00:00
Fred Nicolson
252a4788b5 Added ability to set/get HTTP response/request version
+ Additional tests
2018-11-19 15:23:10 +00:00
Fred Nicolson
8a4ee937b1 Added ability to set/get recv timeouts. Fixed HTTP receive bug.
Recv timeouts can now be specified for sockets, which is the maximum amount of time to wait before returning during a receive. They will return WouldBlock if no data was received during the wait time.

Receiving a HTTP request in non-blocking mode will no longer fail.
2018-08-16 11:24:52 +01:00
Fred Nicolson
27d02ca055 fr::Packet optimisations & marking Sendable::send() as const
Replaced instances of resize&memcpy with append, which gives a noticeable performance boost.

fr::Packet::operator<<(const char *str) no longer converts str into an std::string before adding it, removing an unneeded copy.

fr::Packet::clear no longer calls erase, should result in more of the internal buffer remaining allocated.

Framing for std::vector's has been changed from a uint64_t to a uint32_t (breaking change for packet framing!)
2018-03-27 12:03:55 +01:00
Fred Nicolson
103e0faaae Bug fixes. HTTP parsing improvements. More tests.
Fixed TcpSocket::set_descriptor(nullptr) causing an invalid read from address 0x0.

Improved HTTP response/request parsing so that they report a parse failure if the first few bytes of the HTTP request don't match the expected format rather than continuing to look for an end of header.

Fixed broken fr::Http::url_encode() implementation.

Optimised fr::Http::url_decode() implementation.

Added fr::Http unit tests.
2018-03-01 15:51:57 +00:00
Fred Nicolson
ff25d11089 Removed socket mutexes. Added more tests. Improved examples.
Socket mutexes are no longer really required, and so have been removed.

Added more tests for network encoding functions, and the URL parser.

The URL parser now returns a path preceeded with a '/' instead of cutting it out. Added get_uri() to URL, for getting the whole URI, so users don't have to concat it themselves from the more specialised functions.

Fixed default socket connect timeout checking for the wrong value.

Fixed request_type_strings not containing all of the possible request types.

Fixed README using old socket close syntax.

Cleaned up the examples a bit.
2018-02-01 11:56:34 +00:00
Fred Nicolson
c8e03f2df8 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.
2017-09-25 16:19:47 +01:00
Fred Nicolson
5c2b6c3a8d Fixed request parse issues on Windows
Tests on Windows now passing.

For some reason, std::string::find was not returning std::string::npos despite not finding anything on MinGW.
2017-08-23 11:50:57 +01:00
Fred Nicolson
f1db713069 Made POST/GET/HEADER members case insensitive again
It broke things. Bad.
2017-08-22 13:57:08 +01:00
Fred Nicolson
0bd41ec6bd get_remote_address() now works on SSL sockets accepted through SSLListener
Post/get/... data is no longer case insensitive.
2017-08-02 17:32:16 +01:00
Fred Nicolson
cfda0f969e Specified default move/copy constructors/operators to Http/Response/Request 2017-08-01 16:15:43 +01:00
Fred Nicolson
84382cad0b Made some changes recommended by Clang-Tidy. 2017-07-20 15:02:43 +01:00
Fred Nicolson
a0ca16c891 Work on fr::HttpRequest unit tests. Some tweaking.
GET variables are now actually added to the request when constructing them, instead of being ignored.
2017-07-20 10:42:18 +01:00
Fred Nicolson
f2cebd0847 Work on tests. Bug fixes and tweaks.
Started work on tests for fr::HttpRequest.

Fixed the final POST data variable containing header data it shouldn't (\r\n\r\n).

Fixed fr::Http::header_exists, and family, not converting things to lowercase first.
2017-07-19 17:30:43 +01:00
Fred Nicolson
e748fde121 API changes, and lots of fixes.
fr::HttpSocket has been removed.

fr::Sendable has been added. Classes can inherit this if they want to be sendable through sockets. Both fr::Http (which is inherited by fr::HttpRequest and fr::HttpResponse), and fr::Packet inherit this, to allow them to be sent through fr::Socket::send()/fr::Socket::receive().

Fixed broken fr::SocketSelector and fr::SocketReactor, as they no longer accepted fr::Listener's due to fr::Listener no longer inheriting fr::Socket.
2017-07-18 17:34:49 +01:00
Fred Nicolson
7c9dee579f Bug fixes
Fixed HTTP Request receive expecting more bytes than there actually is, and so waiting for more bytes when there is none.
2017-07-12 16:53:34 +01:00
Unknown
93ec4fa999 Bug fixes
Fixed Content-Length header being added to Http responses even if there's a pre-existing one.

Fixed header parsing sometimes adding a carriage return to the header value.

Removed useless copy/move constructors from HttpResponse, causing issues.
2017-07-10 21:47:34 +01:00
Fred Nicolson
df509a42f5 Socket and HTTP Response bug fixes
fr::TcpSocket checked if the recv response was greater than 0, which created issues as 0 is a valid result if no data was received and no error occurred.

fr::HttpResponse::construct() now adds in a content-length header.

fr::HttpResponse::parse trims the body if it's larger than content length.

fr::Http::set_uri() now prepends a '/' if one's not provided.

Fixed fr::Http::parse_header from cutting off the end of headers.
2017-07-07 11:05:19 +01:00
Fred Nicolson
aa8509e460 Added move/copy constructors to Http & HttpResponse 2017-06-16 15:16:13 +01:00
Fred Nicolson
7ea87cced8 Added helpers for detecting mimetype
fr::Http::get_mimetype(filename) will return the mimetype of a given filename or file extention. This should be used to set the 'content-type' header when creating fr::HttpResponses.
2017-05-07 10:44:33 +01:00
Fred Nicolson
53ab6e2090 Header names are automatically lower-cased now. 2017-04-11 10:39:23 +01:00
Fred Nicolson
561b395e93 Removed debugging text. Fixed header parsing issue.
An extra character was been included in the header data.
2017-04-11 09:43:52 +01:00
Fred Nicolson
6b1ef27764 Re-wrote HTML request/response parsing
It's now much more robust, supports requests received over multiple recvs. Supports POST variables. Supports 'content-length' header.
2017-04-10 17:24:57 +01:00
Fred Nicolson
27b559b4ef Added URL encoding/decoding and proper POST parsing
Also fixed last body line being ignored in requests
2016-12-31 22:05:44 +00:00
Cloaked9000
2de9540819 Added windows support. Updated build system.
CMake build system builds as a library, not an executable now.

Windows is now supported and should work fine.
2016-12-19 12:10:39 +00:00
Cloaked9000
8c94c337e9 SSL Contexts are now shared between sockets 2016-12-16 14:55:41 +00:00
Fred Nicolson
98897dec02 Cleaned up HTTP socket/request code. 2016-12-11 12:14:47 +00:00