Skip to content

Commit

Permalink
docs(capi): output the hyper_version in the capi examples (#2623)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Aug 18, 2021
1 parent 684f2fa commit c351539
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion capi/examples/client.c
Expand Up @@ -175,7 +175,7 @@ int main(int argc, char *argv[]) {
hyper_io_set_read(io, read_cb);
hyper_io_set_write(io, write_cb);

printf("http handshake ...\n");
printf("http handshake (hyper v%s) ...\n", hyper_version());

// We need an executor generally to poll futures
const hyper_executor *exec = hyper_executor_new();
Expand Down
14 changes: 9 additions & 5 deletions capi/examples/upload.c
Expand Up @@ -148,14 +148,13 @@ static int print_each_header(void *userdata,
return HYPER_ITER_CONTINUE;
}

static void print_informational(void *userdata, hyper_response *resp) {
static void print_informational(void *userdata, const 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");
const hyper_buf* headers = hyper_response_headers_raw(resp);
write(1, hyper_buf_bytes(headers), hyper_buf_len(headers));
}

typedef enum {
Expand Down Expand Up @@ -218,14 +217,15 @@ int main(int argc, char *argv[]) {
hyper_io_set_read(io, read_cb);
hyper_io_set_write(io, write_cb);

printf("http handshake ...\n");
printf("http handshake (hyper v%s) ...\n", hyper_version());

// We need an executor generally to poll futures
const hyper_executor *exec = hyper_executor_new();

// Prepare client options
hyper_clientconn_options *opts = hyper_clientconn_options_new();
hyper_clientconn_options_exec(opts, exec);
hyper_clientconn_options_headers_raw(opts, 1);

hyper_task *handshake = hyper_clientconn_handshake(io, opts);
hyper_task_set_userdata(handshake, (void *)EXAMPLE_HANDSHAKE);
Expand Down Expand Up @@ -275,6 +275,10 @@ int main(int argc, char *argv[]) {
hyper_headers_set(req_headers, STR_ARG("host"), STR_ARG(host));
hyper_headers_set(req_headers, STR_ARG("expect"), STR_ARG("100-continue"));

// NOTE: We aren't handling *waiting* for the 100 Continue,
// the body is sent immediately. This will just print if any
// informational headers are received.
printf(" with expect-continue ...\n");
hyper_request_on_informational(req, print_informational, NULL);

// Prepare the req body
Expand Down

0 comments on commit c351539

Please sign in to comment.