diff --git a/examples/protocols/http2_request/components/sh2lib/sh2lib.c b/examples/protocols/http2_request/components/sh2lib/sh2lib.c index 450fd63a7..ba46593f6 100644 --- a/examples/protocols/http2_request/components/sh2lib/sh2lib.c +++ b/examples/protocols/http2_request/components/sh2lib/sh2lib.c @@ -58,6 +58,7 @@ static int do_ssl_connect(struct sh2lib_handle *hd, int sockfd, const char *host hd->ssl_ctx = ssl_ctx; hd->ssl = ssl; hd->sockfd = sockfd; + hd->hostname = strdup(hostname); int flags = fcntl(hd->sockfd, F_GETFL, 0); fcntl(hd->sockfd, F_SETFL, flags | O_NONBLOCK); @@ -331,6 +332,10 @@ void sh2lib_free(struct sh2lib_handle *hd) close(hd->sockfd); hd->ssl_ctx = 0; } + if (hd->hostname) { + free(hd->hostname); + hd->hostname = NULL; + } } int sh2lib_execute(struct sh2lib_handle *hd) @@ -361,10 +366,10 @@ int sh2lib_do_get_with_nv(struct sh2lib_handle *hd, const nghttp2_nv *nva, size_ int sh2lib_do_get(struct sh2lib_handle *hd, const char *path, sh2lib_frame_data_recv_cb_t recv_cb) { -#define HTTP2_PATH_NV ":path" const nghttp2_nv nva[] = { SH2LIB_MAKE_NV(":method", "GET"), SH2LIB_MAKE_NV(":scheme", "https"), - {(uint8_t *)HTTP2_PATH_NV, (uint8_t *)path, strlen(HTTP2_PATH_NV), strlen(path), NGHTTP2_NV_FLAG_NONE}, + SH2LIB_MAKE_NV(":authority", hd->hostname), + SH2LIB_MAKE_NV(":path", path), }; return sh2lib_do_get_with_nv(hd, nva, sizeof(nva) / sizeof(nva[0]), recv_cb); } @@ -400,6 +405,7 @@ int sh2lib_do_post(struct sh2lib_handle *hd, const char *path, { const nghttp2_nv nva[] = { SH2LIB_MAKE_NV(":method", "POST"), SH2LIB_MAKE_NV(":scheme", "https"), + SH2LIB_MAKE_NV(":authority", hd->hostname), SH2LIB_MAKE_NV(":path", path), }; return sh2lib_do_putpost_with_nv(hd, nva, sizeof(nva) / sizeof(nva[0]), send_cb, recv_cb); @@ -411,6 +417,7 @@ int sh2lib_do_put(struct sh2lib_handle *hd, const char *path, { const nghttp2_nv nva[] = { SH2LIB_MAKE_NV(":method", "PUT"), SH2LIB_MAKE_NV(":scheme", "https"), + SH2LIB_MAKE_NV(":authority", hd->hostname), SH2LIB_MAKE_NV(":path", path), }; return sh2lib_do_putpost_with_nv(hd, nva, sizeof(nva) / sizeof(nva[0]), send_cb, recv_cb); diff --git a/examples/protocols/http2_request/components/sh2lib/sh2lib.h b/examples/protocols/http2_request/components/sh2lib/sh2lib.h index a454d8084..97095eb5a 100644 --- a/examples/protocols/http2_request/components/sh2lib/sh2lib.h +++ b/examples/protocols/http2_request/components/sh2lib/sh2lib.h @@ -39,7 +39,8 @@ struct sh2lib_handle { SSL_CTX *ssl_ctx; /*!< Pointer to the SSL context */ SSL *ssl; /*!< Pointer to the SSL handle */ nghttp2_session *http2_sess; /*!< Pointer to the HTTP2 session handle */ - int sockfd; /*!< Socket file descriptor */ + int sockfd; /*!< Socket file descriptor */ + char *hostname; /*!< The hostname we are connected to */ }; /** Flag indicating receive stream is reset */