summaryrefslogtreecommitdiff
path: root/lib/http.h
diff options
context:
space:
mode:
authorStefan Eissing <stefan@eissing.org>2023-03-20 14:23:53 +0100
committerDaniel Stenberg <daniel@haxx.se>2023-03-30 09:08:05 +0200
commit61f52a97e9fd1bb79f1b312fe031ceb95fd13d27 (patch)
treea66c5448188d73f07fe4a8f3e9a971208e794fa5 /lib/http.h
parent8cabef6fc312b7a59e2cbf73fabd9f3cc2b459ba (diff)
downloadcurl-61f52a97e9fd1bb79f1b312fe031ceb95fd13d27.tar.gz
lib: add `bufq` and `dynhds`
Adding `bufq`: - at init() time configured to hold up to `n` chunks of `m` bytes each. - various methods for reading from and writing to it. - `peek` support to get access to buffered data without copy - `pass` support to allow buffer flushing on write if it becomes full - use case: IO buffers for dynamic reads and writes that do not blow up - distinct from `dynbuf` in that: - it maintains a read position - writes on a full bufq return CURLE_AGAIN instead of nuking itself - Init options: - SOFT_LIMIT: allow writes into a full bufq - NO_SPARES: free empty chunks right away - a `bufc_pool` that can keep a number of spare chunks to be shared between different `bufq` instances Adding `dynhds`: - a straightforward list of name+value pairs as used for HTTP headers - headers can be appended dynamically - headers can be removed again - headers can be replaced - headers can be looked up - http/1.1 formatting into a `dynbuf` - configured at init() with limits on header counts and total string sizes - use case: pass a HTTP request or response around without being version specific - express a HTTP request without a curl easy handle (used in h2 proxy tunnels) - future extension possibilities: - conversions of `dynhds` to nghttp2/nghttp3 name+value arrays Closes #10720
Diffstat (limited to 'lib/http.h')
-rw-r--r--lib/http.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/http.h b/lib/http.h
index 444abc0be..5f4fcb904 100644
--- a/lib/http.h
+++ b/lib/http.h
@@ -29,6 +29,7 @@
#include <pthread.h>
#endif
+#include "dynhds.h"
#include "ws.h"
typedef enum {
@@ -60,6 +61,7 @@ extern const struct Curl_handler Curl_handler_wss;
#endif
#endif /* websockets */
+struct dynhds;
/* Header specific functions */
bool Curl_compareheader(const char *headerline, /* line to check */
@@ -97,6 +99,10 @@ CURLcode Curl_add_custom_headers(struct Curl_easy *data,
void *headers
#endif
);
+CURLcode Curl_dynhds_add_custom(struct Curl_easy *data,
+ bool is_connect,
+ struct dynhds *hds);
+
CURLcode Curl_http_compile_trailers(struct curl_slist *trailers,
struct dynbuf *buf,
struct Curl_easy *handle);
@@ -328,4 +334,48 @@ Curl_http_output_auth(struct Curl_easy *data,
bool proxytunnel); /* TRUE if this is the request setting
up the proxy tunnel */
+/* Decode HTTP status code string. */
+CURLcode Curl_http_decode_status(int *pstatus, const char *s, size_t len);
+
+/**
+ * All about a core HTTP request, excluding body and trailers
+ */
+struct http_req {
+ char method[12];
+ char *scheme;
+ char *authority;
+ char *path;
+ struct dynhds headers;
+};
+
+/**
+ * Create a HTTP request struct.
+ */
+CURLcode Curl_http_req_make(struct http_req **preq,
+ const char *method,
+ const char *scheme,
+ const char *authority,
+ const char *path);
+
+void Curl_http_req_free(struct http_req *req);
+
+/**
+ * All about a core HTTP response, excluding body and trailers
+ */
+struct http_resp {
+ int status;
+ char *description;
+ struct dynhds headers;
+ struct http_resp *prev;
+};
+
+/**
+ * Create a HTTP response struct.
+ */
+CURLcode Curl_http_resp_make(struct http_resp **presp,
+ int status,
+ const char *description);
+
+void Curl_http_resp_free(struct http_resp *resp);
+
#endif /* HEADER_CURL_HTTP_H */