Commit Graph

124 Commits

Author SHA1 Message Date
weizihan
9dd3055014 apps: Fix the bug that setsockopt didn't check return value
Signed-off-by: weizihan <weizihan@xiaomi.com>
2022-08-17 22:50:56 +08:00
YAMAMOTO Takashi
fe109998c9 webclient_get_tunnel: A comment about how to dispose the returned "conn" 2022-06-20 13:56:53 +08:00
YAMAMOTO Takashi
d435858c53 webclient: Export a few ops on webclient_conn_s
* Make webclient_conn_s self-contained so that it can be
  used without webclient_context.

* Add missing FAR.
2022-06-20 13:56:53 +08:00
YAMAMOTO Takashi
fca5b186b1 webclient: Make webclient_get_tunnel returns void
As it does never fail.
2022-06-20 13:56:53 +08:00
YAMAMOTO Takashi
eece4a5ca0 webclient_abort: Fix a resource leak for the tunneling case 2022-06-17 08:35:59 +03:00
YAMAMOTO Takashi
159ca00752 webclient: Allow users to specify extra headers for proxy
My primary motivation at this point is to use it for basic proxy auth.
(specify "Proxy-Authorization" header)
But there can be other use cases for proxy-specific extra headers.

If/when we want to support other non-trivial auth methods, probably
a callback-based mechanism will be necessary. But at this point,
this serves my purpose well.
2022-06-15 20:40:53 +08:00
YAMAMOTO Takashi
610b04fa97 webclient: Clear WGET_FLAG_GOT_CONTENT_LENGTH for each request
Otherwise, a stale value might be used after a redirection.
2022-06-07 15:09:11 +03:00
YAMAMOTO Takashi
065a130bc8 webclient: Be a bit strict on Location header
* Record Location header explicitly

* Bail out / warn on unexpected cases
2022-06-07 15:09:11 +03:00
YAMAMOTO Takashi
0c4c811434 webcilent: Fix a buffer overrun on a malformed status line 2022-06-07 15:09:11 +03:00
YAMAMOTO Takashi
a563014646 webclient: make webclient_get_tunnel assert http_status 2022-06-03 16:33:09 +08:00
YAMAMOTO Takashi
a696c8945e webclient: Don't forget to check http status before webclient_get_tunnel 2022-06-03 16:33:09 +08:00
YAMAMOTO Takashi
3f4e723ff7 webclient: dispose the response body by default
Instead of a NULL dereference.

This fixes a crash on CONNECT failure when trying to proxy https.
2022-06-03 16:33:09 +08:00
YAMAMOTO Takashi
dbee240869 webclient.c: Fix the placement of "Public Function" banner 2022-06-03 16:33:09 +08:00
YAMAMOTO Takashi
c116f8b673 webclient: Add https proxy (https over http) support
Use a separate webclient_context for tunnel establishment.

I chose this way (instead of having tunnelling steps in
the state machine of a single webclient_context) because
I want to allow tunnelling of non-HTTP protocols sooner or later.
2022-06-02 12:45:41 +08:00
YAMAMOTO Takashi
a95dd30f0e webclient: Add tunneling support
Add a primitive API for tunnel establishment.
(WEBCLIENT_FLAG_TUNNEL and webclient_get_tunnel)

I plan to use this to implement https proxy support.
That is, the primary user will be webclient itself.
2022-06-02 12:45:41 +08:00
YAMAMOTO Takashi
a46b144ab1 webclient: Remove an extra slash for proxy 2022-06-01 22:42:12 +08:00
YAMAMOTO Takashi
f7b0ad4b74 webclient: Require a port in proxy string 2022-05-24 22:42:54 +08:00
YAMAMOTO Takashi
4798f01449 webclient: Implement proxy
Only the very basic case (http over http) for now.
2022-05-24 22:42:54 +08:00
YAMAMOTO Takashi
4f4f4da526 webclient: Separate wget_target_s from wget_s
I plan to use the former for proxy settings.
2022-05-24 22:42:54 +08:00
YAMAMOTO Takashi
f2737a208c webclient: Remove a duplicated "Connection:" header
When making the following change, I haven't noticed that
g_httpuseragentfields contains a "Connection" header.

```
commit 092ce81444
Author: YAMAMOTO Takashi <yamamoto@midokura.com>
Date:   Mon Mar 7 09:30:23 2022 +0900

    webclient: Always use "connection: close" for HTTP 1.1 for now

    * This matches the HTTP 1.0 behavior.

    * Persistent connection doesn't make much sense with the current API.
```

It seems that some servers are not happy with the duplicated header
and ignore them. (and do the default keep-alive for HTTP 1.1)
eg. Azure Blob (global)
2022-03-08 11:52:35 +08:00
YAMAMOTO Takashi
8a5dc04be2 webclient: Remove an inappropriate comment (a copy-and-paste botch) 2022-03-08 11:52:28 +08:00
YAMAMOTO Takashi
44e80ac972 webclient: Implement chunked transfer (receiving side)
This is a requirement for HTTP 1.1.

Tested against:

* http://httpbin.org/stream/10

* Docker API
2022-03-08 09:39:55 +08:00
YAMAMOTO Takashi
092ce81444 webclient: Always use "connection: close" for HTTP 1.1 for now
* This matches the HTTP 1.0 behavior.

* Persistent connection doesn't make much sense with the current API.
2022-03-08 09:39:55 +08:00
YAMAMOTO Takashi
7949059ec2 webclient: Send HTTP 1.1 request if enabled 2022-03-08 09:39:55 +08:00
YAMAMOTO Takashi
3759da3d00 webclient: Add a parameter to specifiy protocol version 2022-03-08 09:39:55 +08:00
YAMAMOTO Takashi
78fb3bc240 webclient: handle EINTR in a few places 2021-09-14 14:39:29 +08:00
YAMAMOTO Takashi
23e0325698 webclient: check content-length
While it's better to use a reliable transport like
TLS with working close notify, it isn't always possible.
2021-08-16 09:47:44 -07:00
YAMAMOTO Takashi
bdae564c22 webclient: Add _s suffix to internal structures
To follow our coding standard.

I left the structures which is a part of the API for now.
(E.g. struct webclient_context)
2021-08-11 03:11:14 -07:00
YAMAMOTO Takashi
b8fd862965 webclient: Add some assertions on webclient_context state 2021-08-08 22:34:26 -07:00
YAMAMOTO Takashi
0bae950b63 webclient: Implement non-blocking I/O
* webclient_perform
    * Add a new flag to use non-blocking mode (WEBCLIENT_FLAG_NON_BLOCKING)
    * Implement restarting

* Add a few associated API functions
    * webclient_get_poll_info: get the descriptor info for poll/select
    * webclient_abort: abort the operation (instead of restarting)
2021-08-08 22:34:26 -07:00
Gustavo Henrique Nihei
a1026c9f23 netutils/webclient: Notify HTTP header data via dedicated callback
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2021-07-23 11:28:26 -07:00
YAMAMOTO Takashi
ce2b9519a7 webclient: Add a way to specify timeout 2021-06-15 05:18:14 -05:00
Alin Jerpelea
ec339bc49a Makefiles: Gregory Nutt: update licenses to Apache
Gregory Nutt is the copyright holder for those files and he has submitted the
SGA as a result we can migrate the licenses to Apache.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2021-06-07 21:35:33 -05:00
YAMAMOTO Takashi
95c9007668 webclient: Fix buffer overrun in wget_parsestatus
Similarly to the fix in wget_parseheaders.
But simply always bail out as i guess it's very rare to see
that long status line.

Tested with an aritifically small CONFIG_WEBCLIENT_MAXHTTPLINE=20,
which is smaller than "HTTP/1.1 301 Moved Permanently".
2021-05-16 11:32:47 -03:00
YAMAMOTO Takashi
b53375074b webclient.c: Fix buffer overrun in HTTP header parsing
* Detect a long header line which doesn't fit the buffer.

* If the header line in question doesn't seem important for us,
  just ignore it.

* Otherwise, bail out with -E2BIG.

The overrun was found by LLVM UBSan on macOS.

The following is an example of a long header line,
which doesn't fit the default CONFIG_WEBCLIENT_MAXHTTPLINE=200.
```
pacetanuki% curl -v https://www.midokura.com
:
:
< HTTP/2 200
< server: nginx
< date: Fri, 14 May 2021 02:16:24 GMT
< content-type: text/html; charset=UTF-8
< content-length: 131313
< x-powered-by: PHP/7.4.18
< link: <https://www.midokura.com/wp-json/>; rel="https://api.w.org/", <https://www.midokura.com/wp-json/wp/v2/pages/7>; rel="alternate"; type="application/json", <https://www.midokura.com/>; rel=shortlink
< x-powered-by: PleskLin
<
```
2021-05-16 11:32:47 -03:00
YAMAMOTO Takashi
eb1a99fdd6 webclient.c: Don't parse the status line as the first header line 2021-05-16 11:32:47 -03:00
YAMAMOTO Takashi
f17af21f9c webclient: Add a few ninfo in header parsing 2021-05-16 11:32:47 -03:00
Atsunori Saito
a12f9d967c netutils/webclient: Fixed socket descriptor leak. 2021-05-03 16:44:28 +09:00
YAMAMOTO Takashi
2d0a174cec webclient: 304 and 305 are not really redirects
Eg. The docker API sometimes returns 304 even for requests without etags.
https://docs.docker.com/engine/api/v1.40/#operation/ContainerStop
2021-04-07 06:44:16 -05:00
YAMAMOTO Takashi
15c65b23c7 netutils/webclient/webclient.c: Appease the latest nxstyle 2021-04-07 06:44:16 -05:00
YAMAMOTO Takashi
f613da4f92 webclient.c: Remove a space after a negative sign
from:

    return - ECONNABORTED;

to:

    return -ECONNABORTED;

The latter style is more commonly used within NuttX code base.

Note: nxstyle doesn't complain on either of them.
2021-02-12 08:51:23 +00:00
YAMAMOTO Takashi
412cf2b955 webclient: Fix a use of uninitialized variable
Detected by clang static analyzer.
2021-01-19 19:06:24 -08:00
YAMAMOTO Takashi
ee1f4fdcdb webclient: Don't call the sink callback if no data is available
This happened frequently for me with Docker Desktop's
/var/run/docker.sock on macOS.
But I believe it can happen on other environments, even with TCP.

Alternatively, this case can be handled by the callback
implementations.  But it's simpler to handle the corner case here.
2021-01-17 18:44:17 -08:00
YAMAMOTO Takashi
1131cbe14d webclient: Implement AF_LOCAL 2021-01-17 18:44:17 -08:00
YAMAMOTO Takashi
ebe3b0d302 webclient: Report unexpected connection loss as an explicit error
Otherwise, it can end up with mysterious results in user apps.
2021-01-13 20:51:06 -06:00
YAMAMOTO Takashi
73fb7baa05 webclient: Distinguish request size and buffer size in body callback
This fixes the case when webclient_set_static_body is used
for data larger than webclient_context::buflen.

Note: as of writing this, webclient_set_static_body is the
only user of body_callback in NuttX apps tree.
2020-11-19 18:46:38 -08:00
YAMAMOTO Takashi
a1db71fa43 webclient improvements
Highlights:

* TLS support (a hook to allow users to provide TLS implementation)
* ability to add extra request headers
* ability to use PUT method
* ability to report http status
* error handling improvements

Proposed on the ML while ago:
https://www.mail-archive.com/dev@nuttx.apache.org/msg03803.html

The original API is kept for now.
I plan to remove them after adapting the existing users.
(examples in this repo)
2020-10-01 15:32:25 +08:00
YAMAMOTO Takashi
b78370dbf2 webclient: move WGET_USE_URLENCODE definiton to the header
Because it's used by the header.

This fixes warnings while building wgetjson.
2020-09-30 08:22:16 +02:00
SPRESENSE
78e8090842 examples: wget: Fix nxstyle issues 2020-08-18 10:07:47 -05:00
SPRESENSE
7a1d626504 netutils/webclient: Enable to send long HTTP request
Call send() repeatedly until whole buffer to be sent.
2020-08-18 10:07:47 -05:00