feat(ffi): add hyper_request_on_informational

This defines an extension type used in requests for the client that is
used to setup a callback for receipt of informational (1xx) responses.
The type isn't currently public, and is only usable in the C API.
This commit is contained in:
Sean McArthur
2021-07-08 11:32:39 -07:00
parent 1cd40b7e26
commit 25d18c0b74
10 changed files with 162 additions and 8 deletions

View File

@@ -207,6 +207,8 @@ typedef int (*hyper_body_foreach_callback)(void*, const struct hyper_buf*);
typedef int (*hyper_body_data_callback)(void*, struct hyper_context*, struct hyper_buf**);
typedef void (*hyper_request_on_informational_callback)(void*, const struct hyper_response*);
typedef int (*hyper_headers_foreach_callback)(void*, const uint8_t*, size_t, const uint8_t*, size_t);
typedef size_t (*hyper_io_read_callback)(void*, struct hyper_context*, uint8_t*, size_t);
@@ -454,6 +456,27 @@ struct hyper_headers *hyper_request_headers(struct hyper_request *req);
*/
enum hyper_code hyper_request_set_body(struct hyper_request *req, struct hyper_body *body);
/*
Set an informational (1xx) response callback.
The callback is called each time hyper receives an informational (1xx)
response for this request.
The third argument is an opaque user data pointer, which is passed to
the callback each time.
The callback is passed the `void *` data pointer, and a
`hyper_response *` which can be inspected as any other response. The
body of the response will always be empty.
NOTE: The `const hyper_response *` is just borrowed data, and will not
be valid after the callback finishes. You must copy any data you wish
to persist.
*/
enum hyper_code hyper_request_on_informational(struct hyper_request *req,
hyper_request_on_informational_callback callback,
void *data);
/*
Free an HTTP response after using it.
*/