Skip to content

Commit 324a97e

Browse files
Diego Besbagder
Diego Bes
authored andcommitted
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.
1 parent e683182 commit 324a97e

File tree

7 files changed

+29
-8
lines changed

7 files changed

+29
-8
lines changed

docs/HTTP2.md

+3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ curl tool
9696

9797
curl offers the `--http2` command line option to enable use of HTTP/2.
9898

99+
curl offers the `--http2-prior-knowledge` command line option to enable use of
100+
HTTP/2 without HTTP/1.1 Upgrade.
101+
99102
Since 7.47.0, the curl tool enables HTTP/2 by default for HTTPS connections.
100103

101104
HTTP Alternative Services

docs/curl.1

+5
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ version. (Added in 7.33.0)
150150
.IP "--http2"
151151
(HTTP) Tells curl to issue its requests using HTTP 2. This requires that the
152152
underlying libcurl was built to support it. (Added in 7.33.0)
153+
.IP "--http2-prior-knowledge"
154+
(HTTP) Tells curl to issue its requests using HTTP 2 without HTTP/1.1 Upgrade.
155+
This requires prior knowledge that the server supports HTTP 2.
156+
This requires that the underlying libcurl was built to support it.
157+
(Added in 7.49.0)
153158
.IP "--no-npn"
154159
Disable the NPN TLS extension. NPN is enabled by default if libcurl was built
155160
with an SSL library that supports NPN. NPN is used by a libcurl that supports

docs/libcurl/symbols-in-versions

+1
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ CURL_HTTP_VERSION_1_1 7.9.1
695695
CURL_HTTP_VERSION_2 7.43.0
696696
CURL_HTTP_VERSION_2_0 7.33.0
697697
CURL_HTTP_VERSION_2TLS 7.47.0
698+
CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE 7.49.0
698699
CURL_HTTP_VERSION_NONE 7.9.1
699700
CURL_IPRESOLVE_V4 7.10.8
700701
CURL_IPRESOLVE_V6 7.10.8

include/curl/curl.h

+2
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,8 @@ enum {
17271727
CURL_HTTP_VERSION_1_1, /* please use HTTP 1.1 in the request */
17281728
CURL_HTTP_VERSION_2_0, /* please use HTTP 2 in the request */
17291729
CURL_HTTP_VERSION_2TLS, /* use version 2 for HTTPS, version 1.1 for HTTP */
1730+
CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE, /* please use HTTP 2 without HTTP/1.1
1731+
Upgrade */
17301732

17311733
CURL_HTTP_VERSION_LAST /* *ILLEGAL* http version */
17321734
};

lib/http.c

+12-8
Original file line numberDiff line numberDiff line change
@@ -1792,13 +1792,6 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
17921792
switch(conn->negnpn) {
17931793
case CURL_HTTP_VERSION_2:
17941794
conn->httpversion = 20; /* we know we're on HTTP/2 now */
1795-
result = Curl_http2_init(conn);
1796-
if(result)
1797-
return result;
1798-
1799-
result = Curl_http2_setup(conn);
1800-
if(result)
1801-
return result;
18021795

18031796
result = Curl_http2_switched(conn, NULL, 0);
18041797
if(result)
@@ -1808,7 +1801,18 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
18081801
/* continue with HTTP/1.1 when explicitly requested */
18091802
break;
18101803
default:
1811-
/* and as fallback */
1804+
/* Check if user wants to use HTTP/2 with clear TCP*/
1805+
#ifdef USE_NGHTTP2
1806+
if(conn->data->set.httpversion ==
1807+
CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE) {
1808+
DEBUGF(infof(data, "HTTP/2 over clean TCP\n"));
1809+
conn->httpversion = 20;
1810+
1811+
result = Curl_http2_switched(conn, NULL, 0);
1812+
if(result)
1813+
return result;
1814+
}
1815+
#endif
18121816
break;
18131817
}
18141818
}

src/tool_getparam.c

+5
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ static const struct LongShort aliases[]= {
184184
{"0", "http1.0", FALSE},
185185
{"01", "http1.1", FALSE},
186186
{"02", "http2", FALSE},
187+
{"03", "http2-prior-knowledge", FALSE},
187188
{"1", "tlsv1", FALSE},
188189
{"10", "tlsv1.0", FALSE},
189190
{"11", "tlsv1.1", FALSE},
@@ -1036,6 +1037,10 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
10361037
/* HTTP version 2.0 */
10371038
config->httpversion = CURL_HTTP_VERSION_2_0;
10381039
break;
1040+
case '3':
1041+
/* HTTP version 2.0 over clean TCP*/
1042+
config->httpversion = CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE;
1043+
break;
10391044
}
10401045
break;
10411046
case '1': /* --tlsv1* options */

src/tool_help.c

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

0 commit comments

Comments
 (0)