summaryrefslogtreecommitdiff
path: root/uclient-http.c
Commit message (Collapse)AuthorAgeFilesLines
* uclient-http: set eof mark when content-length is 0Youfu Zhang2021-05-141-1/+2
| | | | | | | or uclient-fetch will stall until timeout for 2XX (except 204) response with content-length of 0 Signed-off-by: Youfu Zhang <zhangyoufu@gmail.com>
* uclient-http: fix extra compiler warnings on mips_24kc and cortex-a9+neonPetr Štetiar2020-12-111-4/+5
| | | | | | | | | | | | | | | | | | Fixes following warnings as reported on 32-bit platforms toolchain-mips_24kc_gcc-8.4.0_musl and toolchain-arm_cortex-a9+neon_gcc-8.4.0_musl_eabi: uclient-http.c:1111:10: error: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Werror=sign-compare] if (len > data_end - data) ^ uclient-http.c:1115:11: error: comparison of integer expressions of different signedness: 'unsigned int' and 'long int' [-Werror=sign-compare] if (len > uh->read_chunked) ^ uclient-http.c:1120:11: error: comparison of integer expressions of different signedness: 'unsigned int' and 'long int' [-Werror=sign-compare] if (len > uh->content_length) ^ References: https://gitlab.com/ynezz/openwrt-uclient/-/pipelines/226912126 Signed-off-by: Petr Štetiar <ynezz@true.cz>
* uclient-http: fix freeing of stack allocated memoryPetr Štetiar2020-12-111-7/+5
| | | | | | | | | | Fixes following issue reported by clang-12 static analyzer: uclient-http.c:568:2: warning: Memory allocated by alloca() should not be deallocated [unix.Malloc] free(buf_orig); ^~~~~~~~~~~~~~ Signed-off-by: Petr Štetiar <ynezz@true.cz>
* Fix extra compiler warningsPetr Štetiar2020-12-111-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes following -Wextra compiler warnings: uclient.c:195:16: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] for (i = 0; i < ARRAY_SIZE(backends); i++) { ~ ^ ~~~~~~~~~~~~~~~~~~~~ uclient-http.c:619:2: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] blobmsg_for_each_attr(cur, uh->headers.head, rem) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ uclient-http.c:619:2: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] blobmsg_for_each_attr(cur, uh->headers.head, rem) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ uclient-http.c:993:16: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] for (i = 0; i < ARRAY_SIZE(request_types); i++) { ~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~ uclient.c:195:16: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] for (i = 0; i < ARRAY_SIZE(backends); i++) { ~ ^ ~~~~~~~~~~~~~~~~~~~~ uclient-http.c:619:2: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] blobmsg_for_each_attr(cur, uh->headers.head, rem) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ uclient-http.c:619:2: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] blobmsg_for_each_attr(cur, uh->headers.head, rem) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ uclient-http.c:993:16: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] for (i = 0; i < ARRAY_SIZE(request_types); i++) { ~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~ uclient-fetch.c:551:67: error: missing field 'flag' initializer [-Werror,-Wmissing-field-initializers] [L_NO_CHECK_CERTIFICATE] = { "no-check-certificate", no_argument }, Signed-off-by: Petr Štetiar <ynezz@true.cz>
* uclient-http: set data_eof when content-length is 0Yousong Zhou2019-05-301-1/+2
| | | | | | | | | Otherwise uclient-fetch can report "Connection reset prematurely" Fixes FS#2222 Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com> Acked-by: Petr Štetiar <ynezz@true.cz>
* uclient-http: properly handle HTTP redirects via proxy connectionsJo-Philipp Wich2018-11-241-2/+9
| | | | | | | | | | | | When uclient connects via an HTTP proxy connection we need to swap the contexts .proxy_url and not the .url property (which is the connection URL to the proxy server itself). This fixes uclient erroring out in a redirect loop when connecting via a proxy connection. Ref: https://forum.openwrt.org/t/opkg-update-fails/25813 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* uclient-http: Close ustream file handle only if allocatedTobias Schramm2018-08-031-1/+2
| | | | | | | | Since the connection setup in uclient_do_connect can fail before ustream_init_fd is called we must check the fd was actually allocated before closing it, else we would close STDIN. Signed-off-by: Tobias Schramm <tobleminer@gmail.com>
* uclient-http: Implement error handling for header-sendingTobias Schramm2018-02-221-13/+24
| | | | | | | Add some error handling for errors during assembly of headers Signed-off-by: Tobias Schramm <tobleminer@gmail.com> Signed-off-by: Felix Fietkau <nbd@nbd.name>
* uclient-http: Handle memory allocation failureTobias Schramm2018-02-201-0/+3
| | | | | | Add null pointer check to allocation of uclient_http struct Signed-off-by: Tobias Schramm <tobleminer@gmail.com>
* uclient-http: auth digest: Handle multiple possible memory allocation failuresTobias Schramm2018-02-201-9/+34
| | | | | | Add null pointer checks to allocation of buffers for authentication parameters Signed-off-by: Tobias Schramm <tobleminer@gmail.com>
* uclient-http: basic auth: Handle memory allocation failureTobias Schramm2018-02-201-2/+7
| | | | | | | Allocation of the base64 buffer might fail, resulting in a null ptr being passed to base64_encode as a target buffer Signed-off-by: Tobias Schramm <tobleminer@gmail.com>
* uclient-http: fix Host: header for literal IPv6 addressesMatthias Schiffer2017-09-061-3/+9
| | | | | | | | | | | | | | | | | | For literal IPv6 addresses, the host header must have the form Host: [...] including the square brackets, as it may also contain a port. Some webservers ignore the missing brackets, while others will return error 400. IPv6 addresses are determined by searching for ':' characters in the host, as neither IPv4 addresses nor DNS names can contain colons. An alternative would be to add a flag to the uclient_url struct; but as this struct is exposed in public headers, such a change could be considered an ABI change, making a backport difficult. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net> Acked-by: Jo-Philipp Wich <jo@mein.io>
* Fix unused results warningsFlorian Fainelli2016-12-091-1/+4
| | | | | | | | | | | | | | | | | | Fixes: uclient-http.c:385:8: error: ignoring return value of 'fread', declared with attribute warn_unused_result [-Werror=unused-result] fread(&val, sizeof(val), 1, f); ^ uclient-fetch.c: In function 'main': uclient-fetch.c:664:12: error: ignoring return value of 'asprintf', declared with attribute warn_unused_result [-Werror=unused-result] asprintf(&auth_str, "%s:%s", username, password); ^ uclient-fetch.c: In function 'read_data_cb': uclient-fetch.c:269:9: error: ignoring return value of 'write', declared with attribute warn_unused_result [-Werror=unused-result] write(output_fd, buf, len); Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
* uclient-http: send correct "Host:" header if port is setAlexander Couzens2016-11-301-2/+4
| | | | | | | | When connecting to a website with a special port, uclient-fetch connects to the correct port, but is sending an incorrect Host: header without the corresponding port. Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
* http: add support for relative location on redirectFelix Fietkau2016-07-051-1/+1
| | | | Signed-off-by: Felix Fietkau <nbd@nbd.name>
* http: allow sending message body for DELETE requestRafał Miłecki2016-06-161-2/+14
| | | | | | | | | | Sending entity within DELETE is not forbidden by RFC 7231, see section 4.3.5. DELETE: > A payload within a DELETE request message has no defined semantics; > sending a payload body on a DELETE request might cause some existing > implementations to reject the request. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
* http: use usock_inet_timeout()Felix Fietkau2016-01-281-1/+3
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* http: add support for specifying ipv4/ipv6 preferenceFelix Fietkau2016-01-251-1/+26
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* http: assume data EOF if the connection terminatesFelix Fietkau2016-01-231-0/+3
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* http: fix processing server http data separated by \n instead of \r\nFelix Fietkau2016-01-231-6/+11
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* http: add proper error handling to uclient_http_redirect()Felix Fietkau2016-01-231-2/+4
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* http: fix connection close handling on authFelix Fietkau2016-01-201-2/+4
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-http: use blocking connect, switch to non-blocking later. fixes ipv6 ↵Felix Fietkau2016-01-161-1/+3
| | | | | | -> ipv4 fallback Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* http: detect connect failureFelix Fietkau2016-01-161-0/+4
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* http: add proxy supportFelix Fietkau2016-01-161-0/+4
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* http: allow the header_done callback to reset the client stateFelix Fietkau2016-01-161-1/+3
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* http: get remote address from usock instead of using getpeernameFelix Fietkau2016-01-151-5/+4
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-fetch: set server_name of the ssl context to support SNIAlexander Couzens2015-08-061-0/+1
| | | | Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
* uclient-http: end custom header lines with CRLFFelix Fietkau2015-04-141-1/+1
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-http: allow .header_done() callback to reset the connectionFelix Fietkau2015-04-141-0/+6
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* allow sending requests with DELETE methodRafał Miłecki2015-01-221-0/+2
| | | | Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
* use const for char buffer in uclient_writeRafał Miłecki2015-01-221-1/+1
| | | | | | We are not supposed to modify it and ustream accepts const already. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
* support for connection timeoutRafał Miłecki2015-01-181-2/+11
| | | | Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
* http: fix processing of digest auth parametersFelix Fietkau2014-12-101-3/+30
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* http: terminate old connection in uclient_http_connect after incomplete ↵Felix Fietkau2014-09-041-0/+3
| | | | | | request processing Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* http: do not call uclient_http_disconnect from uclient_notify_eof directlyFelix Fietkau2014-09-041-13/+13
| | | | | | Depending on the context, it can lead to crashes Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-http: only invoke data_sent callback if it is providedJo-Philipp Wich2014-09-041-1/+3
| | | | Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
* http: ignore empty lines before HTTP responseFelix Fietkau2014-08-211-0/+3
| | | | | | Fixes HTTP keepalive issues with some servers Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* http: implement data_sent write callbackLuka Perkov2014-07-071-0/+22
| | | | Signed-off-by: Luka Perkov <luka@openwrt.org>
* http: rework authentication handling - only retry internally for GET requestsFelix Fietkau2014-05-281-4/+2
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* fetch: indicate an error if the connection was terminated prematurelyFelix Fietkau2014-05-071-2/+6
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* add support for PUT requestsLuka Perkov2014-05-051-2/+4
| | | | Signed-off-by: Luka Perkov <luka@openwrt.org>
* add uclient_disconnect() to force a disconnect without further callbacksFelix Fietkau2014-05-041-0/+38
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* http: make ustream_ssl optional, only use provided ssl contextFelix Fietkau2014-05-041-18/+16
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* http: get address at initial connect timeFelix Fietkau2014-04-301-8/+9
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* add support for querying local/remote addressFelix Fietkau2014-04-071-0/+8
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* ignore empty writesFelix Fietkau2014-04-031-3/+4
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* add support for 204 (no content)Felix Fietkau2014-03-291-1/+1
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* fix arguments to uclient_http_reset_headersFelix Fietkau2014-03-291-1/+1
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* avoid sending duplicate headersFelix Fietkau2014-03-291-0/+2
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>