Skip to content

Commit 86eaf5d

Browse files
committed
http2: Include 'authority' field by default in the request
Closes #1717
1 parent 7e268ad commit 86eaf5d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ static int do_ssl_connect(struct sh2lib_handle *hd, int sockfd, const char *host
5858
hd->ssl_ctx = ssl_ctx;
5959
hd->ssl = ssl;
6060
hd->sockfd = sockfd;
61+
hd->hostname = strdup(hostname);
6162

6263
int flags = fcntl(hd->sockfd, F_GETFL, 0);
6364
fcntl(hd->sockfd, F_SETFL, flags | O_NONBLOCK);
@@ -331,6 +332,10 @@ void sh2lib_free(struct sh2lib_handle *hd)
331332
close(hd->sockfd);
332333
hd->ssl_ctx = 0;
333334
}
335+
if (hd->hostname) {
336+
free(hd->hostname);
337+
hd->hostname = NULL;
338+
}
334339
}
335340

336341
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_
361366

362367
int sh2lib_do_get(struct sh2lib_handle *hd, const char *path, sh2lib_frame_data_recv_cb_t recv_cb)
363368
{
364-
#define HTTP2_PATH_NV ":path"
365369
const nghttp2_nv nva[] = { SH2LIB_MAKE_NV(":method", "GET"),
366370
SH2LIB_MAKE_NV(":scheme", "https"),
367-
{(uint8_t *)HTTP2_PATH_NV, (uint8_t *)path, strlen(HTTP2_PATH_NV), strlen(path), NGHTTP2_NV_FLAG_NONE},
371+
SH2LIB_MAKE_NV(":authority", hd->hostname),
372+
SH2LIB_MAKE_NV(":path", path),
368373
};
369374
return sh2lib_do_get_with_nv(hd, nva, sizeof(nva) / sizeof(nva[0]), recv_cb);
370375
}
@@ -400,6 +405,7 @@ int sh2lib_do_post(struct sh2lib_handle *hd, const char *path,
400405
{
401406
const nghttp2_nv nva[] = { SH2LIB_MAKE_NV(":method", "POST"),
402407
SH2LIB_MAKE_NV(":scheme", "https"),
408+
SH2LIB_MAKE_NV(":authority", hd->hostname),
403409
SH2LIB_MAKE_NV(":path", path),
404410
};
405411
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,
411417
{
412418
const nghttp2_nv nva[] = { SH2LIB_MAKE_NV(":method", "PUT"),
413419
SH2LIB_MAKE_NV(":scheme", "https"),
420+
SH2LIB_MAKE_NV(":authority", hd->hostname),
414421
SH2LIB_MAKE_NV(":path", path),
415422
};
416423
return sh2lib_do_putpost_with_nv(hd, nva, sizeof(nva) / sizeof(nva[0]), send_cb, recv_cb);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ struct sh2lib_handle {
3939
SSL_CTX *ssl_ctx; /*!< Pointer to the SSL context */
4040
SSL *ssl; /*!< Pointer to the SSL handle */
4141
nghttp2_session *http2_sess; /*!< Pointer to the HTTP2 session handle */
42-
int sockfd; /*!< Socket file descriptor */
42+
int sockfd; /*!< Socket file descriptor */
43+
char *hostname; /*!< The hostname we are connected to */
4344
};
4445

4546
/** Flag indicating receive stream is reset */

0 commit comments

Comments
 (0)