1 Reply Latest reply on Sep 21, 2015 7:43 PM by AnSa_1225656

    Added CORS support to WICED http_server.c to make JSON testing easier

    AnSa_1225656

      I added the

          "Access-Control-Allow-Origin: *\r\n" // This line added to enable cross site scripting

      line in the top of the http_server.c in Library/deamons.  It allows me to build my web site as files on my PC and go against real JSON data from my device.  Thought it might be handy to others.  Let me know if there is a better approach to adding CORS support.

       

      <snip>

      static const char ok_header[] =

          "HTTP/1.0 200 OK\r\n"

          "Access-Control-Allow-Origin: *\r\n" // This line added to enable cross site scripting

          "Content-Type: ";

      </snip>

        • 1. Re: Added CORS support to WICED http_server.c to make JSON testing easier
          AnSa_1225656

          For 3.1.2

          ----In http_server.c----

              /* Content-Type: xx/yy\r\n */

              wiced_tcp_stream_write( stream, HTTP_HEADER_CONTENT_TYPE, strlen( HTTP_HEADER_CONTENT_TYPE ) );

              wiced_tcp_stream_write( stream, http_mime_array[mime_type], strlen( http_mime_array[mime_type] ) );

              wiced_tcp_stream_write( stream, CRLF, strlen( CRLF ) );

           

              // Add following two lines to allow cross site scripting

              wiced_tcp_stream_write( stream, HTTP_HEADER_CORS, strlen( HTTP_HEADER_CORS ) );

              wiced_tcp_stream_write( stream, CRLF, strlen( CRLF ) );

           

          ----In http_server.h----

          #define HTTP_HEADER_CONTENT_TYPE       "Content-Type: "

          // Add the following line

          #define HTTP_HEADER_CORS               "Access-Control-Allow-Origin: *"

          #define HTTP_HEADER_CHUNKED            "Transfer-Encoding: chunked"