http2: enforce gzip auto-decompress
[platform/upstream/curl.git] / lib / http2.c
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
10  * This software is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution. The terms
12  * are also available at http://curl.haxx.se/docs/copyright.html.
13  *
14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15  * copies of the Software, and permit persons to whom the Software is
16  * furnished to do so, under the terms of the COPYING file.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  ***************************************************************************/
22
23 #include "curl_setup.h"
24
25 #ifdef USE_NGHTTP2
26 #define _MPRINTF_REPLACE
27 #include <curl/mprintf.h>
28
29 #include <nghttp2/nghttp2.h>
30 #include "urldata.h"
31 #include "http2.h"
32 #include "http.h"
33 #include "sendf.h"
34 #include "curl_base64.h"
35 #include "curl_memory.h"
36 #include "rawstr.h"
37
38 /* include memdebug.h last */
39 #include "memdebug.h"
40
41 #if (NGHTTP2_VERSION_NUM < 0x000300)
42 #error too old nghttp2 version, upgrade!
43 #endif
44
45 /*
46  * HTTP2 handler interface. This isn't added to the general list of protocols
47  * but will be used at run-time when the protocol is dynamically switched from
48  * HTTP to HTTP2.
49  */
50 const struct Curl_handler Curl_handler_http2 = {
51   "HTTP2",                              /* scheme */
52   ZERO_NULL,                            /* setup_connection */
53   ZERO_NULL,                            /* do_it */
54   ZERO_NULL     ,                       /* done */
55   ZERO_NULL,                            /* do_more */
56   ZERO_NULL,                            /* connect_it */
57   ZERO_NULL,                            /* connecting */
58   ZERO_NULL,                            /* doing */
59   ZERO_NULL,                            /* proto_getsock */
60   ZERO_NULL,                            /* doing_getsock */
61   ZERO_NULL,                            /* domore_getsock */
62   ZERO_NULL,                            /* perform_getsock */
63   ZERO_NULL,                            /* disconnect */
64   ZERO_NULL,                            /* readwrite */
65   PORT_HTTP,                            /* defport */
66   CURLPROTO_HTTP,                       /* protocol */
67   PROTOPT_NONE                          /* flags */
68 };
69
70
71 /*
72  * Store nghttp2 version info in this buffer, Prefix with a space.  Return
73  * total length written.
74  */
75 int Curl_http2_ver(char *p, size_t len)
76 {
77   nghttp2_info *h2 = nghttp2_version(0);
78   return snprintf(p, len, " nghttp2/%s", h2->version_str);
79 }
80
81 /*
82  * The implementation of nghttp2_send_callback type. Here we write |data| with
83  * size |length| to the network and return the number of bytes actually
84  * written. See the documentation of nghttp2_send_callback for the details.
85  */
86 static ssize_t send_callback(nghttp2_session *h2,
87                              const uint8_t *data, size_t length, int flags,
88                              void *userp)
89 {
90   struct connectdata *conn = (struct connectdata *)userp;
91   struct http_conn *httpc = &conn->proto.httpc;
92   ssize_t written;
93   CURLcode rc;
94   (void)h2;
95   (void)flags;
96
97   rc = 0;
98   written = ((Curl_send*)httpc->send_underlying)(conn, FIRSTSOCKET,
99                                                  data, length, &rc);
100
101   if(rc == CURLE_AGAIN) {
102     return NGHTTP2_ERR_WOULDBLOCK;
103   }
104
105   if(written == -1) {
106     failf(conn->data, "Failed sending HTTP2 data");
107     return NGHTTP2_ERR_CALLBACK_FAILURE;
108   }
109
110   if(!written)
111     return NGHTTP2_ERR_WOULDBLOCK;
112
113   return written;
114 }
115
116 static int on_frame_recv(nghttp2_session *session, const nghttp2_frame *frame,
117                          void *userp)
118 {
119   struct connectdata *conn = (struct connectdata *)userp;
120   struct http_conn *c = &conn->proto.httpc;
121   int rv;
122   (void)session;
123   (void)frame;
124   infof(conn->data, "on_frame_recv() was called with header %x\n",
125         frame->hd.type);
126   switch(frame->hd.type) {
127   case NGHTTP2_HEADERS:
128     if(frame->headers.cat != NGHTTP2_HCAT_RESPONSE)
129       break;
130     c->bodystarted = TRUE;
131     Curl_add_buffer(c->header_recvbuf, "\r\n", 2);
132     c->nread_header_recvbuf = c->len < c->header_recvbuf->size_used ?
133       c->len : c->header_recvbuf->size_used;
134
135     memcpy(c->mem, c->header_recvbuf->buffer, c->nread_header_recvbuf);
136
137     c->mem += c->nread_header_recvbuf;
138     c->len -= c->nread_header_recvbuf;
139     break;
140   case NGHTTP2_PUSH_PROMISE:
141     rv = nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE,
142                                    frame->hd.stream_id, NGHTTP2_CANCEL);
143     if(nghttp2_is_fatal(rv)) {
144       return rv;
145     }
146     break;
147   }
148   return 0;
149 }
150
151 static int on_invalid_frame_recv(nghttp2_session *session,
152                                  const nghttp2_frame *frame,
153                                  nghttp2_error_code error_code, void *userp)
154 {
155   struct connectdata *conn = (struct connectdata *)userp;
156   (void)session;
157   (void)frame;
158   infof(conn->data, "on_invalid_frame_recv() was called, error_code = %d\n",
159         error_code);
160   return 0;
161 }
162
163 static int on_data_chunk_recv(nghttp2_session *session, uint8_t flags,
164                               int32_t stream_id,
165                               const uint8_t *data, size_t len, void *userp)
166 {
167   struct connectdata *conn = (struct connectdata *)userp;
168   struct http_conn *c = &conn->proto.httpc;
169   size_t nread;
170   (void)session;
171   (void)flags;
172   (void)data;
173   infof(conn->data, "on_data_chunk_recv() "
174         "len = %u, stream = %x\n", len, stream_id);
175
176   if(stream_id != c->stream_id) {
177     return 0;
178   }
179
180   nread = c->len < len ? c->len : len;
181   memcpy(c->mem, data, nread);
182
183   c->mem += nread;
184   c->len -= nread;
185
186   infof(conn->data, "%zu data written\n", nread);
187
188   if(nread < len) {
189     c->data = data + nread;
190     c->datalen = len - nread;
191     return NGHTTP2_ERR_PAUSE;
192   }
193   return 0;
194 }
195
196 static int before_frame_send(nghttp2_session *session,
197                              const nghttp2_frame *frame,
198                              void *userp)
199 {
200   struct connectdata *conn = (struct connectdata *)userp;
201   struct http_conn *c = &conn->proto.httpc;
202   (void)session;
203   (void)frame;
204   infof(conn->data, "before_frame_send() was called\n");
205   if(frame->hd.type == NGHTTP2_HEADERS &&
206      frame->headers.cat == NGHTTP2_HCAT_REQUEST) {
207     /* Get stream ID of our request */
208     c->stream_id = frame->hd.stream_id;
209   }
210   return 0;
211 }
212 static int on_frame_send(nghttp2_session *session,
213                          const nghttp2_frame *frame,
214                          void *userp)
215 {
216   struct connectdata *conn = (struct connectdata *)userp;
217   (void)session;
218   (void)frame;
219   infof(conn->data, "on_frame_send() was called\n");
220   return 0;
221 }
222 static int on_frame_not_send(nghttp2_session *session,
223                              const nghttp2_frame *frame,
224                              int lib_error_code, void *userp)
225 {
226   struct connectdata *conn = (struct connectdata *)userp;
227   (void)session;
228   (void)frame;
229   infof(conn->data, "on_frame_not_send() was called, lib_error_code = %d\n",
230         lib_error_code);
231   return 0;
232 }
233 static int on_stream_close(nghttp2_session *session, int32_t stream_id,
234                            nghttp2_error_code error_code, void *userp)
235 {
236   struct connectdata *conn = (struct connectdata *)userp;
237   struct http_conn *c = &conn->proto.httpc;
238   (void)session;
239   (void)stream_id;
240   infof(conn->data, "on_stream_close() was called, error_code = %d\n",
241         error_code);
242
243   if(stream_id != c->stream_id) {
244     return 0;
245   }
246
247   c->closed = TRUE;
248
249   return 0;
250 }
251
252 static int on_unknown_frame_recv(nghttp2_session *session,
253                                  const uint8_t *head, size_t headlen,
254                                  const uint8_t *payload, size_t payloadlen,
255                                  void *userp)
256 {
257   struct connectdata *conn = (struct connectdata *)userp;
258   (void)session;
259   (void)head;
260   (void)headlen;
261   (void)payload;
262   (void)payloadlen;
263   infof(conn->data, "on_unknown_frame_recv() was called\n");
264   return 0;
265 }
266 static int on_begin_headers(nghttp2_session *session,
267                             const nghttp2_frame *frame, void *userp)
268 {
269   struct connectdata *conn = (struct connectdata *)userp;
270   (void)session;
271   (void)frame;
272   infof(conn->data, "on_begin_headers() was called\n");
273   return 0;
274 }
275
276 static const char STATUS[] = ":status";
277
278 /* frame->hd.type is either NGHTTP2_HEADERS or NGHTTP2_PUSH_PROMISE */
279 static int on_header(nghttp2_session *session, const nghttp2_frame *frame,
280                       const uint8_t *name, size_t namelen,
281                       const uint8_t *value, size_t valuelen,
282                       void *userp)
283 {
284   struct connectdata *conn = (struct connectdata *)userp;
285   struct http_conn *c = &conn->proto.httpc;
286   (void)session;
287   (void)frame;
288
289   if(frame->hd.stream_id != c->stream_id) {
290     return 0;
291   }
292
293   if(namelen == sizeof(":status") - 1 &&
294      memcmp(STATUS, name, namelen) == 0) {
295     snprintf(c->header_recvbuf->buffer, 13, "HTTP/2.0 %s", value);
296     c->header_recvbuf->buffer[12] = '\r';
297     return 0;
298   }
299   else {
300     /* convert to a HTTP1-style header */
301     infof(conn->data, "got header\n");
302     Curl_add_buffer(c->header_recvbuf, name, namelen);
303     Curl_add_buffer(c->header_recvbuf, ":", 1);
304     Curl_add_buffer(c->header_recvbuf, value, valuelen);
305     Curl_add_buffer(c->header_recvbuf, "\r\n", 2);
306   }
307
308   return 0; /* 0 is successful */
309 }
310
311 /*
312  * This is all callbacks nghttp2 calls
313  */
314 static const nghttp2_session_callbacks callbacks = {
315   send_callback,         /* nghttp2_send_callback */
316   NULL,                  /* nghttp2_recv_callback */
317   on_frame_recv,         /* nghttp2_on_frame_recv_callback */
318   on_invalid_frame_recv, /* nghttp2_on_invalid_frame_recv_callback */
319   on_data_chunk_recv,    /* nghttp2_on_data_chunk_recv_callback */
320   before_frame_send,     /* nghttp2_before_frame_send_callback */
321   on_frame_send,         /* nghttp2_on_frame_send_callback */
322   on_frame_not_send,     /* nghttp2_on_frame_not_send_callback */
323   on_stream_close,       /* nghttp2_on_stream_close_callback */
324   on_unknown_frame_recv, /* nghttp2_on_unknown_frame_recv_callback */
325   on_begin_headers,      /* nghttp2_on_begin_headers_callback */
326   on_header              /* nghttp2_on_header_callback */
327 };
328
329 /*
330  * The HTTP2 settings we send in the Upgrade request
331  */
332 static nghttp2_settings_entry settings[] = {
333   { NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 100 },
334   { NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, NGHTTP2_INITIAL_WINDOW_SIZE },
335 };
336
337 #define H2_BUFSIZE 4096
338
339 /*
340  * Initialize nghttp2 for a Curl connection
341  */
342 CURLcode Curl_http2_init(struct connectdata *conn)
343 {
344   if(!conn->proto.httpc.h2) {
345     int rc;
346     conn->proto.httpc.inbuf = malloc(H2_BUFSIZE);
347     if(conn->proto.httpc.inbuf == NULL)
348       return CURLE_OUT_OF_MEMORY;
349
350     /* The nghttp2 session is not yet setup, do it */
351     rc = nghttp2_session_client_new(&conn->proto.httpc.h2,
352                                     &callbacks, conn);
353     if(rc) {
354       failf(conn->data, "Couldn't initialize nghttp2!");
355       return CURLE_OUT_OF_MEMORY; /* most likely at least */
356     }
357   }
358   return CURLE_OK;
359 }
360
361 /*
362  * Send a request using http2
363  */
364 CURLcode Curl_http2_send_request(struct connectdata *conn)
365 {
366   (void)conn;
367   return CURLE_OK;
368 }
369
370 /*
371  * Append headers to ask for a HTTP1.1 to HTTP2 upgrade.
372  */
373 CURLcode Curl_http2_request_upgrade(Curl_send_buffer *req,
374                                     struct connectdata *conn)
375 {
376   CURLcode result;
377   ssize_t binlen;
378   char *base64;
379   size_t blen;
380   struct SingleRequest *k = &conn->data->req;
381   uint8_t *binsettings = conn->proto.httpc.binsettings;
382
383   Curl_http2_init(conn);
384
385   /* As long as we have a fixed set of settings, we don't have to dynamically
386    * figure out the base64 strings since it'll always be the same. However,
387    * the settings will likely not be fixed every time in the future.
388    */
389
390   /* this returns number of bytes it wrote */
391   binlen = nghttp2_pack_settings_payload(binsettings, H2_BINSETTINGS_LEN,
392                                          settings,
393                                          sizeof(settings)/sizeof(settings[0]));
394   if(!binlen) {
395     failf(conn->data, "nghttp2 unexpectedly failed on pack_settings_payload");
396     return CURLE_FAILED_INIT;
397   }
398   conn->proto.httpc.binlen = binlen;
399
400   result = Curl_base64_encode(conn->data, (const char *)binsettings, binlen,
401                               &base64, &blen);
402   if(result)
403     return result;
404
405   result = Curl_add_bufferf(req,
406                             "Connection: Upgrade, HTTP2-Settings\r\n"
407                             "Upgrade: %s\r\n"
408                             "HTTP2-Settings: %s\r\n",
409                             NGHTTP2_PROTO_VERSION_ID, base64);
410   free(base64);
411
412   k->upgr101 = UPGR101_REQUESTED;
413   k->auto_decoding = GZIP;
414
415   return result;
416 }
417
418 /*
419  * If the read would block (EWOULDBLOCK) we return -1. Otherwise we return
420  * a regular CURLcode value.
421  */
422 static ssize_t http2_recv(struct connectdata *conn, int sockindex,
423                           char *mem, size_t len, CURLcode *err)
424 {
425   CURLcode rc;
426   ssize_t rv;
427   ssize_t nread;
428   struct http_conn *httpc = &conn->proto.httpc;
429
430   (void)sockindex; /* we always do HTTP2 on sockindex 0 */
431
432   if(httpc->bodystarted &&
433      httpc->nread_header_recvbuf < httpc->header_recvbuf->size_used) {
434     size_t left =
435       httpc->header_recvbuf->size_used - httpc->nread_header_recvbuf;
436     size_t ncopy = len < left ? len : left;
437     memcpy(mem, httpc->header_recvbuf->buffer + httpc->nread_header_recvbuf,
438            ncopy);
439     httpc->nread_header_recvbuf += ncopy;
440     return ncopy;
441   }
442
443   if(httpc->data) {
444     nread = len < httpc->datalen ? len : httpc->datalen;
445     memcpy(mem, httpc->data, nread);
446
447     httpc->data += nread;
448     httpc->datalen -= nread;
449
450     infof(conn->data, "%zu data written\n", nread);
451     if(httpc->datalen == 0) {
452       httpc->data = NULL;
453       httpc->datalen = 0;
454     }
455     return nread;
456   }
457
458   conn->proto.httpc.mem = mem;
459   conn->proto.httpc.len = len;
460
461   infof(conn->data, "http2_recv: %d bytes buffer\n",
462         conn->proto.httpc.len);
463
464   rc = 0;
465   nread = ((Curl_recv*)httpc->recv_underlying)(conn, FIRSTSOCKET,
466                                                httpc->inbuf, H2_BUFSIZE, &rc);
467
468   if(rc == CURLE_AGAIN) {
469     *err = rc;
470     return -1;
471   }
472
473   if(nread == -1) {
474     failf(conn->data, "Failed receiving HTTP2 data");
475     *err = rc;
476     return 0;
477   }
478
479   infof(conn->data, "nread=%zd\n", nread);
480   rv = nghttp2_session_mem_recv(httpc->h2,
481                                 (const uint8_t *)httpc->inbuf, nread);
482
483   if(nghttp2_is_fatal((int)rv)) {
484     failf(conn->data, "nghttp2_session_mem_recv() returned %d:%s\n",
485           rv, nghttp2_strerror((int)rv));
486     *err = CURLE_RECV_ERROR;
487     return 0;
488   }
489   infof(conn->data, "nghttp2_session_mem_recv() returns %zd\n", rv);
490   /* Always send pending frames in nghttp2 session, because
491      nghttp2_session_mem_recv() may queue new frame */
492   rv = nghttp2_session_send(httpc->h2);
493   if(rv != 0) {
494     *err = CURLE_SEND_ERROR;
495     return 0;
496   }
497   if(len != httpc->len) {
498     return len - conn->proto.httpc.len;
499   }
500   /* If stream is closed, return 0 to signal the http routine to close
501      the connection */
502   if(httpc->closed) {
503     return 0;
504   }
505   *err = CURLE_AGAIN;
506   return -1;
507 }
508
509 #define MAKE_NV(k, v)                                           \
510   { (uint8_t*)k, (uint8_t*)v, sizeof(k) - 1, sizeof(v) - 1 }
511
512 #define MAKE_NV2(k, v, vlen)                            \
513   { (uint8_t*)k, (uint8_t*)v, sizeof(k) - 1, vlen }
514
515 /* return number of received (decrypted) bytes */
516 static ssize_t http2_send(struct connectdata *conn, int sockindex,
517                           const void *mem, size_t len, CURLcode *err)
518 {
519   /*
520    * BIG TODO: Currently, we send request in this function, but this
521    * function is also used to send request body. It would be nice to
522    * add dedicated function for request.
523    */
524   int rv;
525   struct http_conn *httpc = &conn->proto.httpc;
526   nghttp2_nv *nva;
527   size_t nheader;
528   size_t i;
529   char *hdbuf = (char*)mem;
530   char *end;
531   (void)sockindex;
532
533   infof(conn->data, "http2_send len=%zu\n", len);
534
535   /* Calculate number of headers contained in [mem, mem + len) */
536   /* Here, we assume the curl http code generate *correct* HTTP header
537      field block */
538   nheader = 0;
539   for(i = 0; i < len; ++i) {
540     if(hdbuf[i] == 0x0a) {
541       ++nheader;
542     }
543   }
544   /* We counted additional 2 \n in the first and last line. We need 3
545      new headers: :method, :path and :scheme. Therefore we need one
546      more space. */
547   nheader += 1;
548   nva = malloc(sizeof(nghttp2_nv) * nheader);
549   if(nva == NULL) {
550     *err = CURLE_OUT_OF_MEMORY;
551     return -1;
552   }
553   /* Extract :method, :path from request line */
554   end = strchr(hdbuf, ' ');
555   nva[0].name = (unsigned char *)":method";
556   nva[0].namelen = (uint16_t)strlen((char *)nva[0].name);
557   nva[0].value = (unsigned char *)hdbuf;
558   nva[0].valuelen = (uint16_t)(end - hdbuf);
559
560   hdbuf = end + 1;
561
562   end = strchr(hdbuf, ' ');
563   nva[1].name = (unsigned char *)":path";
564   nva[1].namelen = (uint16_t)strlen((char *)nva[1].name);
565   nva[1].value = (unsigned char *)hdbuf;
566   nva[1].valuelen = (uint16_t)(end - hdbuf);
567
568   nva[2].name = (unsigned char *)":scheme";
569   nva[2].namelen = (uint16_t)strlen((char *)nva[2].name);
570   if(conn->handler->flags & PROTOPT_SSL)
571     nva[2].value = (unsigned char *)"https";
572   else
573     nva[2].value = (unsigned char *)"http";
574   nva[2].valuelen = (uint16_t)strlen((char *)nva[2].value);
575
576   hdbuf = strchr(hdbuf, 0x0a);
577   ++hdbuf;
578
579   for(i = 3; i < nheader; ++i) {
580     end = strchr(hdbuf, ':');
581     assert(end);
582     if(end - hdbuf == 4 && Curl_raw_nequal("host", hdbuf, 4)) {
583       nva[i].name = (unsigned char *)":authority";
584       nva[i].namelen = (uint16_t)strlen((char *)nva[i].name);
585     }
586     else {
587       nva[i].name = (unsigned char *)hdbuf;
588       nva[i].namelen = (uint16_t)(end - hdbuf);
589     }
590     hdbuf = end + 1;
591     for(; *hdbuf == ' '; ++hdbuf);
592     end = strchr(hdbuf, 0x0d);
593     assert(end);
594     nva[i].value = (unsigned char *)hdbuf;
595     nva[i].valuelen = (uint16_t)(end - hdbuf);
596
597     hdbuf = end + 2;
598   }
599
600   rv = nghttp2_submit_request(httpc->h2, 0, nva, nheader, NULL, NULL);
601
602   free(nva);
603
604   if(rv != 0) {
605     *err = CURLE_SEND_ERROR;
606     return -1;
607   }
608
609   rv = nghttp2_session_send(httpc->h2);
610
611   if(rv != 0) {
612     *err = CURLE_SEND_ERROR;
613     return -1;
614   }
615
616   /* TODO: Still whole HEADERS frame may have not been sent because of
617      EAGAIN. But I don't know how to setup to call
618      nghttp2_session_send() when socket becomes writable. */
619
620   return len;
621 }
622
623 int Curl_http2_switched(struct connectdata *conn)
624 {
625   int rv;
626   CURLcode rc;
627   struct http_conn *httpc = &conn->proto.httpc;
628   /* we are switched! */
629   /* Don't know this is needed here at this moment. Original
630      handler->flags is still useful. */
631   /* conn->handler = &Curl_handler_http2; */
632   httpc->recv_underlying = (recving)conn->recv[FIRSTSOCKET];
633   httpc->send_underlying = (sending)conn->send[FIRSTSOCKET];
634   conn->recv[FIRSTSOCKET] = http2_recv;
635   conn->send[FIRSTSOCKET] = http2_send;
636   infof(conn->data, "We have switched to HTTP2\n");
637   httpc->bodystarted = FALSE;
638   httpc->closed = FALSE;
639   httpc->header_recvbuf = Curl_add_buffer_init();
640   httpc->nread_header_recvbuf = 0;
641   httpc->data = NULL;
642   httpc->datalen = 0;
643
644   conn->data->req.auto_decoding = GZIP;
645
646   /* Put place holder for status line */
647   Curl_add_buffer(httpc->header_recvbuf, "HTTP/2.0 200\r\n", 14);
648
649   /* TODO: May get CURLE_AGAIN */
650   rv = (int) ((Curl_send*)httpc->send_underlying)
651     (conn, FIRSTSOCKET,
652      NGHTTP2_CLIENT_CONNECTION_HEADER,
653      NGHTTP2_CLIENT_CONNECTION_HEADER_LEN,
654      &rc);
655   assert(rv == 24);
656   if(conn->data->req.upgr101 == UPGR101_RECEIVED) {
657     /* stream 1 is opened implicitly on upgrade */
658     httpc->stream_id = 1;
659     /* queue SETTINGS frame (again) */
660     rv = nghttp2_session_upgrade(httpc->h2, httpc->binsettings,
661                                  httpc->binlen, NULL);
662     if(rv != 0) {
663       failf(conn->data, "nghttp2_session_upgrade() failed: %s(%d)",
664             nghttp2_strerror(rv), rv);
665       return -1;
666     }
667   }
668   else {
669     /* stream ID is unknown at this point */
670     httpc->stream_id = -1;
671     rv = nghttp2_submit_settings(httpc->h2, NGHTTP2_FLAG_NONE, NULL, 0);
672     if(rv != 0) {
673       failf(conn->data, "nghttp2_submit_settings() failed: %s(%d)",
674             nghttp2_strerror(rv), rv);
675       return -1;
676     }
677   }
678   return 0;
679 }
680
681 #endif