1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

http2: support "prior knowledge", no upgrade from HTTP/1.1

Supports HTTP/2 over clear TCP

- Optimize switching to HTTP/2 by removing calls to init and setup
before switching. Switching will eventually call setup and setup calls
init.

- Supports new version to “force” the use of HTTP/2 over clean TCP

- Add common line parameter “--http2-prior-knowledge” to the Curl
  command line tool.
This commit is contained in:
Diego Bes 2016-03-18 15:25:56 -07:00 committed by Daniel Stenberg
parent e683182918
commit 324a97ecf8
7 changed files with 29 additions and 8 deletions

View File

@ -96,6 +96,9 @@ curl tool
curl offers the `--http2` command line option to enable use of HTTP/2. curl offers the `--http2` command line option to enable use of HTTP/2.
curl offers the `--http2-prior-knowledge` command line option to enable use of
HTTP/2 without HTTP/1.1 Upgrade.
Since 7.47.0, the curl tool enables HTTP/2 by default for HTTPS connections. Since 7.47.0, the curl tool enables HTTP/2 by default for HTTPS connections.
HTTP Alternative Services HTTP Alternative Services

View File

@ -150,6 +150,11 @@ version. (Added in 7.33.0)
.IP "--http2" .IP "--http2"
(HTTP) Tells curl to issue its requests using HTTP 2. This requires that the (HTTP) Tells curl to issue its requests using HTTP 2. This requires that the
underlying libcurl was built to support it. (Added in 7.33.0) underlying libcurl was built to support it. (Added in 7.33.0)
.IP "--http2-prior-knowledge"
(HTTP) Tells curl to issue its requests using HTTP 2 without HTTP/1.1 Upgrade.
This requires prior knowledge that the server supports HTTP 2.
This requires that the underlying libcurl was built to support it.
(Added in 7.49.0)
.IP "--no-npn" .IP "--no-npn"
Disable the NPN TLS extension. NPN is enabled by default if libcurl was built Disable the NPN TLS extension. NPN is enabled by default if libcurl was built
with an SSL library that supports NPN. NPN is used by a libcurl that supports with an SSL library that supports NPN. NPN is used by a libcurl that supports

View File

@ -695,6 +695,7 @@ CURL_HTTP_VERSION_1_1 7.9.1
CURL_HTTP_VERSION_2 7.43.0 CURL_HTTP_VERSION_2 7.43.0
CURL_HTTP_VERSION_2_0 7.33.0 CURL_HTTP_VERSION_2_0 7.33.0
CURL_HTTP_VERSION_2TLS 7.47.0 CURL_HTTP_VERSION_2TLS 7.47.0
CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE 7.49.0
CURL_HTTP_VERSION_NONE 7.9.1 CURL_HTTP_VERSION_NONE 7.9.1
CURL_IPRESOLVE_V4 7.10.8 CURL_IPRESOLVE_V4 7.10.8
CURL_IPRESOLVE_V6 7.10.8 CURL_IPRESOLVE_V6 7.10.8

View File

@ -1727,6 +1727,8 @@ enum {
CURL_HTTP_VERSION_1_1, /* please use HTTP 1.1 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 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_2TLS, /* use version 2 for HTTPS, version 1.1 for HTTP */
CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE, /* please use HTTP 2 without HTTP/1.1
Upgrade */
CURL_HTTP_VERSION_LAST /* *ILLEGAL* http version */ CURL_HTTP_VERSION_LAST /* *ILLEGAL* http version */
}; };

View File

@ -1792,13 +1792,6 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
switch(conn->negnpn) { switch(conn->negnpn) {
case CURL_HTTP_VERSION_2: case CURL_HTTP_VERSION_2:
conn->httpversion = 20; /* we know we're on HTTP/2 now */ conn->httpversion = 20; /* we know we're on HTTP/2 now */
result = Curl_http2_init(conn);
if(result)
return result;
result = Curl_http2_setup(conn);
if(result)
return result;
result = Curl_http2_switched(conn, NULL, 0); result = Curl_http2_switched(conn, NULL, 0);
if(result) if(result)
@ -1808,7 +1801,18 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
/* continue with HTTP/1.1 when explicitly requested */ /* continue with HTTP/1.1 when explicitly requested */
break; break;
default: default:
/* and as fallback */ /* Check if user wants to use HTTP/2 with clear TCP*/
#ifdef USE_NGHTTP2
if(conn->data->set.httpversion ==
CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE) {
DEBUGF(infof(data, "HTTP/2 over clean TCP\n"));
conn->httpversion = 20;
result = Curl_http2_switched(conn, NULL, 0);
if(result)
return result;
}
#endif
break; break;
} }
} }

View File

@ -184,6 +184,7 @@ static const struct LongShort aliases[]= {
{"0", "http1.0", FALSE}, {"0", "http1.0", FALSE},
{"01", "http1.1", FALSE}, {"01", "http1.1", FALSE},
{"02", "http2", FALSE}, {"02", "http2", FALSE},
{"03", "http2-prior-knowledge", FALSE},
{"1", "tlsv1", FALSE}, {"1", "tlsv1", FALSE},
{"10", "tlsv1.0", FALSE}, {"10", "tlsv1.0", FALSE},
{"11", "tlsv1.1", FALSE}, {"11", "tlsv1.1", FALSE},
@ -1036,6 +1037,10 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
/* HTTP version 2.0 */ /* HTTP version 2.0 */
config->httpversion = CURL_HTTP_VERSION_2_0; config->httpversion = CURL_HTTP_VERSION_2_0;
break; break;
case '3':
/* HTTP version 2.0 over clean TCP*/
config->httpversion = CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE;
break;
} }
break; break;
case '1': /* --tlsv1* options */ case '1': /* --tlsv1* options */

View File

@ -111,6 +111,7 @@ static const char *const helptext[] = {
" -0, --http1.0 Use HTTP 1.0 (H)", " -0, --http1.0 Use HTTP 1.0 (H)",
" --http1.1 Use HTTP 1.1 (H)", " --http1.1 Use HTTP 1.1 (H)",
" --http2 Use HTTP 2 (H)", " --http2 Use HTTP 2 (H)",
" --http2-prior-knowledge Use HTTP 2 without HTTP/1.1 Upgrade (H)",
" --ignore-content-length Ignore the HTTP Content-Length header", " --ignore-content-length Ignore the HTTP Content-Length header",
" -i, --include Include protocol headers in the output (H/F)", " -i, --include Include protocol headers in the output (H/F)",
" -k, --insecure Allow connections to SSL sites without certs (H)", " -k, --insecure Allow connections to SSL sites without certs (H)",