@@ -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
336341int 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
362367int 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 );
0 commit comments