mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 15:48:49 -05:00
http2: switch into http2 mode if NPN indicates
Check the NPN result before preparing an HTTP request and switch into HTTP/2.0 mode if necessary. This is a work in progress, the actual code to prepare and send the request using nghttp2 is still missing from Curl_http2_send_request().
This commit is contained in:
parent
8e778887b5
commit
dd011df9e1
15
lib/http.c
15
lib/http.c
@ -1668,6 +1668,21 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
|
||||
the rest of the request in the PERFORM phase. */
|
||||
*done = TRUE;
|
||||
|
||||
switch (conn->negnpn) {
|
||||
case NPN_HTTP2_DRAFT09:
|
||||
infof(data, "http, we have to use HTTP-draft-09/2\n");
|
||||
Curl_http2_init(conn);
|
||||
Curl_http2_switched(conn);
|
||||
Curl_http2_send_request(conn);
|
||||
break;
|
||||
case NPN_HTTP1_1:
|
||||
/* continue with HTTP/1.1 when explicitly requested */
|
||||
break;
|
||||
default:
|
||||
/* and as fallback */
|
||||
break;
|
||||
}
|
||||
|
||||
http = data->req.protop;
|
||||
|
||||
if(!data->state.this_is_a_follow) {
|
||||
|
43
lib/http2.c
43
lib/http2.c
@ -115,8 +115,12 @@ static ssize_t recv_callback(nghttp2_session *h2,
|
||||
{
|
||||
struct connectdata *conn = (struct connectdata *)userp;
|
||||
ssize_t nread;
|
||||
CURLcode rc = Curl_read_plain(conn->sock[FIRSTSOCKET], (char *)buf, length,
|
||||
&nread);
|
||||
CURLcode rc;
|
||||
|
||||
infof(conn->data, "recv_callback() was called with length %d\n", length);
|
||||
|
||||
rc = Curl_read_plain(conn->sock[FIRSTSOCKET], (char *)buf, length,
|
||||
&nread);
|
||||
(void)h2;
|
||||
(void)flags;
|
||||
|
||||
@ -285,6 +289,31 @@ static nghttp2_settings_entry settings[] = {
|
||||
{ NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, NGHTTP2_INITIAL_WINDOW_SIZE },
|
||||
};
|
||||
|
||||
/*
|
||||
* Initialize nghttp2 for a Curl connection
|
||||
*/
|
||||
CURLcode Curl_http2_init(struct connectdata *conn) {
|
||||
if(!conn->proto.httpc.h2) {
|
||||
/* The nghttp2 session is not yet setup, do it */
|
||||
int rc = nghttp2_session_client_new(&conn->proto.httpc.h2,
|
||||
&callbacks, conn);
|
||||
if(rc) {
|
||||
failf(conn->data, "Couldn't initialize nghttp2!");
|
||||
return CURLE_OUT_OF_MEMORY; /* most likely at least */
|
||||
}
|
||||
}
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a request using http2
|
||||
*/
|
||||
CURLcode Curl_http2_send_request(struct connectdata *conn)
|
||||
{
|
||||
(void)conn;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Append headers to ask for a HTTP1.1 to HTTP2 upgrade.
|
||||
*/
|
||||
@ -298,15 +327,7 @@ CURLcode Curl_http2_request_upgrade(Curl_send_buffer *req,
|
||||
size_t blen;
|
||||
struct SingleRequest *k = &conn->data->req;
|
||||
|
||||
if(!conn->proto.httpc.h2) {
|
||||
/* The nghttp2 session is not yet setup, do it */
|
||||
int rc = nghttp2_session_client_new(&conn->proto.httpc.h2,
|
||||
&callbacks, conn);
|
||||
if(rc) {
|
||||
failf(conn->data, "Couldn't initialize nghttp2!");
|
||||
return CURLE_OUT_OF_MEMORY; /* most likely at least */
|
||||
}
|
||||
}
|
||||
Curl_http2_init(conn);
|
||||
|
||||
/* As long as we have a fixed set of settings, we don't have to dynamically
|
||||
* figure out the base64 strings since it'll always be the same. However,
|
||||
|
Loading…
Reference in New Issue
Block a user