]> granicus.if.org Git - esp-idf/commitdiff
http2: Include 'authority' field by default in the request
authorKedar Sovani <kedars@gmail.com>
Tue, 20 Mar 2018 08:02:45 +0000 (13:32 +0530)
committerKedar Sovani <kedars@gmail.com>
Tue, 20 Mar 2018 12:03:05 +0000 (17:33 +0530)
Closes https://github.com/espressif/esp-idf/issues/1717

examples/protocols/http2_request/components/sh2lib/sh2lib.c
examples/protocols/http2_request/components/sh2lib/sh2lib.h

index 450fd63a76d9b7c8d29b5dbf755c39b898f25d00..ba46593f62c62666fc25d232755d45e327fe9750 100644 (file)
@@ -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);
index a454d808443566ba838764c3f483c62cfb72cb1d..97095eb5af18b977c7300d86309d983e7fb162df 100644 (file)
@@ -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 */