Commit 4bcc532d authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

http: add libcurl option to allow HTTP/2 for HTTPS only

... and stick to 1.1 for HTTP. This is in line with what browsers do and
should have very little risk.
parent 7f683b0e
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -45,8 +45,15 @@ Enforce HTTP 1.0 requests.
.IP CURL_HTTP_VERSION_1_1
Enforce HTTP 1.1 requests.
.IP CURL_HTTP_VERSION_2_0
Attempt HTTP 2 requests. libcurl will fall back to HTTP 1.x if HTTP 2 can't be
Attempt HTTP 2 requests. libcurl will fall back to HTTP 1.1 if HTTP 2 can't be
negotiated with the server. (Added in 7.33.0)

The alias \fICURL_HTTP_VERSION_2\fI was added in 7.43.0 to better reflect the
actual protocol name.
.IP CURL_HTTP_VERSION_2TLS
Attempt HTTP 2 over TLS (HTTPS) only. libcurl will fall back to HTTP 1.1 if
HTTP 2 can't be negotiated with the HTTPS server. For clear text HTTP servers,
libcurl will use 1.1. (Added in 7.47.0)
.SH DEFAULT
CURL_HTTP_VERSION_NONE
.SH PROTOCOLS
+1 −0
Original line number Diff line number Diff line
@@ -692,6 +692,7 @@ CURL_HTTP_VERSION_1_0 7.9.1
CURL_HTTP_VERSION_1_1           7.9.1
CURL_HTTP_VERSION_2             7.43.0
CURL_HTTP_VERSION_2_0           7.33.0
CURL_HTTP_VERSION_2TLS          7.47.0
CURL_HTTP_VERSION_NONE          7.9.1
CURL_IPRESOLVE_V4               7.10.8
CURL_IPRESOLVE_V6               7.10.8
+2 −1
Original line number Diff line number Diff line
@@ -1722,7 +1722,8 @@ enum {
                             for us! */
  CURL_HTTP_VERSION_1_0,  /* please use HTTP 1.0 in the request */
  CURL_HTTP_VERSION_1_1,  /* please use HTTP 1.1 in the request */
  CURL_HTTP_VERSION_2_0,  /* please use HTTP 2.0 in the request */
  CURL_HTTP_VERSION_2_0,  /* please use HTTP 2 in the request */
  CURL_HTTP_VERSION_2TLS, /* use version 2 for HTTPS, version 1.1 for HTTP */

  CURL_HTTP_VERSION_LAST /* *ILLEGAL* http version */
};
+9 −7
Original line number Diff line number Diff line
@@ -1539,11 +1539,13 @@ CURLcode Curl_http_done(struct connectdata *conn,
static bool use_http_1_1plus(const struct SessionHandle *data,
                             const struct connectdata *conn)
{
  return ((data->set.httpversion >= CURL_HTTP_VERSION_1_1) ||
         ((data->set.httpversion != CURL_HTTP_VERSION_1_0) &&
          ((conn->httpversion == 11) ||
           ((conn->httpversion != 10) &&
            (data->state.httpversion != 10))))) ? TRUE : FALSE;
  if((data->state.httpversion == 10) || (conn->httpversion == 10))
    return FALSE;
  if((data->set.httpversion == CURL_HTTP_VERSION_1_0) &&
     (conn->httpversion <= 10))
    return FALSE;
  return ((data->set.httpversion == CURL_HTTP_VERSION_NONE) ||
          (data->set.httpversion >= CURL_HTTP_VERSION_1_1));
}

/* check and possibly add an Expect: header */
@@ -1785,7 +1787,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
  if(conn->httpversion < 20) { /* unless the connection is re-used and already
                                  http2 */
    switch(conn->negnpn) {
    case CURL_HTTP_VERSION_2_0:
    case CURL_HTTP_VERSION_2:
      conn->httpversion = 20; /* we know we're on HTTP/2 now */
      result = Curl_http2_init(conn);
      if(result)
@@ -2338,7 +2340,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)

  if(!(conn->handler->flags&PROTOPT_SSL) &&
     conn->httpversion != 20 &&
     (data->set.httpversion == CURL_HTTP_VERSION_2_0)) {
     (data->set.httpversion == CURL_HTTP_VERSION_2)) {
    /* append HTTP2 upgrade magic stuff to the HTTP request if it isn't done
       over SSL */
    result = Curl_http2_request_upgrade(req_buffer, conn);
+2 −2
Original line number Diff line number Diff line
@@ -1294,7 +1294,7 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
     */
    arg = va_arg(param, long);
#ifndef USE_NGHTTP2
    if(arg == CURL_HTTP_VERSION_2_0)
    if(arg >= CURL_HTTP_VERSION_2)
      return CURLE_UNSUPPORTED_PROTOCOL;
#endif
    data->set.httpversion = arg;
@@ -2865,7 +2865,7 @@ static bool IsPipeliningPossible(const struct SessionHandle *handle,
      return TRUE;

    if(Curl_pipeline_wanted(handle->multi, CURLPIPE_MULTIPLEX) &&
       (handle->set.httpversion == CURL_HTTP_VERSION_2_0))
       (handle->set.httpversion >= CURL_HTTP_VERSION_2))
      /* allows HTTP/2 */
      return TRUE;
  }
Loading