2020-12-14 16:10:33 +03:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2023-01-02 15:51:48 +03:00
|
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
2020-12-14 16:10:33 +03:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: curl
|
2022-05-17 12:16:50 +03:00
|
|
|
*
|
2020-12-14 16:10:33 +03:00
|
|
|
***************************************************************************/
|
|
|
|
|
2023-10-24 17:51:05 +03:00
|
|
|
/* Curl's integration with Hyper. This replaces certain functions in http.c,
|
|
|
|
* based on configuration #defines. This implementation supports HTTP/1.1 but
|
|
|
|
* not HTTP/2.
|
|
|
|
*/
|
2020-12-14 16:10:33 +03:00
|
|
|
#include "curl_setup.h"
|
|
|
|
|
|
|
|
#if !defined(CURL_DISABLE_HTTP) && defined(USE_HYPER)
|
|
|
|
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_NETDB_H
|
|
|
|
#include <netdb.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ARPA_INET_H
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NET_IF_H
|
|
|
|
#include <net/if.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
#include <sys/param.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <hyper.h>
|
|
|
|
#include "urldata.h"
|
2024-02-14 14:09:32 +03:00
|
|
|
#include "cfilters.h"
|
2020-12-14 16:10:33 +03:00
|
|
|
#include "sendf.h"
|
2024-02-06 16:56:05 +03:00
|
|
|
#include "headers.h"
|
2020-12-14 16:10:33 +03:00
|
|
|
#include "transfer.h"
|
|
|
|
#include "multiif.h"
|
|
|
|
#include "progress.h"
|
2021-03-11 18:05:15 +03:00
|
|
|
#include "content_encoding.h"
|
2022-09-09 16:11:14 +03:00
|
|
|
#include "ws.h"
|
2020-12-14 16:10:33 +03:00
|
|
|
|
|
|
|
/* The last 3 #include files should be in this order */
|
|
|
|
#include "curl_printf.h"
|
|
|
|
#include "curl_memory.h"
|
|
|
|
#include "memdebug.h"
|
|
|
|
|
2023-09-01 04:41:22 +03:00
|
|
|
typedef enum {
|
|
|
|
USERDATA_NOT_SET = 0, /* for tasks with no userdata set; must be zero */
|
|
|
|
USERDATA_RESP_BODY
|
|
|
|
} userdata_t;
|
|
|
|
|
2021-01-04 11:36:41 +03:00
|
|
|
size_t Curl_hyper_recv(void *userp, hyper_context *ctx,
|
|
|
|
uint8_t *buf, size_t buflen)
|
2020-12-14 16:10:33 +03:00
|
|
|
{
|
2024-02-14 14:09:32 +03:00
|
|
|
struct hyp_io_ctx *io_ctx = userp;
|
|
|
|
struct Curl_easy *data = io_ctx->data;
|
2021-01-21 18:49:14 +03:00
|
|
|
struct connectdata *conn = data->conn;
|
2020-12-14 16:10:33 +03:00
|
|
|
CURLcode result;
|
|
|
|
ssize_t nread;
|
2021-01-30 19:51:00 +03:00
|
|
|
DEBUGASSERT(conn);
|
2020-12-14 16:10:33 +03:00
|
|
|
(void)ctx;
|
|
|
|
|
2023-06-19 13:11:53 +03:00
|
|
|
DEBUGF(infof(data, "Curl_hyper_recv(%zu)", buflen));
|
2024-02-14 14:09:32 +03:00
|
|
|
result = Curl_conn_recv(data, io_ctx->sockindex,
|
|
|
|
(char *)buf, buflen, &nread);
|
2020-12-14 16:10:33 +03:00
|
|
|
if(result == CURLE_AGAIN) {
|
|
|
|
/* would block, register interest */
|
2023-06-19 13:11:53 +03:00
|
|
|
DEBUGF(infof(data, "Curl_hyper_recv(%zu) -> EAGAIN", buflen));
|
2020-12-14 16:10:33 +03:00
|
|
|
if(data->hyp.read_waker)
|
|
|
|
hyper_waker_free(data->hyp.read_waker);
|
|
|
|
data->hyp.read_waker = hyper_context_waker(ctx);
|
|
|
|
if(!data->hyp.read_waker) {
|
|
|
|
failf(data, "Couldn't make the read hyper_context_waker");
|
|
|
|
return HYPER_IO_ERROR;
|
|
|
|
}
|
|
|
|
return HYPER_IO_PENDING;
|
|
|
|
}
|
|
|
|
else if(result) {
|
|
|
|
failf(data, "Curl_read failed");
|
|
|
|
return HYPER_IO_ERROR;
|
|
|
|
}
|
2023-06-19 13:11:53 +03:00
|
|
|
DEBUGF(infof(data, "Curl_hyper_recv(%zu) -> %zd", buflen, nread));
|
2020-12-14 16:10:33 +03:00
|
|
|
return (size_t)nread;
|
|
|
|
}
|
|
|
|
|
2021-01-04 11:36:41 +03:00
|
|
|
size_t Curl_hyper_send(void *userp, hyper_context *ctx,
|
2020-12-14 16:10:33 +03:00
|
|
|
const uint8_t *buf, size_t buflen)
|
|
|
|
{
|
2024-02-14 14:09:32 +03:00
|
|
|
struct hyp_io_ctx *io_ctx = userp;
|
|
|
|
struct Curl_easy *data = io_ctx->data;
|
2020-12-14 16:10:33 +03:00
|
|
|
CURLcode result;
|
|
|
|
ssize_t nwrote;
|
|
|
|
|
2023-06-19 13:11:53 +03:00
|
|
|
DEBUGF(infof(data, "Curl_hyper_send(%zu)", buflen));
|
2024-02-14 14:09:32 +03:00
|
|
|
result = Curl_conn_send(data, io_ctx->sockindex,
|
|
|
|
(void *)buf, buflen, &nwrote);
|
2020-12-14 16:10:33 +03:00
|
|
|
if(result == CURLE_AGAIN) {
|
2023-06-19 13:11:53 +03:00
|
|
|
DEBUGF(infof(data, "Curl_hyper_send(%zu) -> EAGAIN", buflen));
|
2020-12-14 16:10:33 +03:00
|
|
|
/* would block, register interest */
|
|
|
|
if(data->hyp.write_waker)
|
|
|
|
hyper_waker_free(data->hyp.write_waker);
|
|
|
|
data->hyp.write_waker = hyper_context_waker(ctx);
|
|
|
|
if(!data->hyp.write_waker) {
|
|
|
|
failf(data, "Couldn't make the write hyper_context_waker");
|
|
|
|
return HYPER_IO_ERROR;
|
|
|
|
}
|
|
|
|
return HYPER_IO_PENDING;
|
|
|
|
}
|
|
|
|
else if(result) {
|
|
|
|
failf(data, "Curl_write failed");
|
|
|
|
return HYPER_IO_ERROR;
|
|
|
|
}
|
2023-06-19 13:11:53 +03:00
|
|
|
DEBUGF(infof(data, "Curl_hyper_send(%zu) -> %zd", buflen, nwrote));
|
2020-12-14 16:10:33 +03:00
|
|
|
return (size_t)nwrote;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hyper_each_header(void *userdata,
|
|
|
|
const uint8_t *name,
|
|
|
|
size_t name_len,
|
|
|
|
const uint8_t *value,
|
|
|
|
size_t value_len)
|
|
|
|
{
|
|
|
|
struct Curl_easy *data = (struct Curl_easy *)userdata;
|
|
|
|
size_t len;
|
|
|
|
char *headp;
|
|
|
|
CURLcode result;
|
2021-06-07 14:07:37 +03:00
|
|
|
int writetype;
|
2021-06-07 14:16:07 +03:00
|
|
|
|
2021-07-05 18:13:29 +03:00
|
|
|
if(name_len + value_len + 2 > CURL_MAX_HTTP_HEADER) {
|
|
|
|
failf(data, "Too long response header");
|
2023-12-18 12:34:17 +03:00
|
|
|
data->state.hresult = CURLE_TOO_LARGE;
|
2021-07-05 18:13:29 +03:00
|
|
|
return HYPER_ITER_BREAK;
|
|
|
|
}
|
|
|
|
|
2021-06-07 14:16:07 +03:00
|
|
|
if(!data->req.bytecount)
|
|
|
|
Curl_pgrsTime(data, TIMER_STARTTRANSFER);
|
|
|
|
|
2020-12-14 16:10:33 +03:00
|
|
|
Curl_dyn_reset(&data->state.headerb);
|
|
|
|
if(name_len) {
|
|
|
|
if(Curl_dyn_addf(&data->state.headerb, "%.*s: %.*s\r\n",
|
|
|
|
(int) name_len, name, (int) value_len, value))
|
|
|
|
return HYPER_ITER_BREAK;
|
|
|
|
}
|
|
|
|
else {
|
2022-02-07 21:25:09 +03:00
|
|
|
if(Curl_dyn_addn(&data->state.headerb, STRCONST("\r\n")))
|
2020-12-14 16:10:33 +03:00
|
|
|
return HYPER_ITER_BREAK;
|
|
|
|
}
|
|
|
|
len = Curl_dyn_len(&data->state.headerb);
|
|
|
|
headp = Curl_dyn_ptr(&data->state.headerb);
|
|
|
|
|
|
|
|
result = Curl_http_header(data, data->conn, headp);
|
|
|
|
if(result) {
|
|
|
|
data->state.hresult = result;
|
|
|
|
return HYPER_ITER_BREAK;
|
|
|
|
}
|
|
|
|
|
|
|
|
Curl_debug(data, CURLINFO_HEADER_IN, headp, len);
|
|
|
|
|
2023-10-23 11:33:07 +03:00
|
|
|
writetype = CLIENTWRITE_HEADER;
|
|
|
|
if(data->state.hconnect)
|
|
|
|
writetype |= CLIENTWRITE_CONNECT;
|
|
|
|
if(data->req.httpcode/100 == 1)
|
|
|
|
writetype |= CLIENTWRITE_1XX;
|
|
|
|
result = Curl_client_write(data, writetype, headp, len);
|
|
|
|
if(result) {
|
|
|
|
data->state.hresult = CURLE_ABORTED_BY_CALLBACK;
|
|
|
|
return HYPER_ITER_BREAK;
|
2020-12-14 16:10:33 +03:00
|
|
|
}
|
|
|
|
|
2023-08-03 00:34:48 +03:00
|
|
|
result = Curl_bump_headersize(data, len, FALSE);
|
|
|
|
if(result) {
|
|
|
|
data->state.hresult = result;
|
|
|
|
return HYPER_ITER_BREAK;
|
|
|
|
}
|
2020-12-14 16:10:33 +03:00
|
|
|
return HYPER_ITER_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hyper_body_chunk(void *userdata, const hyper_buf *chunk)
|
|
|
|
{
|
|
|
|
char *buf = (char *)hyper_buf_bytes(chunk);
|
|
|
|
size_t len = hyper_buf_len(chunk);
|
|
|
|
struct Curl_easy *data = (struct Curl_easy *)userdata;
|
|
|
|
struct SingleRequest *k = &data->req;
|
2021-08-13 18:29:33 +03:00
|
|
|
CURLcode result = CURLE_OK;
|
2020-12-14 16:10:33 +03:00
|
|
|
|
2023-10-23 11:33:07 +03:00
|
|
|
if(0 == k->bodywrites) {
|
2020-12-14 16:10:33 +03:00
|
|
|
bool done = FALSE;
|
2021-05-31 16:11:27 +03:00
|
|
|
#if defined(USE_NTLM)
|
|
|
|
struct connectdata *conn = data->conn;
|
|
|
|
if(conn->bits.close &&
|
|
|
|
(((data->req.httpcode == 401) &&
|
|
|
|
(conn->http_ntlm_state == NTLMSTATE_TYPE2)) ||
|
|
|
|
((data->req.httpcode == 407) &&
|
|
|
|
(conn->proxy_ntlm_state == NTLMSTATE_TYPE2)))) {
|
2021-07-06 18:05:17 +03:00
|
|
|
infof(data, "Connection closed while negotiating NTLM");
|
2021-05-31 16:11:27 +03:00
|
|
|
data->state.authproblem = TRUE;
|
|
|
|
Curl_safefree(data->req.newurl);
|
|
|
|
}
|
|
|
|
#endif
|
2021-08-13 18:29:33 +03:00
|
|
|
if(data->state.expect100header) {
|
|
|
|
Curl_expire_done(data, EXPIRE_100_TIMEOUT);
|
|
|
|
if(data->req.httpcode < 400) {
|
|
|
|
k->exp100 = EXP100_SEND_DATA;
|
|
|
|
if(data->hyp.exp100_waker) {
|
|
|
|
hyper_waker_wake(data->hyp.exp100_waker);
|
|
|
|
data->hyp.exp100_waker = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { /* >= 4xx */
|
|
|
|
k->exp100 = EXP100_FAILED;
|
|
|
|
}
|
|
|
|
}
|
2021-10-22 11:57:54 +03:00
|
|
|
if(data->state.hconnect && (data->req.httpcode/100 != 2) &&
|
|
|
|
data->state.authproxy.done) {
|
2021-06-09 00:30:57 +03:00
|
|
|
done = TRUE;
|
|
|
|
result = CURLE_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result = Curl_http_firstwrite(data, data->conn, &done);
|
2020-12-14 16:10:33 +03:00
|
|
|
if(result || done) {
|
2021-07-06 18:05:17 +03:00
|
|
|
infof(data, "Return early from hyper_body_chunk");
|
2020-12-14 16:10:33 +03:00
|
|
|
data->state.hresult = result;
|
|
|
|
return HYPER_ITER_BREAK;
|
|
|
|
}
|
|
|
|
}
|
2023-09-20 12:59:16 +03:00
|
|
|
result = Curl_client_write(data, CLIENTWRITE_BODY, buf, len);
|
2020-12-14 16:10:33 +03:00
|
|
|
|
2021-01-18 01:49:15 +03:00
|
|
|
if(result) {
|
|
|
|
data->state.hresult = result;
|
2020-12-14 16:10:33 +03:00
|
|
|
return HYPER_ITER_BREAK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return HYPER_ITER_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2022-10-26 09:59:35 +03:00
|
|
|
* Hyper does not consider the status line, the first line in an HTTP/1
|
2020-12-14 16:10:33 +03:00
|
|
|
* response, to be a header. The libcurl API does. This function sends the
|
|
|
|
* status line in the header callback. */
|
|
|
|
static CURLcode status_line(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn,
|
|
|
|
uint16_t http_status,
|
|
|
|
int http_version,
|
|
|
|
const uint8_t *reason, size_t rlen)
|
|
|
|
{
|
|
|
|
CURLcode result;
|
|
|
|
size_t len;
|
|
|
|
const char *vstr;
|
2021-06-07 14:07:37 +03:00
|
|
|
int writetype;
|
2020-12-14 16:10:33 +03:00
|
|
|
vstr = http_version == HYPER_HTTP_VERSION_1_1 ? "1.1" :
|
|
|
|
(http_version == HYPER_HTTP_VERSION_2 ? "2" : "1.0");
|
2021-10-21 20:44:29 +03:00
|
|
|
|
|
|
|
/* We need to set 'httpcodeq' for functions that check the response code in
|
|
|
|
a single place. */
|
2020-12-14 16:10:33 +03:00
|
|
|
data->req.httpcode = http_status;
|
|
|
|
|
2022-12-08 19:47:54 +03:00
|
|
|
if(data->state.hconnect)
|
|
|
|
/* CONNECT */
|
|
|
|
data->info.httpproxycode = http_status;
|
|
|
|
else {
|
|
|
|
conn->httpversion =
|
|
|
|
http_version == HYPER_HTTP_VERSION_1_1 ? 11 :
|
|
|
|
(http_version == HYPER_HTTP_VERSION_2 ? 20 : 10);
|
|
|
|
if(http_version == HYPER_HTTP_VERSION_1_0)
|
|
|
|
data->state.httpwant = CURL_HTTP_VERSION_1_0;
|
|
|
|
|
|
|
|
result = Curl_http_statusline(data, conn);
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
}
|
2020-12-14 16:10:33 +03:00
|
|
|
|
|
|
|
Curl_dyn_reset(&data->state.headerb);
|
|
|
|
|
|
|
|
result = Curl_dyn_addf(&data->state.headerb, "HTTP/%s %03d %.*s\r\n",
|
|
|
|
vstr,
|
|
|
|
(int)http_status,
|
|
|
|
(int)rlen, reason);
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
len = Curl_dyn_len(&data->state.headerb);
|
|
|
|
Curl_debug(data, CURLINFO_HEADER_IN, Curl_dyn_ptr(&data->state.headerb),
|
|
|
|
len);
|
|
|
|
|
2023-10-23 11:33:07 +03:00
|
|
|
writetype = CLIENTWRITE_HEADER|CLIENTWRITE_STATUS;
|
|
|
|
if(data->state.hconnect)
|
|
|
|
writetype |= CLIENTWRITE_CONNECT;
|
|
|
|
result = Curl_client_write(data, writetype,
|
|
|
|
Curl_dyn_ptr(&data->state.headerb), len);
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
|
2023-08-03 00:34:48 +03:00
|
|
|
result = Curl_bump_headersize(data, len, FALSE);
|
|
|
|
return result;
|
2020-12-14 16:10:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hyper does not pass on the last empty response header. The libcurl API
|
|
|
|
* does. This function sends an empty header in the header callback.
|
|
|
|
*/
|
|
|
|
static CURLcode empty_header(struct Curl_easy *data)
|
|
|
|
{
|
2021-10-01 20:57:23 +03:00
|
|
|
CURLcode result = Curl_http_size(data);
|
|
|
|
if(!result) {
|
|
|
|
result = hyper_each_header(data, NULL, 0, NULL, 0) ?
|
|
|
|
CURLE_WRITE_ERROR : CURLE_OK;
|
|
|
|
if(result)
|
|
|
|
failf(data, "hyperstream: couldn't pass blank header");
|
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
2023-12-01 15:50:32 +03:00
|
|
|
/* Hyper does chunked decoding itself. If it was added during
|
|
|
|
* response header processing, remove it again. */
|
|
|
|
Curl_cwriter_remove_by_name(data, "chunked");
|
2021-10-01 20:57:23 +03:00
|
|
|
}
|
|
|
|
return result;
|
2020-12-14 16:10:33 +03:00
|
|
|
}
|
|
|
|
|
2021-01-04 11:36:41 +03:00
|
|
|
CURLcode Curl_hyper_stream(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn,
|
|
|
|
int *didwhat,
|
|
|
|
bool *done,
|
|
|
|
int select_res)
|
2020-12-14 16:10:33 +03:00
|
|
|
{
|
|
|
|
hyper_response *resp = NULL;
|
|
|
|
uint16_t http_status;
|
|
|
|
int http_version;
|
|
|
|
hyper_headers *headers = NULL;
|
|
|
|
hyper_body *resp_body = NULL;
|
|
|
|
struct hyptransfer *h = &data->hyp;
|
|
|
|
hyper_task *task;
|
|
|
|
hyper_task *foreach;
|
|
|
|
const uint8_t *reasonp;
|
|
|
|
size_t reason_len;
|
|
|
|
CURLcode result = CURLE_OK;
|
2021-08-13 18:29:33 +03:00
|
|
|
struct SingleRequest *k = &data->req;
|
2020-12-14 16:10:33 +03:00
|
|
|
(void)conn;
|
|
|
|
|
2021-08-13 18:29:33 +03:00
|
|
|
if(k->exp100 > EXP100_SEND_DATA) {
|
|
|
|
struct curltime now = Curl_now();
|
|
|
|
timediff_t ms = Curl_timediff(now, k->start100);
|
|
|
|
if(ms >= data->set.expect_100_timeout) {
|
|
|
|
/* we've waited long enough, continue anyway */
|
|
|
|
k->exp100 = EXP100_SEND_DATA;
|
|
|
|
k->keepon |= KEEP_SEND;
|
|
|
|
Curl_expire_done(data, EXPIRE_100_TIMEOUT);
|
|
|
|
infof(data, "Done waiting for 100-continue");
|
|
|
|
if(data->hyp.exp100_waker) {
|
|
|
|
hyper_waker_wake(data->hyp.exp100_waker);
|
|
|
|
data->hyp.exp100_waker = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-14 16:10:33 +03:00
|
|
|
if(select_res & CURL_CSELECT_IN) {
|
|
|
|
if(h->read_waker)
|
|
|
|
hyper_waker_wake(h->read_waker);
|
|
|
|
h->read_waker = NULL;
|
|
|
|
}
|
|
|
|
if(select_res & CURL_CSELECT_OUT) {
|
|
|
|
if(h->write_waker)
|
|
|
|
hyper_waker_wake(h->write_waker);
|
|
|
|
h->write_waker = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*done = FALSE;
|
|
|
|
do {
|
|
|
|
hyper_task_return_type t;
|
|
|
|
task = hyper_executor_poll(h->exec);
|
|
|
|
if(!task) {
|
|
|
|
*didwhat = KEEP_RECV;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
t = hyper_task_type(task);
|
|
|
|
if(t == HYPER_TASK_ERROR) {
|
2023-09-01 04:41:22 +03:00
|
|
|
hyper_error *hypererr = hyper_task_value(task);
|
|
|
|
hyper_task_free(task);
|
2021-07-26 15:54:13 +03:00
|
|
|
if(data->state.hresult) {
|
2020-12-14 16:10:33 +03:00
|
|
|
/* override Hyper's view, might not even be an error */
|
|
|
|
result = data->state.hresult;
|
2021-07-06 18:05:17 +03:00
|
|
|
infof(data, "hyperstream is done (by early callback)");
|
2020-12-14 16:10:33 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
uint8_t errbuf[256];
|
|
|
|
size_t errlen = hyper_error_print(hypererr, errbuf, sizeof(errbuf));
|
2021-01-04 18:55:30 +03:00
|
|
|
hyper_code code = hyper_error_code(hypererr);
|
|
|
|
failf(data, "Hyper: [%d] %.*s", (int)code, (int)errlen, errbuf);
|
2023-08-08 14:19:37 +03:00
|
|
|
switch(code) {
|
|
|
|
case HYPERE_ABORTED_BY_CALLBACK:
|
2021-07-26 15:54:13 +03:00
|
|
|
result = CURLE_OK;
|
2023-08-08 14:19:37 +03:00
|
|
|
break;
|
|
|
|
case HYPERE_UNEXPECTED_EOF:
|
|
|
|
if(!data->req.bytecount)
|
|
|
|
result = CURLE_GOT_NOTHING;
|
|
|
|
else
|
|
|
|
result = CURLE_RECV_ERROR;
|
|
|
|
break;
|
|
|
|
case HYPERE_INVALID_PEER_MESSAGE:
|
|
|
|
/* bump headerbytecount to avoid the count remaining at zero and
|
|
|
|
appearing to not having read anything from the peer at all */
|
|
|
|
data->req.headerbytecount++;
|
2021-05-27 18:04:05 +03:00
|
|
|
result = CURLE_UNSUPPORTED_PROTOCOL; /* maybe */
|
2023-08-08 14:19:37 +03:00
|
|
|
break;
|
|
|
|
default:
|
2021-01-04 18:55:30 +03:00
|
|
|
result = CURLE_RECV_ERROR;
|
2023-08-08 14:19:37 +03:00
|
|
|
break;
|
|
|
|
}
|
2020-12-14 16:10:33 +03:00
|
|
|
}
|
|
|
|
*done = TRUE;
|
|
|
|
hyper_error_free(hypererr);
|
|
|
|
break;
|
|
|
|
}
|
2023-09-01 04:41:22 +03:00
|
|
|
else if(t == HYPER_TASK_EMPTY) {
|
|
|
|
void *userdata = hyper_task_userdata(task);
|
|
|
|
hyper_task_free(task);
|
|
|
|
if((userdata_t)userdata == USERDATA_RESP_BODY) {
|
|
|
|
/* end of transfer */
|
|
|
|
*done = TRUE;
|
|
|
|
infof(data, "hyperstream is done");
|
|
|
|
if(!k->bodywrites) {
|
|
|
|
/* hyper doesn't always call the body write callback */
|
|
|
|
bool stilldone;
|
|
|
|
result = Curl_http_firstwrite(data, data->conn, &stilldone);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* A background task for hyper; ignore */
|
|
|
|
continue;
|
2021-08-30 18:49:25 +03:00
|
|
|
}
|
2020-12-14 16:10:33 +03:00
|
|
|
}
|
2023-09-01 04:41:22 +03:00
|
|
|
|
|
|
|
DEBUGASSERT(HYPER_TASK_RESPONSE);
|
|
|
|
|
|
|
|
resp = hyper_task_value(task);
|
|
|
|
hyper_task_free(task);
|
2020-12-14 16:10:33 +03:00
|
|
|
|
|
|
|
*didwhat = KEEP_RECV;
|
|
|
|
if(!resp) {
|
2020-12-24 01:41:13 +03:00
|
|
|
failf(data, "hyperstream: couldn't get response");
|
2020-12-14 16:10:33 +03:00
|
|
|
return CURLE_RECV_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
http_status = hyper_response_status(resp);
|
|
|
|
http_version = hyper_response_version(resp);
|
|
|
|
reasonp = hyper_response_reason_phrase(resp);
|
|
|
|
reason_len = hyper_response_reason_phrase_len(resp);
|
|
|
|
|
2022-05-07 03:34:14 +03:00
|
|
|
if(http_status == 417 && data->state.expect100header) {
|
|
|
|
infof(data, "Got 417 while waiting for a 100");
|
|
|
|
data->state.disableexpect = TRUE;
|
|
|
|
data->req.newurl = strdup(data->state.url);
|
|
|
|
Curl_done_sending(data, k);
|
|
|
|
}
|
|
|
|
|
2020-12-14 16:10:33 +03:00
|
|
|
result = status_line(data, conn,
|
|
|
|
http_status, http_version, reasonp, reason_len);
|
|
|
|
if(result)
|
|
|
|
break;
|
|
|
|
|
|
|
|
headers = hyper_response_headers(resp);
|
|
|
|
if(!headers) {
|
2020-12-24 01:41:13 +03:00
|
|
|
failf(data, "hyperstream: couldn't get response headers");
|
2020-12-14 16:10:33 +03:00
|
|
|
result = CURLE_RECV_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the headers are already received */
|
|
|
|
hyper_headers_foreach(headers, hyper_each_header, data);
|
|
|
|
if(data->state.hresult) {
|
|
|
|
result = data->state.hresult;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-10-01 20:57:23 +03:00
|
|
|
result = empty_header(data);
|
|
|
|
if(result)
|
2020-12-14 16:10:33 +03:00
|
|
|
break;
|
|
|
|
|
2022-09-09 16:11:14 +03:00
|
|
|
k->deductheadercount =
|
|
|
|
(100 <= http_status && 199 >= http_status)?k->headerbytecount:0;
|
|
|
|
#ifdef USE_WEBSOCKETS
|
|
|
|
if(k->upgr101 == UPGR101_WS) {
|
|
|
|
if(http_status == 101) {
|
|
|
|
/* verify the response */
|
2023-02-08 16:24:49 +03:00
|
|
|
result = Curl_ws_accept(data, NULL, 0);
|
2022-09-09 16:11:14 +03:00
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
failf(data, "Expected 101, got %u", k->httpcode);
|
|
|
|
result = CURLE_HTTP_RETURNED_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-12-30 13:58:39 +03:00
|
|
|
/* Curl_http_auth_act() checks what authentication methods that are
|
|
|
|
* available and decides which one (if any) to use. It will set 'newurl'
|
|
|
|
* if an auth method was picked. */
|
2021-01-08 19:58:15 +03:00
|
|
|
result = Curl_http_auth_act(data);
|
2020-12-30 13:58:39 +03:00
|
|
|
if(result)
|
|
|
|
break;
|
|
|
|
|
2020-12-14 16:10:33 +03:00
|
|
|
resp_body = hyper_response_body(resp);
|
|
|
|
if(!resp_body) {
|
2020-12-24 01:41:13 +03:00
|
|
|
failf(data, "hyperstream: couldn't get response body");
|
2020-12-14 16:10:33 +03:00
|
|
|
result = CURLE_RECV_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
foreach = hyper_body_foreach(resp_body, hyper_body_chunk, data);
|
|
|
|
if(!foreach) {
|
2020-12-24 01:41:13 +03:00
|
|
|
failf(data, "hyperstream: body foreach failed");
|
2020-12-14 16:10:33 +03:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2023-09-01 04:41:22 +03:00
|
|
|
hyper_task_set_userdata(foreach, (void *)USERDATA_RESP_BODY);
|
2020-12-14 16:10:33 +03:00
|
|
|
if(HYPERE_OK != hyper_executor_push(h->exec, foreach)) {
|
|
|
|
failf(data, "Couldn't hyper_executor_push the body-foreach");
|
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
hyper_response_free(resp);
|
|
|
|
resp = NULL;
|
|
|
|
} while(1);
|
|
|
|
if(resp)
|
|
|
|
hyper_response_free(resp);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CURLcode debug_request(struct Curl_easy *data,
|
|
|
|
const char *method,
|
2023-10-24 17:51:05 +03:00
|
|
|
const char *path)
|
2020-12-14 16:10:33 +03:00
|
|
|
{
|
2023-10-24 17:51:05 +03:00
|
|
|
char *req = aprintf("%s %s HTTP/1.1\r\n", method, path);
|
2020-12-14 16:10:33 +03:00
|
|
|
if(!req)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
Curl_debug(data, CURLINFO_HEADER_OUT, req, strlen(req));
|
|
|
|
free(req);
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a full header line "name: value" (optional CRLF in the input, should
|
|
|
|
* be in the output), add to Hyper and send to the debug callback.
|
|
|
|
*
|
|
|
|
* Supports multiple headers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
CURLcode Curl_hyper_header(struct Curl_easy *data, hyper_headers *headers,
|
|
|
|
const char *line)
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
const char *n;
|
|
|
|
size_t nlen;
|
|
|
|
const char *v;
|
|
|
|
size_t vlen;
|
|
|
|
bool newline = TRUE;
|
|
|
|
int numh = 0;
|
|
|
|
|
|
|
|
if(!line)
|
|
|
|
return CURLE_OK;
|
|
|
|
n = line;
|
|
|
|
do {
|
|
|
|
size_t linelen = 0;
|
|
|
|
|
|
|
|
p = strchr(n, ':');
|
|
|
|
if(!p)
|
|
|
|
/* this is fine if we already added at least one header */
|
|
|
|
return numh ? CURLE_OK : CURLE_BAD_FUNCTION_ARGUMENT;
|
|
|
|
nlen = p - n;
|
|
|
|
p++; /* move past the colon */
|
|
|
|
while(*p == ' ')
|
|
|
|
p++;
|
|
|
|
v = p;
|
|
|
|
p = strchr(v, '\r');
|
|
|
|
if(!p) {
|
|
|
|
p = strchr(v, '\n');
|
|
|
|
if(p)
|
|
|
|
linelen = 1; /* LF only */
|
|
|
|
else {
|
|
|
|
p = strchr(v, '\0');
|
|
|
|
newline = FALSE; /* no newline */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
linelen = 2; /* CRLF ending */
|
|
|
|
linelen += (p - n);
|
|
|
|
vlen = p - v;
|
|
|
|
|
|
|
|
if(HYPERE_OK != hyper_headers_add(headers, (uint8_t *)n, nlen,
|
|
|
|
(uint8_t *)v, vlen)) {
|
2021-07-05 17:53:00 +03:00
|
|
|
failf(data, "hyper refused to add header '%s'", line);
|
2020-12-14 16:10:33 +03:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
if(data->set.verbose) {
|
|
|
|
char *ptr = NULL;
|
|
|
|
if(!newline) {
|
|
|
|
ptr = aprintf("%.*s\r\n", (int)linelen, line);
|
|
|
|
if(!ptr)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
Curl_debug(data, CURLINFO_HEADER_OUT, ptr, linelen + 2);
|
|
|
|
free(ptr);
|
|
|
|
}
|
|
|
|
else
|
2021-08-13 17:46:22 +03:00
|
|
|
Curl_debug(data, CURLINFO_HEADER_OUT, (char *)n, linelen);
|
2020-12-14 16:10:33 +03:00
|
|
|
}
|
|
|
|
numh++;
|
|
|
|
n += linelen;
|
|
|
|
} while(newline);
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CURLcode request_target(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn,
|
|
|
|
const char *method,
|
|
|
|
hyper_request *req)
|
|
|
|
{
|
|
|
|
CURLcode result;
|
|
|
|
struct dynbuf r;
|
|
|
|
|
|
|
|
Curl_dyn_init(&r, DYN_HTTP_REQUEST);
|
|
|
|
|
|
|
|
result = Curl_http_target(data, conn, &r);
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
|
2023-10-24 17:51:05 +03:00
|
|
|
if(hyper_request_set_uri(req, (uint8_t *)Curl_dyn_uptr(&r),
|
2021-10-08 12:33:50 +03:00
|
|
|
Curl_dyn_len(&r))) {
|
|
|
|
failf(data, "error setting uri to hyper");
|
2020-12-14 16:10:33 +03:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
else
|
2023-10-24 17:51:05 +03:00
|
|
|
result = debug_request(data, method, Curl_dyn_ptr(&r));
|
2020-12-14 16:10:33 +03:00
|
|
|
|
|
|
|
Curl_dyn_free(&r);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int uploadpostfields(void *userdata, hyper_context *ctx,
|
|
|
|
hyper_buf **chunk)
|
|
|
|
{
|
|
|
|
struct Curl_easy *data = (struct Curl_easy *)userdata;
|
|
|
|
(void)ctx;
|
2021-08-23 14:04:59 +03:00
|
|
|
if(data->req.exp100 > EXP100_SEND_DATA) {
|
|
|
|
if(data->req.exp100 == EXP100_FAILED)
|
|
|
|
return HYPER_POLL_ERROR;
|
|
|
|
|
|
|
|
/* still waiting confirmation */
|
|
|
|
if(data->hyp.exp100_waker)
|
|
|
|
hyper_waker_free(data->hyp.exp100_waker);
|
|
|
|
data->hyp.exp100_waker = hyper_context_waker(ctx);
|
|
|
|
return HYPER_POLL_PENDING;
|
|
|
|
}
|
2020-12-14 16:10:33 +03:00
|
|
|
if(data->req.upload_done)
|
|
|
|
*chunk = NULL; /* nothing more to deliver */
|
|
|
|
else {
|
|
|
|
/* send everything off in a single go */
|
2021-05-28 13:31:55 +03:00
|
|
|
hyper_buf *copy = hyper_buf_copy(data->set.postfields,
|
|
|
|
(size_t)data->req.p.http->postsize);
|
|
|
|
if(copy)
|
|
|
|
*chunk = copy;
|
2021-06-16 11:52:21 +03:00
|
|
|
else {
|
|
|
|
data->state.hresult = CURLE_OUT_OF_MEMORY;
|
2021-05-28 13:31:55 +03:00
|
|
|
return HYPER_POLL_ERROR;
|
2021-06-16 11:52:21 +03:00
|
|
|
}
|
2021-06-08 11:11:28 +03:00
|
|
|
/* increasing the writebytecount here is a little premature but we
|
2022-10-30 19:38:16 +03:00
|
|
|
don't know exactly when the body is sent */
|
2021-06-08 11:11:28 +03:00
|
|
|
data->req.writebytecount += (size_t)data->req.p.http->postsize;
|
|
|
|
Curl_pgrsSetUploadCounter(data, data->req.writebytecount);
|
2020-12-14 16:10:33 +03:00
|
|
|
data->req.upload_done = TRUE;
|
|
|
|
}
|
|
|
|
return HYPER_POLL_READY;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int uploadstreamed(void *userdata, hyper_context *ctx,
|
|
|
|
hyper_buf **chunk)
|
|
|
|
{
|
|
|
|
size_t fillcount;
|
|
|
|
struct Curl_easy *data = (struct Curl_easy *)userdata;
|
2021-08-13 18:29:33 +03:00
|
|
|
CURLcode result;
|
2020-12-14 16:10:33 +03:00
|
|
|
(void)ctx;
|
2021-08-13 18:29:33 +03:00
|
|
|
|
|
|
|
if(data->req.exp100 > EXP100_SEND_DATA) {
|
|
|
|
if(data->req.exp100 == EXP100_FAILED)
|
|
|
|
return HYPER_POLL_ERROR;
|
|
|
|
|
|
|
|
/* still waiting confirmation */
|
|
|
|
if(data->hyp.exp100_waker)
|
|
|
|
hyper_waker_free(data->hyp.exp100_waker);
|
|
|
|
data->hyp.exp100_waker = hyper_context_waker(ctx);
|
|
|
|
return HYPER_POLL_PENDING;
|
|
|
|
}
|
|
|
|
|
2024-02-16 14:15:10 +03:00
|
|
|
if(data->req.upload_chunky && data->req.authneg) {
|
2022-12-11 13:13:14 +03:00
|
|
|
fillcount = 0;
|
|
|
|
data->req.upload_chunky = FALSE;
|
|
|
|
result = CURLE_OK;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = Curl_fillreadbuffer(data, data->set.upload_buffer_size,
|
|
|
|
&fillcount);
|
|
|
|
}
|
2021-06-16 11:52:21 +03:00
|
|
|
if(result) {
|
|
|
|
data->state.hresult = result;
|
2020-12-14 16:10:33 +03:00
|
|
|
return HYPER_POLL_ERROR;
|
2021-06-16 11:52:21 +03:00
|
|
|
}
|
2022-06-30 03:45:32 +03:00
|
|
|
if(!fillcount) {
|
|
|
|
if((data->req.keepon & KEEP_SEND_PAUSE) != KEEP_SEND_PAUSE)
|
|
|
|
/* done! */
|
|
|
|
*chunk = NULL;
|
|
|
|
else {
|
|
|
|
/* paused, save a waker */
|
|
|
|
if(data->hyp.send_body_waker)
|
|
|
|
hyper_waker_free(data->hyp.send_body_waker);
|
|
|
|
data->hyp.send_body_waker = hyper_context_waker(ctx);
|
|
|
|
return HYPER_POLL_PENDING;
|
|
|
|
}
|
|
|
|
}
|
2021-05-28 13:31:55 +03:00
|
|
|
else {
|
|
|
|
hyper_buf *copy = hyper_buf_copy((uint8_t *)data->state.ulbuf, fillcount);
|
|
|
|
if(copy)
|
|
|
|
*chunk = copy;
|
2021-06-16 11:52:21 +03:00
|
|
|
else {
|
|
|
|
data->state.hresult = CURLE_OUT_OF_MEMORY;
|
2021-05-28 13:31:55 +03:00
|
|
|
return HYPER_POLL_ERROR;
|
2021-06-16 11:52:21 +03:00
|
|
|
}
|
2021-06-08 11:11:28 +03:00
|
|
|
/* increasing the writebytecount here is a little premature but we
|
2022-10-30 19:38:16 +03:00
|
|
|
don't know exactly when the body is sent */
|
2021-06-08 11:11:28 +03:00
|
|
|
data->req.writebytecount += fillcount;
|
2023-09-01 07:55:47 +03:00
|
|
|
Curl_pgrsSetUploadCounter(data, data->req.writebytecount);
|
2021-05-28 13:31:55 +03:00
|
|
|
}
|
2020-12-14 16:10:33 +03:00
|
|
|
return HYPER_POLL_READY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2022-10-26 09:59:35 +03:00
|
|
|
* bodysend() sets up headers in the outgoing request for an HTTP transfer that
|
2020-12-14 16:10:33 +03:00
|
|
|
* sends a body
|
|
|
|
*/
|
|
|
|
|
|
|
|
static CURLcode bodysend(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn,
|
|
|
|
hyper_headers *headers,
|
|
|
|
hyper_request *hyperreq,
|
|
|
|
Curl_HttpReq httpreq)
|
|
|
|
{
|
2021-08-13 18:29:33 +03:00
|
|
|
struct HTTP *http = data->req.p.http;
|
2020-12-20 20:33:54 +03:00
|
|
|
CURLcode result = CURLE_OK;
|
2020-12-14 16:10:33 +03:00
|
|
|
struct dynbuf req;
|
|
|
|
if((httpreq == HTTPREQ_GET) || (httpreq == HTTPREQ_HEAD))
|
|
|
|
Curl_pgrsSetUploadSize(data, 0); /* no request body */
|
|
|
|
else {
|
|
|
|
hyper_body *body;
|
|
|
|
Curl_dyn_init(&req, DYN_HTTP_REQUEST);
|
|
|
|
result = Curl_http_bodysend(data, conn, &req, httpreq);
|
|
|
|
|
|
|
|
if(!result)
|
|
|
|
result = Curl_hyper_header(data, headers, Curl_dyn_ptr(&req));
|
|
|
|
|
|
|
|
Curl_dyn_free(&req);
|
|
|
|
|
|
|
|
body = hyper_body_new();
|
|
|
|
hyper_body_set_userdata(body, data);
|
|
|
|
if(data->set.postfields)
|
|
|
|
hyper_body_set_data_func(body, uploadpostfields);
|
|
|
|
else {
|
|
|
|
result = Curl_get_upload_buffer(data);
|
2023-08-28 07:35:08 +03:00
|
|
|
if(result) {
|
|
|
|
hyper_body_free(body);
|
2020-12-14 16:10:33 +03:00
|
|
|
return result;
|
2023-08-28 07:35:08 +03:00
|
|
|
}
|
2020-12-14 16:10:33 +03:00
|
|
|
/* init the "upload from here" pointer */
|
|
|
|
data->req.upload_fromhere = data->state.ulbuf;
|
|
|
|
hyper_body_set_data_func(body, uploadstreamed);
|
|
|
|
}
|
|
|
|
if(HYPERE_OK != hyper_request_set_body(hyperreq, body)) {
|
|
|
|
/* fail */
|
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
2021-08-13 18:29:33 +03:00
|
|
|
http->sending = HTTPSEND_BODY;
|
2020-12-14 16:10:33 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CURLcode cookies(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn,
|
|
|
|
hyper_headers *headers)
|
|
|
|
{
|
|
|
|
struct dynbuf req;
|
|
|
|
CURLcode result;
|
|
|
|
Curl_dyn_init(&req, DYN_HTTP_REQUEST);
|
|
|
|
|
|
|
|
result = Curl_http_cookies(data, conn, &req);
|
|
|
|
if(!result)
|
|
|
|
result = Curl_hyper_header(data, headers, Curl_dyn_ptr(&req));
|
|
|
|
Curl_dyn_free(&req);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-08-14 19:04:22 +03:00
|
|
|
/* called on 1xx responses */
|
|
|
|
static void http1xx_cb(void *arg, struct hyper_response *resp)
|
|
|
|
{
|
|
|
|
struct Curl_easy *data = (struct Curl_easy *)arg;
|
|
|
|
hyper_headers *headers = NULL;
|
|
|
|
CURLcode result = CURLE_OK;
|
|
|
|
uint16_t http_status;
|
|
|
|
int http_version;
|
|
|
|
const uint8_t *reasonp;
|
|
|
|
size_t reason_len;
|
|
|
|
|
|
|
|
infof(data, "Got HTTP 1xx informational");
|
|
|
|
|
|
|
|
http_status = hyper_response_status(resp);
|
|
|
|
http_version = hyper_response_version(resp);
|
|
|
|
reasonp = hyper_response_reason_phrase(resp);
|
|
|
|
reason_len = hyper_response_reason_phrase_len(resp);
|
|
|
|
|
|
|
|
result = status_line(data, data->conn,
|
|
|
|
http_status, http_version, reasonp, reason_len);
|
|
|
|
if(!result) {
|
|
|
|
headers = hyper_response_headers(resp);
|
|
|
|
if(!headers) {
|
|
|
|
failf(data, "hyperstream: couldn't get 1xx response headers");
|
|
|
|
result = CURLE_RECV_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data->state.hresult = result;
|
|
|
|
|
|
|
|
if(!result) {
|
|
|
|
/* the headers are already received */
|
|
|
|
hyper_headers_foreach(headers, hyper_each_header, data);
|
|
|
|
/* this callback also sets data->state.hresult on error */
|
|
|
|
|
|
|
|
if(empty_header(data))
|
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(data->state.hresult)
|
2022-04-16 12:55:05 +03:00
|
|
|
infof(data, "ERROR in 1xx, bail out");
|
2021-08-14 19:04:22 +03:00
|
|
|
}
|
|
|
|
|
2020-12-14 16:10:33 +03:00
|
|
|
/*
|
2022-10-26 09:59:35 +03:00
|
|
|
* Curl_http() gets called from the generic multi_do() function when an HTTP
|
2020-12-14 16:10:33 +03:00
|
|
|
* request is to be performed. This creates and sends a properly constructed
|
|
|
|
* HTTP request.
|
|
|
|
*/
|
2021-01-08 19:58:15 +03:00
|
|
|
CURLcode Curl_http(struct Curl_easy *data, bool *done)
|
2020-12-14 16:10:33 +03:00
|
|
|
{
|
2021-01-08 19:58:15 +03:00
|
|
|
struct connectdata *conn = data->conn;
|
2020-12-14 16:10:33 +03:00
|
|
|
struct hyptransfer *h = &data->hyp;
|
|
|
|
hyper_io *io = NULL;
|
|
|
|
hyper_clientconn_options *options = NULL;
|
|
|
|
hyper_task *task = NULL; /* for the handshake */
|
|
|
|
hyper_task *sendtask = NULL; /* for the send */
|
|
|
|
hyper_clientconn *client = NULL;
|
|
|
|
hyper_request *req = NULL;
|
|
|
|
hyper_headers *headers = NULL;
|
|
|
|
hyper_task *handshake = NULL;
|
|
|
|
CURLcode result;
|
|
|
|
const char *p_accept; /* Accept: string */
|
|
|
|
const char *method;
|
|
|
|
Curl_HttpReq httpreq;
|
|
|
|
const char *te = NULL; /* transfer-encoding */
|
2021-08-14 19:04:22 +03:00
|
|
|
hyper_code rc;
|
2020-12-14 16:10:33 +03:00
|
|
|
|
|
|
|
/* Always consider the DO phase done after this function call, even if there
|
|
|
|
may be parts of the request that is not yet sent, since we can deal with
|
|
|
|
the rest of the request in the PERFORM phase. */
|
|
|
|
*done = TRUE;
|
2024-02-14 14:09:32 +03:00
|
|
|
Curl_cw_reset(data);
|
2020-12-14 16:10:33 +03:00
|
|
|
|
2024-02-06 16:56:05 +03:00
|
|
|
/* Add collecting of headers written to client. For a new connection,
|
|
|
|
* we might have done that already, but reuse
|
|
|
|
* or multiplex needs it here as well. */
|
|
|
|
result = Curl_headers_init(data);
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
|
2021-07-06 18:05:17 +03:00
|
|
|
infof(data, "Time for the Hyper dance");
|
2020-12-14 16:10:33 +03:00
|
|
|
memset(h, 0, sizeof(struct hyptransfer));
|
|
|
|
|
|
|
|
result = Curl_http_host(data, conn);
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
Curl_http_method(data, conn, &method, &httpreq);
|
|
|
|
|
2023-11-21 13:24:18 +03:00
|
|
|
DEBUGASSERT(data->req.bytecount == 0);
|
|
|
|
|
2020-12-14 16:10:33 +03:00
|
|
|
/* setup the authentication headers */
|
|
|
|
{
|
|
|
|
char *pq = NULL;
|
|
|
|
if(data->state.up.query) {
|
|
|
|
pq = aprintf("%s?%s", data->state.up.path, data->state.up.query);
|
|
|
|
if(!pq)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
2021-01-08 19:58:15 +03:00
|
|
|
result = Curl_http_output_auth(data, conn, method, httpreq,
|
2020-12-14 16:10:33 +03:00
|
|
|
(pq ? pq : data->state.up.path), FALSE);
|
|
|
|
free(pq);
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = Curl_http_resume(data, conn, httpreq);
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
|
2021-01-08 19:58:15 +03:00
|
|
|
result = Curl_http_range(data, httpreq);
|
2020-12-14 16:10:33 +03:00
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
|
2021-01-08 19:58:15 +03:00
|
|
|
result = Curl_http_useragent(data);
|
2020-12-14 16:10:33 +03:00
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
io = hyper_io_new();
|
|
|
|
if(!io) {
|
|
|
|
failf(data, "Couldn't create hyper IO");
|
2021-10-13 10:15:48 +03:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
2020-12-14 16:10:33 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
/* tell Hyper how to read/write network data */
|
2024-02-14 14:09:32 +03:00
|
|
|
h->io_ctx.data = data;
|
|
|
|
h->io_ctx.sockindex = FIRSTSOCKET;
|
|
|
|
hyper_io_set_userdata(io, &h->io_ctx);
|
2021-01-04 11:36:41 +03:00
|
|
|
hyper_io_set_read(io, Curl_hyper_recv);
|
|
|
|
hyper_io_set_write(io, Curl_hyper_send);
|
2020-12-14 16:10:33 +03:00
|
|
|
|
|
|
|
/* create an executor to poll futures */
|
|
|
|
if(!h->exec) {
|
|
|
|
h->exec = hyper_executor_new();
|
|
|
|
if(!h->exec) {
|
|
|
|
failf(data, "Couldn't create hyper executor");
|
2021-10-13 10:15:48 +03:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
2020-12-14 16:10:33 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
options = hyper_clientconn_options_new();
|
|
|
|
if(!options) {
|
|
|
|
failf(data, "Couldn't create hyper client options");
|
2021-10-13 10:15:48 +03:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
2020-12-14 16:10:33 +03:00
|
|
|
goto error;
|
|
|
|
}
|
2022-09-01 10:23:22 +03:00
|
|
|
if(conn->alpn == CURL_HTTP_VERSION_2) {
|
2023-10-24 17:51:05 +03:00
|
|
|
failf(data, "ALPN protocol h2 not supported with Hyper");
|
|
|
|
result = CURLE_UNSUPPORTED_PROTOCOL;
|
|
|
|
goto error;
|
2020-12-14 16:10:33 +03:00
|
|
|
}
|
2022-04-14 07:36:21 +03:00
|
|
|
hyper_clientconn_options_set_preserve_header_case(options, 1);
|
|
|
|
hyper_clientconn_options_set_preserve_header_order(options, 1);
|
2022-07-27 18:23:41 +03:00
|
|
|
hyper_clientconn_options_http1_allow_multiline_headers(options, 1);
|
2020-12-14 16:10:33 +03:00
|
|
|
|
|
|
|
hyper_clientconn_options_exec(options, h->exec);
|
|
|
|
|
|
|
|
/* "Both the `io` and the `options` are consumed in this function call" */
|
|
|
|
handshake = hyper_clientconn_handshake(io, options);
|
|
|
|
if(!handshake) {
|
|
|
|
failf(data, "Couldn't create hyper client handshake");
|
2021-10-13 10:15:48 +03:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
2020-12-14 16:10:33 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
io = NULL;
|
|
|
|
options = NULL;
|
|
|
|
|
|
|
|
if(HYPERE_OK != hyper_executor_push(h->exec, handshake)) {
|
|
|
|
failf(data, "Couldn't hyper_executor_push the handshake");
|
2021-10-13 10:15:48 +03:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
2020-12-14 16:10:33 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
handshake = NULL; /* ownership passed on */
|
|
|
|
|
|
|
|
task = hyper_executor_poll(h->exec);
|
|
|
|
if(!task) {
|
|
|
|
failf(data, "Couldn't hyper_executor_poll the handshake");
|
2021-10-13 10:15:48 +03:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
2020-12-14 16:10:33 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
client = hyper_task_value(task);
|
|
|
|
hyper_task_free(task);
|
|
|
|
|
|
|
|
req = hyper_request_new();
|
|
|
|
if(!req) {
|
|
|
|
failf(data, "Couldn't hyper_request_new");
|
2021-10-13 10:15:48 +03:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
2020-12-14 16:10:33 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2021-08-23 15:20:08 +03:00
|
|
|
if(!Curl_use_http_1_1plus(data, conn)) {
|
2020-12-14 16:10:33 +03:00
|
|
|
if(HYPERE_OK != hyper_request_set_version(req,
|
|
|
|
HYPER_HTTP_VERSION_1_0)) {
|
2021-01-27 17:07:35 +03:00
|
|
|
failf(data, "error setting HTTP version");
|
2021-10-13 10:15:48 +03:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
2020-12-14 16:10:33 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
2022-05-07 03:34:14 +03:00
|
|
|
else {
|
2023-10-24 17:51:05 +03:00
|
|
|
if(!data->state.disableexpect) {
|
2022-05-07 03:34:14 +03:00
|
|
|
data->state.expect100header = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2020-12-14 16:10:33 +03:00
|
|
|
|
|
|
|
if(hyper_request_set_method(req, (uint8_t *)method, strlen(method))) {
|
|
|
|
failf(data, "error setting method");
|
2021-10-13 10:15:48 +03:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
2020-12-14 16:10:33 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2023-10-24 17:51:05 +03:00
|
|
|
result = request_target(data, conn, method, req);
|
2020-12-14 16:10:33 +03:00
|
|
|
if(result)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
headers = hyper_request_headers(req);
|
|
|
|
if(!headers) {
|
2020-12-24 01:41:13 +03:00
|
|
|
failf(data, "hyper_request_headers");
|
2021-10-13 10:15:48 +03:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
2020-12-14 16:10:33 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2021-08-14 19:04:22 +03:00
|
|
|
rc = hyper_request_on_informational(req, http1xx_cb, data);
|
2021-10-13 10:15:48 +03:00
|
|
|
if(rc) {
|
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
|
|
|
goto error;
|
|
|
|
}
|
2021-08-14 19:04:22 +03:00
|
|
|
|
2020-12-14 16:10:33 +03:00
|
|
|
result = Curl_http_body(data, conn, httpreq, &te);
|
|
|
|
if(result)
|
2021-10-13 10:15:48 +03:00
|
|
|
goto error;
|
2020-12-14 16:10:33 +03:00
|
|
|
|
2023-10-24 17:51:05 +03:00
|
|
|
if(data->state.aptr.host) {
|
|
|
|
result = Curl_hyper_header(data, headers, data->state.aptr.host);
|
|
|
|
if(result)
|
|
|
|
goto error;
|
2021-10-08 12:33:50 +03:00
|
|
|
}
|
2020-12-14 16:10:33 +03:00
|
|
|
|
2021-10-13 10:15:48 +03:00
|
|
|
if(data->state.aptr.proxyuserpwd) {
|
|
|
|
result = Curl_hyper_header(data, headers, data->state.aptr.proxyuserpwd);
|
|
|
|
if(result)
|
|
|
|
goto error;
|
|
|
|
}
|
2020-12-14 16:10:33 +03:00
|
|
|
|
2021-10-13 10:15:48 +03:00
|
|
|
if(data->state.aptr.userpwd) {
|
|
|
|
result = Curl_hyper_header(data, headers, data->state.aptr.userpwd);
|
|
|
|
if(result)
|
|
|
|
goto error;
|
|
|
|
}
|
2020-12-14 16:10:33 +03:00
|
|
|
|
2021-10-13 10:15:48 +03:00
|
|
|
if((data->state.use_range && data->state.aptr.rangeline)) {
|
|
|
|
result = Curl_hyper_header(data, headers, data->state.aptr.rangeline);
|
|
|
|
if(result)
|
|
|
|
goto error;
|
|
|
|
}
|
2020-12-14 16:10:33 +03:00
|
|
|
|
|
|
|
if(data->set.str[STRING_USERAGENT] &&
|
|
|
|
*data->set.str[STRING_USERAGENT] &&
|
2021-10-13 10:15:48 +03:00
|
|
|
data->state.aptr.uagent) {
|
|
|
|
result = Curl_hyper_header(data, headers, data->state.aptr.uagent);
|
|
|
|
if(result)
|
|
|
|
goto error;
|
|
|
|
}
|
2020-12-14 16:10:33 +03:00
|
|
|
|
2022-02-09 02:57:00 +03:00
|
|
|
p_accept = Curl_checkheaders(data,
|
|
|
|
STRCONST("Accept"))?NULL:"Accept: */*\r\n";
|
2021-10-13 10:15:48 +03:00
|
|
|
if(p_accept) {
|
|
|
|
result = Curl_hyper_header(data, headers, p_accept);
|
|
|
|
if(result)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if(te) {
|
|
|
|
result = Curl_hyper_header(data, headers, te);
|
|
|
|
if(result)
|
|
|
|
goto error;
|
|
|
|
}
|
2020-12-14 16:10:33 +03:00
|
|
|
|
2022-05-23 17:47:17 +03:00
|
|
|
#ifndef CURL_DISABLE_ALTSVC
|
|
|
|
if(conn->bits.altused && !Curl_checkheaders(data, STRCONST("Alt-Used"))) {
|
|
|
|
char *altused = aprintf("Alt-Used: %s:%d\r\n",
|
|
|
|
conn->conn_to_host.name, conn->conn_to_port);
|
|
|
|
if(!altused) {
|
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
result = Curl_hyper_header(data, headers, altused);
|
|
|
|
if(result)
|
|
|
|
goto error;
|
|
|
|
free(altused);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-12-14 16:10:33 +03:00
|
|
|
#ifndef CURL_DISABLE_PROXY
|
|
|
|
if(conn->bits.httpproxy && !conn->bits.tunnel_proxy &&
|
2022-02-09 02:57:00 +03:00
|
|
|
!Curl_checkheaders(data, STRCONST("Proxy-Connection")) &&
|
|
|
|
!Curl_checkProxyheaders(data, conn, STRCONST("Proxy-Connection"))) {
|
2021-10-13 10:15:48 +03:00
|
|
|
result = Curl_hyper_header(data, headers, "Proxy-Connection: Keep-Alive");
|
|
|
|
if(result)
|
2020-12-14 16:10:33 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Curl_safefree(data->state.aptr.ref);
|
2022-02-09 02:57:00 +03:00
|
|
|
if(data->state.referer && !Curl_checkheaders(data, STRCONST("Referer"))) {
|
2021-03-26 16:25:45 +03:00
|
|
|
data->state.aptr.ref = aprintf("Referer: %s\r\n", data->state.referer);
|
2020-12-14 16:10:33 +03:00
|
|
|
if(!data->state.aptr.ref)
|
2021-10-13 10:15:48 +03:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
|
|
|
else
|
|
|
|
result = Curl_hyper_header(data, headers, data->state.aptr.ref);
|
|
|
|
if(result)
|
2020-12-14 16:10:33 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2023-01-02 13:02:07 +03:00
|
|
|
#ifdef HAVE_LIBZ
|
|
|
|
/* we only consider transfer-encoding magic if libz support is built-in */
|
|
|
|
result = Curl_transferencode(data);
|
|
|
|
if(result)
|
|
|
|
goto error;
|
|
|
|
result = Curl_hyper_header(data, headers, data->state.aptr.te);
|
|
|
|
if(result)
|
|
|
|
goto error;
|
|
|
|
#endif
|
|
|
|
|
2022-02-09 02:57:00 +03:00
|
|
|
if(!Curl_checkheaders(data, STRCONST("Accept-Encoding")) &&
|
2021-03-11 18:05:15 +03:00
|
|
|
data->set.str[STRING_ENCODING]) {
|
|
|
|
Curl_safefree(data->state.aptr.accept_encoding);
|
|
|
|
data->state.aptr.accept_encoding =
|
|
|
|
aprintf("Accept-Encoding: %s\r\n", data->set.str[STRING_ENCODING]);
|
|
|
|
if(!data->state.aptr.accept_encoding)
|
2021-10-13 10:15:48 +03:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
|
|
|
else
|
|
|
|
result = Curl_hyper_header(data, headers,
|
|
|
|
data->state.aptr.accept_encoding);
|
|
|
|
if(result)
|
2021-03-11 18:05:15 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Curl_safefree(data->state.aptr.accept_encoding);
|
|
|
|
|
2020-12-14 16:10:33 +03:00
|
|
|
result = cookies(data, conn, headers);
|
|
|
|
if(result)
|
2021-10-13 10:15:48 +03:00
|
|
|
goto error;
|
2020-12-14 16:10:33 +03:00
|
|
|
|
2022-09-09 16:11:14 +03:00
|
|
|
if(!result && conn->handler->protocol&(CURLPROTO_WS|CURLPROTO_WSS))
|
|
|
|
result = Curl_ws_request(data, headers);
|
|
|
|
|
2021-01-08 19:58:15 +03:00
|
|
|
result = Curl_add_timecondition(data, headers);
|
2021-01-01 02:48:40 +03:00
|
|
|
if(result)
|
2021-10-13 10:15:48 +03:00
|
|
|
goto error;
|
2021-01-01 02:48:40 +03:00
|
|
|
|
2021-01-08 19:58:15 +03:00
|
|
|
result = Curl_add_custom_headers(data, FALSE, headers);
|
2020-12-14 16:10:33 +03:00
|
|
|
if(result)
|
2021-10-13 10:15:48 +03:00
|
|
|
goto error;
|
2020-12-14 16:10:33 +03:00
|
|
|
|
2020-12-20 20:33:54 +03:00
|
|
|
result = bodysend(data, conn, headers, req, httpreq);
|
|
|
|
if(result)
|
2021-10-13 10:15:48 +03:00
|
|
|
goto error;
|
2020-12-14 16:10:33 +03:00
|
|
|
|
2022-07-20 12:15:25 +03:00
|
|
|
Curl_debug(data, CURLINFO_HEADER_OUT, (char *)"\r\n", 2);
|
2020-12-14 16:10:33 +03:00
|
|
|
|
2024-02-16 14:15:10 +03:00
|
|
|
if(data->req.upload_chunky && data->req.authneg) {
|
2022-12-11 13:13:14 +03:00
|
|
|
data->req.upload_chunky = TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
data->req.upload_chunky = FALSE;
|
|
|
|
}
|
2020-12-14 16:10:33 +03:00
|
|
|
sendtask = hyper_clientconn_send(client, req);
|
|
|
|
if(!sendtask) {
|
2020-12-24 01:41:13 +03:00
|
|
|
failf(data, "hyper_clientconn_send");
|
2021-10-13 10:15:48 +03:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
2020-12-14 16:10:33 +03:00
|
|
|
goto error;
|
|
|
|
}
|
2023-08-25 08:01:53 +03:00
|
|
|
req = NULL;
|
2020-12-14 16:10:33 +03:00
|
|
|
|
|
|
|
if(HYPERE_OK != hyper_executor_push(h->exec, sendtask)) {
|
|
|
|
failf(data, "Couldn't hyper_executor_push the send");
|
2021-10-13 10:15:48 +03:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
2020-12-14 16:10:33 +03:00
|
|
|
goto error;
|
|
|
|
}
|
2023-08-28 07:35:08 +03:00
|
|
|
sendtask = NULL; /* ownership passed on */
|
2020-12-14 16:10:33 +03:00
|
|
|
|
|
|
|
hyper_clientconn_free(client);
|
2023-08-25 11:40:31 +03:00
|
|
|
client = NULL;
|
2020-12-14 16:10:33 +03:00
|
|
|
|
|
|
|
if((httpreq == HTTPREQ_GET) || (httpreq == HTTPREQ_HEAD)) {
|
|
|
|
/* HTTP GET/HEAD download */
|
|
|
|
Curl_pgrsSetUploadSize(data, 0); /* nothing */
|
2024-02-14 14:09:32 +03:00
|
|
|
Curl_xfer_setup(data, FIRSTSOCKET, -1, TRUE, -1);
|
2020-12-14 16:10:33 +03:00
|
|
|
}
|
2021-01-04 11:36:41 +03:00
|
|
|
conn->datastream = Curl_hyper_stream;
|
2021-08-13 18:29:33 +03:00
|
|
|
if(data->state.expect100header)
|
|
|
|
/* Timeout count starts now since with Hyper we don't know exactly when
|
|
|
|
the full request has been sent. */
|
|
|
|
data->req.start100 = Curl_now();
|
2020-12-14 16:10:33 +03:00
|
|
|
|
2023-08-23 15:47:45 +03:00
|
|
|
/* clear userpwd and proxyuserpwd to avoid reusing old credentials
|
|
|
|
* from reused connections */
|
2021-05-27 11:19:50 +03:00
|
|
|
Curl_safefree(data->state.aptr.userpwd);
|
|
|
|
Curl_safefree(data->state.aptr.proxyuserpwd);
|
2020-12-14 16:10:33 +03:00
|
|
|
return CURLE_OK;
|
2023-05-18 07:54:18 +03:00
|
|
|
error:
|
2021-10-13 10:15:48 +03:00
|
|
|
DEBUGASSERT(result);
|
2020-12-14 16:10:33 +03:00
|
|
|
if(io)
|
|
|
|
hyper_io_free(io);
|
|
|
|
|
|
|
|
if(options)
|
|
|
|
hyper_clientconn_options_free(options);
|
|
|
|
|
|
|
|
if(handshake)
|
|
|
|
hyper_task_free(handshake);
|
|
|
|
|
2023-08-25 11:40:31 +03:00
|
|
|
if(client)
|
|
|
|
hyper_clientconn_free(client);
|
|
|
|
|
2023-08-25 08:01:53 +03:00
|
|
|
if(req)
|
|
|
|
hyper_request_free(req);
|
|
|
|
|
2021-10-13 10:15:48 +03:00
|
|
|
return result;
|
2020-12-14 16:10:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Curl_hyper_done(struct Curl_easy *data)
|
|
|
|
{
|
|
|
|
struct hyptransfer *h = &data->hyp;
|
|
|
|
if(h->exec) {
|
|
|
|
hyper_executor_free(h->exec);
|
|
|
|
h->exec = NULL;
|
|
|
|
}
|
|
|
|
if(h->read_waker) {
|
|
|
|
hyper_waker_free(h->read_waker);
|
|
|
|
h->read_waker = NULL;
|
|
|
|
}
|
|
|
|
if(h->write_waker) {
|
|
|
|
hyper_waker_free(h->write_waker);
|
|
|
|
h->write_waker = NULL;
|
|
|
|
}
|
2021-08-13 18:29:33 +03:00
|
|
|
if(h->exp100_waker) {
|
|
|
|
hyper_waker_free(h->exp100_waker);
|
|
|
|
h->exp100_waker = NULL;
|
|
|
|
}
|
2020-12-14 16:10:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !defined(CURL_DISABLE_HTTP) && defined(USE_HYPER) */
|