http2: Include 'authority' field by default in the request

Closes https://github.com/espressif/esp-idf/issues/1717
This commit is contained in:
Kedar Sovani 2018-03-20 13:32:45 +05:30
parent 7e268adaf5
commit 86eaf5d56b
2 changed files with 11 additions and 3 deletions

View 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);

View File

@ -40,6 +40,7 @@ struct sh2lib_handle {
SSL *ssl; /*!< Pointer to the SSL handle */
nghttp2_session *http2_sess; /*!< Pointer to the HTTP2 session handle */
int sockfd; /*!< Socket file descriptor */
char *hostname; /*!< The hostname we are connected to */
};
/** Flag indicating receive stream is reset */