Skip to content

Commit

Permalink
sws: initial tiny steps toward http2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
bagder committed Nov 20, 2014
1 parent 52655b4 commit ac5eb7f
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion tests/server/sws.c
Expand Up @@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
Expand Down Expand Up @@ -114,6 +114,8 @@ struct httprequest {
bool pipelining; /* true if request is pipelined */
int callcount; /* times ProcessRequest() gets called */
bool connmon; /* monitor the state of the connection, log disconnects */
bool upgrade; /* test case allows upgrade to http2 */
bool upgrade_request; /* upgrade request found and allowed */
int done_processing;
};

Expand Down Expand Up @@ -164,6 +166,9 @@ const char *serverlogfile = DEFAULT_LOGFILE;
proper point - like with NTLM */
#define CMD_CONNECTIONMONITOR "connection-monitor"

/* upgrade to http2 */
#define CMD_UPGRADE "upgrade"

#define END_OF_HEADERS "\r\n\r\n"

enum {
Expand Down Expand Up @@ -376,6 +381,10 @@ static int parse_servercmd(struct httprequest *req)
logmsg("enabled connection monitoring");
req->connmon = TRUE;
}
else if(!strncmp(CMD_UPGRADE, cmd, strlen(CMD_UPGRADE))) {
logmsg("enabled upgrade to http2");
req->upgrade = TRUE;
}
else if(1 == sscanf(cmd, "pipe: %d", &num)) {
logmsg("instructed to allow a pipe size of %d", num);
if(num < 0)
Expand Down Expand Up @@ -789,6 +798,12 @@ static int ProcessRequest(struct httprequest *req)
return 1; /* done */
}

if(req->upgrade && strstr(req->reqbuf, "Upgrade:")) {
/* we allow upgrade and there was one! */
logmsg("Found Upgrade: in request and allows it");
req->upgrade_request = TRUE;
}

if(req->cl > 0) {
if(req->cl <= req->offset - (end - req->reqbuf) - strlen(end_of_headers))
return 1; /* done */
Expand Down Expand Up @@ -1754,6 +1769,14 @@ static void http_connect(curl_socket_t *infdp,
*infdp = CURL_SOCKET_BAD;
}

static void http2(struct httprequest *req)
{
(void)req;
logmsg("switched to http2");
/* left to implement */
}


/* returns a socket handle, or 0 if there are no more waiting sockets,
or < 0 if there was an error */
static curl_socket_t accept_connection(curl_socket_t sock)
Expand Down Expand Up @@ -1889,6 +1912,12 @@ static int service_connection(curl_socket_t msgsock, struct httprequest *req,
}
}

if(req->upgrade_request) {
/* an upgrade request, switch to http2 here */
http2(req);
return -1;
}

/* if we got a CONNECT, loop and get another request as well! */

if(req->open) {
Expand Down

0 comments on commit ac5eb7f

Please sign in to comment.