Commit Graph

316 Commits

Author SHA1 Message Date
yhirose
f5598237b2 Fixed many redirects problem on Proxy 2020-05-16 17:34:03 -04:00
Daniel Ottiger
01058659ab
make write timeout configurable (like the read timeout already is) (#477)
In case we want to send a lot of data,
and the receiver is slower than the sender.

This will first fill up the receivers queues and after this
eventually also the senders queues,
until the socket is temporarily unable to accept more data to send.

select_write is done with an timeout of zero,
which makes the select call used always return immediately:
(see http://man7.org/linux/man-pages/man2/select.2.html)

This means that every marginal unavailability will make it return false
for is_writable and therefore httplib will immediately abort the transfer.

Therefore make this values configurable in the same way
as the read timeout already is.

Set the default write timeout to 5 seconds,
the same default value used for the read timeout.
2020-05-16 17:31:46 -04:00
yhirose
25aa3ca982 Added std::ostream os in DataSink. 2020-05-15 21:26:13 -04:00
yhirose
2d67211183 Added more unit tests for the simple interface 2020-05-14 18:25:18 -04:00
yhirose
63a96aeb20 Improved Client2 interface 2020-05-14 12:51:34 -04:00
yhirose
2d4b42b70b Removed url 2020-05-14 01:43:06 -04:00
yhirose
1919d08f71 Added Client2 2020-05-14 01:36:56 -04:00
yhirose
2c0613f211 Fix #472 2020-05-13 21:48:14 -04:00
yhirose
58909f5917 Fix #466 2020-05-10 15:58:53 -04:00
yhirose
eb1fe5b191 Fixed warnings 2020-05-09 15:08:49 -04:00
yhirose
5e01587ed6 Fixed problem created in the previous commit 2020-05-09 13:43:06 -04:00
yhirose
5935d9fa59 Commented out the unit test for digest auth. 2020-05-09 13:32:51 -04:00
Daniel Ottiger
d043b18097
keepalive: support multiple post using content provider (#461) 2020-05-07 08:31:14 -04:00
yhirose
cf386f97fd Merge branch 'master' of https://github.com/yhirose/cpp-httplib 2020-05-04 22:13:17 -04:00
Daniel Ottiger
b2203bb05a
server: support dual-stack server socket (#450)
According to RFC 3493 the socket option IPV6_V6ONLY
should be off by default, see
https://tools.ietf.org/html/rfc3493#page-22 (chapter 5.3).

However this does not seem to be the case on all systems.
For instance on any Windows OS, the option is on by default.

Therefore clear this option in order to allow
an server socket which can support IPv6 and IPv4 at the same time.
2020-05-04 22:13:12 -04:00
yhirose
f5b806d995 Added a test case for #396. 2020-05-04 21:26:14 -04:00
yhirose
3895210f19 Code format 2020-05-04 21:25:59 -04:00
Matthew DeVore
ed1b6afa10
Fix crash caused by header field regex complexity (#457) 2020-05-01 12:44:13 -04:00
yhirose
08fc7085e5 Fixed #456 2020-04-30 19:40:23 -04:00
yhirose
fae30af47d Updated appveyor.yml 2020-04-25 15:48:19 -04:00
yhirose
a2e4af54b7 Fix #399 2020-04-23 23:09:04 -04:00
yhirose
d0b123be26 Support remote_addr and remote_port REMOTE_PORT header in client Request (#433) 2020-04-23 22:12:12 -04:00
Matthew DeVore
df138366e4
Fail to read a chunk if its length is >= ULONG_MAX (#444)
We cannot trivially support such large chunks, and the maximum value
std::strtoul can parse accurately is ULONG_MAX-1. Error out early if the
length is longer than that.
2020-04-23 10:59:15 -04:00
Matthew DeVore
c49441ae64
Do not throw exceptions when parsing request chunks (#441)
detail::read_content_chunked was using std::stoul to parse the
hexadecimal chunk lengths for "Transfer-Encoding: chunked" requests.
This throws an exception if the string does not begin with any valid
digits. read_content_chunked is not called in the context of a try block
so this caused the process to terminate.

Rather than use exceptions, I opted for std::stroul, which is similar to
std::stoul but does not throw exceptions. Since malformed user input is
not particularly exceptional, and some projects are compiled without
exception support, this approach seems both more portable and more
correct.
2020-04-23 09:05:45 -04:00
yhirose
e1506fa186 Code cleanup 2020-04-22 21:43:16 -04:00
yhirose
ad9fd3bd93 Fix #436 2020-04-22 21:42:58 -04:00
yhirose
05e0253195 Fixed test error 2020-04-21 23:07:51 -04:00
yhirose
da26b517a3 Added url::Get interface 2020-04-21 23:00:39 -04:00
yhirose
2b7a968468 Added a unit test for URL interface 2020-04-21 21:21:31 -04:00
Daniel Ottiger
2ece5f116b
Pass certs and keys from memory (#432)
* SSLServer: add constructor to pass ssl-certificates and key from memory

* SSLClient: add constructor to pass ssl-certificates and key from memory

* add TestCase for passing certificates from memory to SSLClient/SSLServer
2020-04-18 16:26:06 -04:00
yhirose
c2b6e4ac04 Fix #431 2020-04-17 21:48:16 -04:00
yhirose
85327e19ae Fix #425 2020-04-12 15:33:08 -04:00
Alexandre Taillefer
ed8efea98b
Added support for DELETE request body (#418)
* Added support for DELETE request body

* Fixed DELETE request body test case typo

Co-authored-by: Alexandre Taillefer <alexandre.taillefer@pwc.ca>
2020-04-07 15:51:52 -04:00
yhirose
e1acb949e7 Fix #382 2020-03-13 18:43:29 -04:00
yhirose
26deffe0c6 Not to send 'EXCEPTION_WHAT' header to client 2020-03-10 17:44:36 -04:00
yhirose
c74129a1c2
Fix #372 (#374) 2020-03-09 23:59:00 -04:00
Matthew DeVore
bf7700d192
Fix exception that occurs with libc++ regex engine (#368)
The regex that parses header lines potentially causes an unlimited
amount of backtracking, which can cause an exception in the libc++ regex
engine.

The exception that occurs looks like this and is identical to the
message of the exception fixed in
https://github.com/yhirose/cpp-httplib/pull/280:

	libc++abi.dylib: terminating with uncaught exception of type
	std::__1::regex_error: The complexity of an attempted match
	against a regular expression exceeded a pre-set level.

This commit eliminates the problematic backtracking.
2020-02-28 06:31:39 -05:00
yhirose
3da925d6fe Adjusted a unit test. 2020-02-25 08:29:29 -05:00
hyperxor
ccc9a9b3f4 Remove code duplication in converting params to query 2020-02-25 02:30:34 +03:00
rymis
f2bb9c45d6
Support for deflate compression (#360) 2020-02-24 11:48:00 -05:00
yhirose
9a663aa94e Added a unit test. 2020-02-21 11:48:47 -05:00
yhirose
d61d63dd97 Added unit tests for SSLServer::bind_to_any_port 2020-02-14 21:59:37 -05:00
yhirose
851edaf77f Code format 2020-02-02 20:02:16 -05:00
yhirose
ac7742bb32 Changed the order of parameters of set_mounting_point. 2020-02-01 09:18:24 -05:00
yhirose
8801e51138 Fix #341 2020-01-31 20:35:20 -05:00
Vitaly Takmazov
5e43680486 HEAD support for static file server 2020-01-28 12:00:27 +03:00
yhirose
4d545cb932 Fix #335 2020-01-21 09:09:05 -05:00
yhirose
2e360f9dd6 Improved Stream interface 2020-01-16 23:28:11 -05:00
yhirose
6b4df41b30 Fix #330 2020-01-14 17:02:25 -05:00
yhirose
a15d16a9de Moved Stream concrete classes into detail namespace 2020-01-10 09:33:14 -05:00
hyperxor
7b4494748e fix indentation 2020-01-10 00:17:40 +03:00
hyperxor
7e1c107029 Use sleep_for and chrono for delays in tests 2020-01-10 00:15:18 +03:00
yhirose
2f72845008 Fix #319 2020-01-07 23:40:11 -05:00
yhirose
96e9ec0663 Improved DataSink interface 2020-01-05 23:59:54 -05:00
yhirose
c58fca5dba Added more tests 2020-01-03 07:57:40 -05:00
yhirose
d2fae4031c Fixed build errors 2020-01-03 01:36:59 -05:00
yhirose
de844e67ef Proxy support for Keep-Alive requests 2020-01-03 01:24:07 -05:00
yhirose
fcbcbd53bd Fix #306 2019-12-26 18:48:22 -05:00
yhirose
aa543240db Added test for post request with query string and body 2019-12-24 21:55:29 -05:00
yhirose
5675cad407 Added proxy test in Makefile 2019-12-22 21:07:26 -05:00
yhirose
079d3605ea Changed to use docker-compose for squid 2019-12-22 19:11:02 -05:00
yhirose
38adeaf02c Fixed problem with proxy support and added unit tests 2019-12-22 15:37:01 -05:00
yhirose
eb4fcb5003 CONNECT method support on client 2019-12-20 06:59:59 -05:00
yhirose
9c81693801 Fix #294 2019-12-18 17:47:36 -05:00
yhirose
9a41b16cbb Fix #285. Added set_interface method on client 2019-12-15 17:44:00 -05:00
yhirose
58b2814fda Format code 2019-12-14 23:50:53 -05:00
yhirose
72b20c08da Better API names 2019-12-13 06:56:00 -05:00
yhirose
afd6d5f9dc Removed compress parameter and added compress method on client 2019-12-12 23:09:59 -05:00
yhirose
5324b3d661 Improved multipart form data interface 2019-12-12 22:48:09 -05:00
yhirose
151ccba57e Code cleanup 2019-12-12 21:50:12 -05:00
Yuji Hirose
d064fb7ff2 Fixed warning 2019-12-10 13:08:07 -05:00
Yuji Hirose
fd4e1b4112 Fix #266 2019-12-10 12:10:14 -05:00
Matthew DeVore
bc9251ea49 Work around incompatibility in <regex> in libc++
libc++ (the implementation of the C++ standard library usually used by
Clang) throws an exception for the regex used by parse_headers before
this patch for certain strings. Work around this by simplifying the
regex and parsing the header lines "by hand" partially. I have repro'd
this problem with Xcode 11.1 which I believe uses libc++ version 8.

This may be a bug in libc++ as I can't see why the regex would result in
asymptotic run-time complexity for any strings. However, it may take a
while for libc++ to be fixed and for everyone to migrate to it, so it
makes sense to work around it in this codebase for now.
2019-12-05 17:14:16 -08:00
Matthew DeVore
a9e942d755 Properly trim whitespace from headers
HTTP Whitespace and regex whitespace are not the same, so we can't use
\s in regexes when parsing HTTP headers. Instead, explicitly specify
what is considered whitespace in the regex.
2019-12-05 17:14:16 -08:00
yhirose
033bc35723 Improve multipart content reader interface 2019-12-02 07:11:12 -05:00
yhirose
b69c0a1dcb Content receiver support for multipart content (Fix #241) 2019-12-01 22:04:26 -05:00
yhirose
295e4d58aa Fix #276 2019-11-29 17:07:51 -05:00
yhirose
880f7fa62b Fix #273 2019-11-27 12:54:01 -05:00
yhirose
9d57899352 Simplified ContentReceiver interface 2019-10-27 23:38:56 -04:00
yhirose
d03937e144 Content receiver support on server 2019-10-27 23:20:56 -04:00
yhirose
5f32c424c2 Content provider support on client 2019-10-25 18:39:04 -04:00
yhirose
0d527e2b83 Code formatting 2019-10-25 12:09:26 -04:00
yhirose
bea3ebd7af Added 'compress' option to POST, PUT and PATCH. 2019-10-25 11:46:12 -04:00
yhirose
a106bd314c Merge branch 'master' of https://github.com/yhirose/cpp-httplib 2019-10-23 08:30:49 -04:00
yhirose
e4fd9f19ca Updated Makefile 2019-10-23 08:28:15 -04:00
yhirose
001b8a5529 Added unit tests 2019-10-22 23:32:14 -04:00
yhirose
dcdb0d047b Fixed PRI request problem 2019-10-03 13:44:18 -04:00
yhirose
6d8302313c Fixed warning 2019-10-03 13:44:18 -04:00
Shunsuke Mie
5f49c13f95 Fix a test, ConnectionErrorTest::InvalidPort. currently, the abcde.com is valid, so I change it. The first byte doesn't permit a hyphen. 2019-10-03 21:49:11 +09:00
yhirose
a99e02aeb3 Add HTTP/2 Connection Preface check test 2019-10-01 06:28:45 -04:00
yhirose
c47c6b3910 Updated test.vcxproj 2019-09-26 13:20:53 -04:00
yhirose
1f99ad5d6e Updated vcxproj for test 2019-09-25 08:16:15 -04:00
Steffen Schuemann
7e92ffec48 Added new Client::Get variant that combines a ContentReceiver with a new ResponseHandler
While trying to implement streaming of internet radio, where a ContentReceiver is needed to handle the audio data, I had the problem, that important information about the stream data is part of the HTTP header (e.g. size of audio chunks between meta data), so I added a ResponseHandler and a new Get variant, to gain access to the header before handling the first chunk of data.

The ResponseHandler can abort the request by returning false, in the same way as the ContentReceiver.

A test case was also added.
2019-09-14 14:55:12 +02:00
yhirose
531708816a Update README 2019-09-06 18:29:22 -04:00
yhirose
bfec81998b Code cleanup 2019-09-06 18:16:42 -04:00
yhirose
c9238434e1 Added redirect support (Fix #211) 2019-09-06 18:07:35 -04:00
yhirose
359b06681b Fixed warnings 2019-09-03 17:16:16 -04:00
yhirose
a0fe91e84d Fixed unit test problem 2019-09-03 17:16:07 -04:00
yhirose
80f040cf69 Fix #209 2019-09-03 17:10:04 -04:00
yhirose
1e82359329 Keep-alive connection support on client (Fix #36) 2019-08-31 17:52:24 -04:00
yhirose
64991a560a Fixed problems with Win32 build 2019-08-07 15:21:22 +09:00
yhirose
d7bb402ca7 Format code 2019-08-06 18:12:05 +09:00
yhirose
2823a94fc1 Added 'resource_releaser' for content provider 2019-08-05 09:40:23 +09:00
yhirose
5a13539e57 Revert "Fixed unit test error on Windows"
This reverts commit 531f6ab84d.
2019-08-04 09:50:47 +09:00
yhirose
531f6ab84d Fixed unit test error on Windows 2019-08-03 20:43:27 -04:00
yhirose
c899462e75 Added 'Content-Range' header for single range request 2019-08-03 22:12:24 +09:00
yhirose
9d7b717504 Range header support and redesign of content provider interface 2019-08-03 03:28:39 +09:00
yhirose
e8799383f3 Made unit tests stable 2019-07-30 01:51:53 +00:00
yhirose
ba7f9fe4c3 Added more unit tests 2019-07-28 19:11:58 -04:00
yhirose
34651ef89b Fix #121 2019-07-23 09:53:44 -04:00
yhirose
e0d327558d Updated README 2019-07-23 08:05:51 -04:00
yhirose
b5a1d52f36 Test code cleanup 2019-07-19 11:47:08 -04:00
yhirose
eaafa5d55c Fix #127 2019-07-19 11:38:06 -04:00
yhirose
6f663028e9 Fix #139. Content receiver support 2019-07-17 22:00:18 -04:00
yhirose
3541fe8330 Use -pthread 2019-07-09 22:31:55 -04:00
yhirose
cdc45c4601 Changed to use CXX and CXXFLAGS in Makefile 2019-06-26 15:09:34 -04:00
yhirose
1981e0ccad Add SSL object on Request 2019-06-20 18:52:28 -04:00
yhirose
8d12e0d8f4 Simplified code 2019-06-11 21:39:35 -04:00
yhirose
07d9843b91 clangformat 2019-06-11 20:57:02 -04:00
yhirose
92f08b54c4
Merge pull request #162 from PixlRainbow/master
client certificates support
2019-06-11 20:53:56 -04:00
PixlRainbow
2d532a6d0c build fix for Mac OS X
removed c_rehash has it appears to not be needed
2019-06-07 01:39:03 +08:00
PixlRainbow
b2f4120d15 setup test cases for client certificates 2019-06-07 01:23:22 +08:00
yhirose
93086957a9 Fixed warnings in googletest 2019-06-05 11:32:22 -04:00
yhirose
dfc94f2cab Code cleanup 2019-05-07 21:46:15 -04:00
yhirose
3f42804a4f Wildcard support for verifying server certificate. fix #87 2019-05-07 21:40:03 -04:00
yhirose
744e8e7071 Fix #144 2019-04-12 23:34:27 -04:00
yhirose
8af85019dc Removed get_header_value_int and use uint64_t for the return value of get_header_value_uint64 2019-04-12 17:22:39 -04:00
Yuji Hirose
5d082f1da4 Apply clangformat 2019-04-11 08:13:31 -04:00
yhirose
a91a0b7dbf Fix #140 2019-04-10 12:21:42 -04:00
yhirose
8483e5931f Fix #136 2019-03-28 19:56:32 -04:00
Yuji Hirose
96cacd24f9 Fixed #134 2019-03-12 08:49:08 -04:00
yhirose
3a3b02e2e5 Added Base Authentication test 2019-02-14 22:51:17 -05:00
Yuji Hirose
d3eb88b740 Fix #126 2019-02-13 08:14:58 -05:00
yhirose
b5927aec12 fix #116 2018-12-17 21:07:38 -05:00
yhirose
86b3dfc480 fix #110 2018-11-30 21:18:35 -05:00
yhirose
76ea8dd560 Added LongQueryValue test 2018-11-14 17:35:27 -05:00
yhirose
49c82c9c50 Fix #97. (Thanks to DJm00n.) 2018-10-28 16:15:22 +09:00
yhirose
4d7cee81eb Fix #95 2018-09-23 12:02:17 -04:00
Yuji Hirose
28d17448b7 Revert test.vcproj.
This reverts commit cc983be31f.
2018-09-14 15:58:16 -04:00
Thomas Tissot
82fc7d5591 Request cancelation feature
This commit modifies the signature of the `Progress` callback
so that its return value will indicate whether the request shall
continue to be processed by returning `true`, or if it shall
be aborted by returning `false`. Such modification will allow
one to cancel an ongoing request before it has completed.

When migrating, developers should modify there `Progress`
callbacks to always return `true` by default in case there
do not want to benefit from the cancelation feature.

A few unit tests use cases were provided, but anyone should feel
free to provide additional uses cases that they find relevant.
2018-08-06 11:54:52 +02:00
yhirose
cc983be31f Removed unused build projects 2018-08-02 22:31:36 -04:00
David Guillen Fandos
dae4124039 Implementing streaming Responses
This enables a much easier handling of big queries after all.
2018-08-01 23:53:01 +02:00
David Guillen Fandos
ca343ae1d8 Fix small issues in tests and added some extra checks. 2018-07-31 22:08:38 +02:00
yhirose
85a30e73a5 Fixed -lpthread linker option position 2018-06-14 15:30:55 +00:00
yhirose
2bb27aa25d Fix #74 2018-06-01 23:05:32 -04:00
yhirose
5b3187e2f9 Fix #72 2018-05-31 22:17:23 -04:00
yhirose
7b9d752583 Fixed problem with connection close 2018-05-14 00:05:14 -04:00
yhirose
312a8d7523 Removed HTTP version. It's now always 'HTTP/1.1'. 2018-05-13 19:18:25 -04:00
yhirose
6c5d0b2a18 Fix #57 and #62 2018-05-08 21:51:41 -04:00
yhirose
6aa3fd6b59 Fix #38 2018-04-20 09:59:19 -04:00