Commit 7bda07b0 authored by Michael Kaufmann's avatar Michael Kaufmann Committed by Daniel Stenberg
Browse files

HTTP: stop parsing headers when switching to unknown protocols

- unknown protocols probably won't send more headers (e.g. WebSocket)
- improved comments and moved them to the correct case statements

Closes #899
parent 9cb851e3
Loading
Loading
Loading
Loading
+23 −10
Original line number Original line Diff line number Diff line
@@ -3054,6 +3054,9 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
#endif /* CURL_DOES_CONVERSIONS */
#endif /* CURL_DOES_CONVERSIONS */


      if(100 <= k->httpcode && 199 >= k->httpcode) {
      if(100 <= k->httpcode && 199 >= k->httpcode) {
        /* "A user agent MAY ignore unexpected 1xx status responses." */
        switch(k->httpcode) {
        case 100:
          /*
          /*
           * We have made a HTTP PUT or POST and this is 1.1-lingo
           * We have made a HTTP PUT or POST and this is 1.1-lingo
           * that tells us that the server is OK with this and ready
           * that tells us that the server is OK with this and ready
@@ -3064,9 +3067,6 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
          k->header = TRUE;
          k->header = TRUE;
          k->headerline = 0; /* restart the header line counter */
          k->headerline = 0; /* restart the header line counter */


        /* "A user agent MAY ignore unexpected 1xx status responses." */
        switch(k->httpcode) {
        case 100:
          /* if we did wait for this do enable write now! */
          /* if we did wait for this do enable write now! */
          if(k->exp100 > EXP100_SEND_DATA) {
          if(k->exp100 > EXP100_SEND_DATA) {
            k->exp100 = EXP100_SEND_DATA;
            k->exp100 = EXP100_SEND_DATA;
@@ -3076,9 +3076,14 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
        case 101:
        case 101:
          /* Switching Protocols */
          /* Switching Protocols */
          if(k->upgr101 == UPGR101_REQUESTED) {
          if(k->upgr101 == UPGR101_REQUESTED) {
            /* Switching to HTTP/2 */
            infof(data, "Received 101\n");
            infof(data, "Received 101\n");
            k->upgr101 = UPGR101_RECEIVED;
            k->upgr101 = UPGR101_RECEIVED;


            /* we'll get more headers (HTTP/2 response) */
            k->header = TRUE;
            k->headerline = 0; /* restart the header line counter */

            /* switch to http2 now. The bytes after response headers
            /* switch to http2 now. The bytes after response headers
               are also processed here, otherwise they are lost. */
               are also processed here, otherwise they are lost. */
            result = Curl_http2_switched(conn, k->str, *nread);
            result = Curl_http2_switched(conn, k->str, *nread);
@@ -3086,8 +3091,16 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
              return result;
              return result;
            *nread = 0;
            *nread = 0;
          }
          }
          else {
            /* Switching to another protocol (e.g. WebSocket) */
            k->header = FALSE; /* no more header to parse! */
          }
          break;
          break;
        default:
        default:
          /* the status code 1xx indicates a provisional response, so
             we'll get another set of headers */
          k->header = TRUE;
          k->headerline = 0; /* restart the header line counter */
          break;
          break;
        }
        }
      }
      }