Go to file
Stefan Eissing d7b6ce64ce
lib: replace readwrite with write_resp
This clarifies the handling of server responses by folding the code for
the complicated protocols into their protocol handlers. This concerns
mainly HTTP and its bastard sibling RTSP.

The terms "read" and "write" are often used without clear context if
they refer to the connect or the client/application side of a
transfer. This PR uses "read/write" for operations on the client side
and "send/receive" for the connection, e.g. server side. If this is
considered useful, we can revisit renaming of further methods in another
PR.

Curl's protocol handler `readwrite()` method been changed:

```diff
-  CURLcode (*readwrite)(struct Curl_easy *data, struct connectdata *conn,
-                        const char *buf, size_t blen,
-                        size_t *pconsumed, bool *readmore);
+  CURLcode (*write_resp)(struct Curl_easy *data, const char *buf, size_t blen,
+                         bool is_eos, bool *done);
```

The name was changed to clarify that this writes reponse data to the
client side. The parameter changes are:

* `conn` removed as it always operates on `data->conn`
* `pconsumed` removed as the method needs to handle all data on success
* `readmore` removed as no longer necessary
* `is_eos` as indicator that this is the last call for the transfer
  response (end-of-stream).
* `done` TRUE on return iff the transfer response is to be treated as
  finished

This change affects many files only because of updated comments in
handlers that provide no implementation. The real change is that the
HTTP protocol handlers now provide an implementation.

The HTTP protocol handlers `write_resp()` implementation will get passed
**all** raw data of a server response for the transfer. The HTTP/1.x
formatted status and headers, as well as the undecoded response
body. `Curl_http_write_resp_hds()` is used internally to parse the
response headers and pass them on. This method is public as the RTSP
protocol handler also uses it.

HTTP/1.1 "chunked" transport encoding is now part of the general
*content encoding* writer stack, just like other encodings. A new flag
`CLIENTWRITE_EOS` was added for the last client write. This allows
writers to verify that they are in a valid end state. The chunked
decoder will check if it indeed has seen the last chunk.

The general response handling in `transfer.c:466` happens in function
`readwrite_data()`. This mainly operates now like:

```
static CURLcode readwrite_data(data, ...)
{
  do {
    Curl_xfer_recv_resp(data, buf)
    ...
    Curl_xfer_write_resp(data, buf)
    ...
  } while(interested);
  ...
}
```

All the response data handling is implemented in
`Curl_xfer_write_resp()`. It calls the protocol handler's `write_resp()`
implementation if available, or does the default behaviour.

All raw response data needs to pass through this function. Which also
means that anyone in possession of such data may call
`Curl_xfer_write_resp()`.

Closes #12480
2024-01-13 17:23:42 +01:00
.circleci CI: install libpsl or configure --without-libpsl in builds 2024-01-09 09:10:58 +01:00
.github CI: spellcheck/appveyor: invoke configure --without-libpsl 2024-01-09 16:00:29 +01:00
.reuse CI: Add dependabot.yml 2024-01-02 23:31:49 +01:00
CMake build: fix some -Wsign-conversion/-Warith-conversion warnings 2023-12-19 12:45:28 +00:00
docs TODO: TFTP doesn't convert LF to CRLF for mode=netascii 2024-01-13 16:26:17 +01:00
include getinfo: CURLINFO_QUEUE_TIME_T 2023-12-27 09:28:48 +01:00
lib lib: replace readwrite with write_resp 2024-01-13 17:23:42 +01:00
LICENSES
m4 configure: when enabling QUIC, check that TLS supports QUIC 2024-01-12 09:47:42 +01:00
packages build: delete unused HAVE_{GSSHEIMDAL,GSSMIT,HEIMDAL} 2023-12-16 13:16:52 +00:00
plan9
projects tidy-up: whitespace 2023-12-08 03:28:50 +00:00
scripts lib: replace readwrite with write_resp 2024-01-13 17:23:42 +01:00
src tool_getparam: move the --rate logic into set_rate() 2024-01-08 22:39:18 +01:00
tests lib: replace readwrite with write_resp 2024-01-13 17:23:42 +01:00
winbuild build: do not publish HAVE_BORINGSSL, HAVE_AWSLC macros 2023-10-08 22:29:45 +00:00
.azure-pipelines.yml CI: install libpsl or configure --without-libpsl in builds 2024-01-09 09:10:58 +01:00
.cirrus.yml CI: install libpsl or configure --without-libpsl in builds 2024-01-09 09:10:58 +01:00
.dcignore
.dir-locals.el
.git-blame-ignore-revs
.gitattributes
.gitignore
.mailmap
acinclude.m4 windows: delete redundant headers 2023-12-18 14:56:57 +00:00
appveyor.sh appveyor: tidy-ups 2023-12-23 03:33:22 +00:00
appveyor.yml CI: spellcheck/appveyor: invoke configure --without-libpsl 2024-01-09 16:00:29 +01:00
buildconf
buildconf.bat
CHANGES
CMakeLists.txt build: delete unused HAVE_{GSSHEIMDAL,GSSMIT,HEIMDAL} 2023-12-16 13:16:52 +00:00
configure.ac configure: when enabling QUIC, check that TLS supports QUIC 2024-01-12 09:47:42 +01:00
COPYING COPYING: update copyright year 2024-01-08 18:40:06 +01:00
curl-config.in
GIT-INFO
libcurl.def
libcurl.pc.in
MacOSX-Framework
Makefile.am Makefile.am: fix the MSVC project generation 2023-12-21 09:19:36 +01:00
Makefile.dist Makefile.mk: drop Windows support 2023-12-16 13:12:22 +00:00
maketgz
README
README.md
RELEASE-NOTES RELEASE-NOTES: synced 2024-01-13 17:02:45 +01:00
SECURITY.md

curl logo

Curl is a command-line tool for transferring data specified with URL syntax. Find out how to use curl by reading the curl.1 man page or the MANUAL document. Find out how to install Curl by reading the INSTALL document.

libcurl is the library curl is using to do its job. It is readily available to be used by your software. Read the libcurl.3 man page to learn how.

You can find answers to the most frequent questions we get in the FAQ document.

Study the COPYING file for distribution terms.

Contact

If you have problems, questions, ideas or suggestions, please contact us by posting to a suitable mailing list.

All contributors to the project are listed in the THANKS document.

Commercial support

For commercial support, maybe private and dedicated help with your problems or applications using (lib)curl visit the support page.

Website

Visit the curl website for the latest news and downloads.

Git

To download the latest source from the Git server, do this:

git clone https://github.com/curl/curl.git

(you will get a directory named curl created, filled with the source code)

Security problems

Report suspected security problems via our HackerOne page and not in public.

Notice

Curl contains pieces of source code that is Copyright (c) 1998, 1999 Kungliga Tekniska Högskolan. This notice is included here to comply with the distribution terms.

Backers

Thank you to all our backers! 🙏 Become a backer.

Sponsors

Support this project by becoming a sponsor.