Added HTTP OPTIONS support:
[platform/upstream/libwebsockets.git] / lib / parsers.c
index b71c63c..a8d0a5e 100644 (file)
@@ -194,6 +194,7 @@ int libwebsocket_parse(
        switch (wsi->u.hdr.parser_state) {
        case WSI_TOKEN_GET_URI:
        case WSI_TOKEN_POST_URI:
+       case WSI_TOKEN_OPTIONS_URI:
        case WSI_TOKEN_HOST:
        case WSI_TOKEN_CONNECTION:
        case WSI_TOKEN_KEY1:
@@ -235,7 +236,9 @@ int libwebsocket_parse(
                                      wsi->u.hdr.parser_state]].len && c == ' ')
                        break;
 
-               if ((wsi->u.hdr.parser_state != WSI_TOKEN_GET_URI) && (wsi->u.hdr.parser_state != WSI_TOKEN_POST_URI))
+               if ((wsi->u.hdr.parser_state != WSI_TOKEN_GET_URI) &&
+                       (wsi->u.hdr.parser_state != WSI_TOKEN_POST_URI) &&
+                       (wsi->u.hdr.parser_state != WSI_TOKEN_OPTIONS_URI))
                        goto check_eol;
 
                /* special URI processing... end at space */
@@ -417,8 +420,10 @@ swallow:
 
                if (wsi->u.hdr.lextable_pos < 0) {
                        /* this is not a header we know about */
-                       if (wsi->u.hdr.ah->frag_index[WSI_TOKEN_GET_URI] || wsi->u.hdr.ah->frag_index[WSI_TOKEN_POST_URI] ||
-                                   wsi->u.hdr.ah->frag_index[WSI_TOKEN_HTTP]) {
+                       if (wsi->u.hdr.ah->frag_index[WSI_TOKEN_GET_URI] ||
+                               wsi->u.hdr.ah->frag_index[WSI_TOKEN_POST_URI] ||
+                               wsi->u.hdr.ah->frag_index[WSI_TOKEN_OPTIONS_URI] ||
+                               wsi->u.hdr.ah->frag_index[WSI_TOKEN_HTTP]) {
                                /*
                                 * altready had the method, no idea what
                                 * this crap is, ignore
@@ -449,6 +454,10 @@ swallow:
                                wsi->u.hdr.ah->frag_index[WSI_TOKEN_POST_URI]) {
                                lwsl_warn("Duplicated POST\n");
                                return -1;
+                       } else if (n == WSI_TOKEN_OPTIONS_URI &&
+                               wsi->u.hdr.ah->frag_index[WSI_TOKEN_OPTIONS_URI]) {
+                               lwsl_warn("Duplicated OPTIONS\n");
+                               return -1;
                        }
 
                        /*