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

@@ -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();