[Libwebsockets] response headers

Andy Green andy at warmcat.com
Sat Sep 3 00:56:21 CEST 2016


On Fri, 2016-09-02 at 20:31 +0000, Srikar Vadlamani wrote:
> Hey,
>  
> How can I add “Access-Control-Allow-Origin” to an HTTP response
> header.

Depends what you're doing....

1) If you're using lwsws, update to master and you can list arbitrary
headers you want added to your responses for a vhost in the JSON
config, eg

  		"headers": [{
                        "Content-Security-Policy": "script-src 'self'",
                        "X-Content-Type-Options": "nosniff",
                        "X-XSS-Protection": "1; mode=block",
                        "X-Frame-Options": "SAMEORIGIN"
                 }]

2) If you are making your own HTTP response headers, use the api

/**
 * lws_add_http_header_by_name() - append named header and value
 *
 * \param wsi: the connection to check
 * \param name: the hdr name, like "my-header:"
 * \param value: the value after the = for this header
 * \param length: the length of the value
 * \param p: pointer to current position in buffer pointer
 * \param end: pointer to end of buffer
 *
 * Appends name: value to the headers
 */
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
lws_add_http_header_by_name(struct lws *wsi, const unsigned char *name,
			    const unsigned char *value, int length,
			    unsigned char **p, unsigned char *end);

to write the header into your buffer

-Andy


> Srikar
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> http://libwebsockets.org/mailman/listinfo/libwebsockets



More information about the Libwebsockets mailing list