]> granicus.if.org Git - curl/commitdiff
sws: initial tiny steps toward http2 support
authorDaniel Stenberg <daniel@haxx.se>
Sat, 2 Aug 2014 22:46:39 +0000 (00:46 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 20 Nov 2014 22:33:34 +0000 (23:33 +0100)
tests/server/sws.c

index 38658cb7472047075ab924260dcd95cce96f1f1f..98c101cf7eec411aeec425f481615082c8004269 100644 (file)
@@ -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
@@ -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;
 };
 
@@ -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 {
@@ -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)
@@ -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 */
@@ -1754,6 +1769,14 @@ http_connect_cleanup:
   *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)
@@ -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) {