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:
@@ -148,6 +148,16 @@ static int print_each_header(void *userdata,
|
||||
return HYPER_ITER_CONTINUE;
|
||||
}
|
||||
|
||||
static void print_informational(void *userdata, hyper_response *resp) {
|
||||
uint16_t http_status = hyper_response_status(resp);
|
||||
|
||||
printf("\nInformational (1xx): %d\n", http_status);
|
||||
|
||||
hyper_headers *headers = hyper_response_headers(resp);
|
||||
hyper_headers_foreach(headers, print_each_header, NULL);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
EXAMPLE_NOT_SET = 0, // tasks we don't know about won't have a userdata set
|
||||
EXAMPLE_HANDSHAKE,
|
||||
@@ -172,7 +182,7 @@ int main(int argc, char *argv[]) {
|
||||
upload.fd = open(file, O_RDONLY);
|
||||
|
||||
if (upload.fd < 0) {
|
||||
printf("error opening file to upload: %d", errno);
|
||||
printf("error opening file to upload: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
printf("connecting to port %s on %s...\n", port, host);
|
||||
@@ -262,7 +272,10 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
hyper_headers *req_headers = hyper_request_headers(req);
|
||||
hyper_headers_set(req_headers, STR_ARG("host"), STR_ARG(host));
|
||||
hyper_headers_set(req_headers, STR_ARG("host"), STR_ARG(host));
|
||||
hyper_headers_set(req_headers, STR_ARG("expect"), STR_ARG("100-continue"));
|
||||
|
||||
hyper_request_on_informational(req, print_informational, NULL);
|
||||
|
||||
// Prepare the req body
|
||||
hyper_body *body = hyper_body_new();
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user