diff --git a/README.md b/README.md index 6f919b795..390edf89b 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,8 @@ lightweight, configurable, scalable and flexible way. It's easy to build and cross-build via cmake and is suitable for tasks from embedded RTOS through mass cloud serving. -[50 minimal examples](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples) for various scenarios, CC0-licensed (public domain) for cut-and-paste, allow you to get started quickly. +[50 minimal examples](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples) for +various scenarios, CC0-licensed (public domain) for cut-and-paste, allow you to get started quickly. ![overview](./doc-assets/lws-overview.svg) @@ -19,38 +20,38 @@ News - **lws threadpool** - lightweight pool of pthreads integrated to lws wsi, with all synchronization to event loop handled internally, queue for excess tasks - [threadpool docs](https://libwebsockets.org/git/libwebsockets/tree/lib/misc/threadpool) - [threadpool minimal example](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/ws-server/minimal-ws-server-threadpool) + [threadpool docs](https://libwebsockets.org/git/libwebsockets/tree/lib/misc/threadpool), + [threadpool minimal example](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/ws-server/minimal-ws-server-threadpool), Cmake config: `-DLWS_WITH_THREADPOOL=1` - **libdbus support** integrated on lws event loop - [lws dbus docs](https://libwebsockets.org/git/libwebsockets/tree/lib/roles/dbus) - [lws dbus client minimal examples](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/dbus-client) - [lws dbus server minimal examples](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/dbus-server) + [lws dbus docs](https://libwebsockets.org/git/libwebsockets/tree/lib/roles/dbus), + [lws dbus client minimal examples](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/dbus-client), + [lws dbus server minimal examples](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/dbus-server), Cmake config: `-DLWS_ROLE_DBUS=1` - **lws allocated chunks (lwsac)** - helpers for optimized mass allocation of small objects inside a few larger malloc chunks... if you need to allocate a lot of inter-related structs for a limited time, this removes per-struct allocation library overhead completely and removes the need for any destruction handling - [lwsac docs](https://libwebsockets.org/git/libwebsockets/tree/lib/misc/lwsac) - [lwsac minimal example](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/api-tests/api-test-lwsac) + [lwsac docs](https://libwebsockets.org/git/libwebsockets/tree/lib/misc/lwsac), + [lwsac minimal example](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/api-tests/api-test-lwsac), Cmake Config: `-DLWS_WITH_LWSAC=1` - **lws tokenizer** - helper api for robustly tokenizing your own strings without allocating or adding complexity. Configurable by flags for common delimiter sets and comma-separated-lists in the tokenizer. Detects and reports syntax errors. - [lws_tokenize docs](https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-tokenize.h) + [lws_tokenize docs](https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-tokenize.h), [lws_tokenize minimal example / api test](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/api-tests/api-test-lws_tokenize) - **lws full-text search** - optimized trie generation, serialization, autocomplete suggestion generation and instant global search support extensible to huge corpuses of UTF-8 text while remaining super lightweight on resources. - [full-text search docs](https://libwebsockets.org/git/libwebsockets/tree/lib/misc/fts) - [full-text search minimal example / api test](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/api-tests/api-test-fts) - [demo](https://libwebsockets.org/ftsdemo/) - [demo sources](https://libwebsockets.org/git/libwebsockets/tree/plugins/protocol_fulltext_demo.c) + [full-text search docs](https://libwebsockets.org/git/libwebsockets/tree/lib/misc/fts), + [full-text search minimal example / api test](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/api-tests/api-test-fts), + [demo](https://libwebsockets.org/ftsdemo/), + [demo sources](https://libwebsockets.org/git/libwebsockets/tree/plugins/protocol_fulltext_demo.c), Cmake config: `-DLWS_WITH_FTS=1 -DLWS_WITH_LWSAC=1` - **gzip + brotli http server-side compression** - h1 and h2 detection of client support @@ -62,7 +63,7 @@ News - **managed disk cache** - API for managing a directory containing cached files with hashed names, and automatic deletion of LRU files once the cache is above a given limit. - [lws diskcache docs](https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-diskcache.h) + [lws diskcache docs](https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-diskcache.h), Cmake config: `-DLWS_WITH_DISKCACHE=1` - **http reverse proxy** - lws mounts support proxying h1 or h2 requests to @@ -70,11 +71,18 @@ News type architectures where parts of the common URL space are actually handled by external processes which may be remote or on the same machine. [lws gitohashi serving](https://libwebsockets.org/git/) is handled this way. - [unix domain sockets reverse proxy docs](https://libwebsockets.org/git/libwebsockets/tree/READMEs/README.unix-domain-reverse-proxy.md) - CMake config: `-DLWS_WITH_HTTP_PROXY=1` + [unix domain sockets reverse proxy docs](https://libwebsockets.org/git/libwebsockets/tree/READMEs/README.unix-domain-reverse-proxy.md), + CMake config: `-DLWS_WITH_HTTP_PROXY=1` and `-DLWS_UNIX_SOCK=1` for Unix Domain Sockets + + - **update minimal examples for strict Content Security Policy** the minimal + examples now show the best practices around Content Security Policy and + disabling inline Javascript. Updated examples that are served with the + recommended security restrictions show a new "Strict Content Security Policy" + graphic. [Read how to upgrade your applications to use a strict CSP](https://libwebsockets.org/git/libwebsockets/tree/READMEs/README.content-security-policy.md). - **release policy docs** - unsure what branch, version or tag to use, or how to follow master cleanly? [Read the release policy docs](https://libwebsockets.org/git/libwebsockets/tree/READMEs/README.release-policy.md) + which explain how and why lws is developed, released and maintained. ## v3.0.1 released diff --git a/READMEs/README.content-security-policy.md b/READMEs/README.content-security-policy.md index 4514a67d6..0fe0cc209 100644 --- a/READMEs/README.content-security-policy.md +++ b/READMEs/README.content-security-policy.md @@ -85,7 +85,8 @@ completely rejected by the browser. Inline `onclick()` etc are kinds of inline scripting and are banned. Modern browsers have offered a different system called ["EventListener" for -a while](https://developer.mozilla.org/en-US/docs/Web/API/EventListener) which allows binding of events to DOM elements in JS. +a while](https://developer.mozilla.org/en-US/docs/Web/API/EventListener) +which allows binding of events to DOM elements in JS. A bunch of different named events are possible to listen on, commonly the `.js` file will ask for one or both of diff --git a/READMEs/README.unix-domain-reverse-proxy.md b/READMEs/README.unix-domain-reverse-proxy.md index ef61968d3..bca4f7520 100644 --- a/READMEs/README.unix-domain-reverse-proxy.md +++ b/READMEs/README.unix-domain-reverse-proxy.md @@ -7,7 +7,9 @@ lws is able to use a mount to place reverse proxies into the URL space. These are particularly useful when using Unix Domain Sockets, basically files in the server filesystem, to communicate between lws and a separate server process and integrate the result into a coherent URL namespace on -the lws side. +the lws side. It's also possible to proxy using tcp sockets. + +![overview](../doc-assets/http-proxy-overview.svg) This has the advantage that the actual web server that forwards the data from the unix socket owner is in a different process than the server diff --git a/changelog b/changelog index e3ce5f2ce..42b8fd2c0 100644 --- a/changelog +++ b/changelog @@ -12,6 +12,11 @@ v3.1.0 - CHANGE: CMAKE: - LWS_WITH_HTTP2: now defaults ON + - CHANGE: Minimal examples updated to use Content Security Policy best + practices, using + `LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE` vhost + option flag and disabling of inline style and scripts. + - NEW: CMAKE - LWS_FOR_GITOHASHI: sets various cmake options suitable for gitohashi - LWS_WITH_ASAN: for Linux, enable build with ASAN diff --git a/doc-assets/http-proxy-overview.svg b/doc-assets/http-proxy-overview.svg new file mode 100644 index 000000000..fbfcf0cfc --- /dev/null +++ b/doc-assets/http-proxy-overview.svg @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + LWSvhost + listensocket + + unixsocket + localserverprocess + + + + + tcpsocket + remoteserverprocess + + tcpsocket + + + + + + + + + + + + + + + + + + + + + + + + + + h1/h2 + h1 proxy + + + + h1 proxy + chosenby URL + chosenby URL + lws http proxying overview + Same physical server + + + diff --git a/include/libwebsockets/lws-context-vhost.h b/include/libwebsockets/lws-context-vhost.h index 10627a2cb..c6ab222a2 100644 --- a/include/libwebsockets/lws-context-vhost.h +++ b/include/libwebsockets/lws-context-vhost.h @@ -145,6 +145,20 @@ enum lws_context_options { * allow lax hostname mappings like localhost / 127.0.0.1, and CNAME * mappings like www.mysite.com / mysite.com */ + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE = (1 << 28), + /**< (VH) Send lws default HTTP headers recommended by Mozilla Observatory + * for security. This is a helper option that sends canned headers on each + * http response enabling a VERY strict Content Security Policy. The policy + * is so strict, for example it won't let the page run its own inline JS nor + * show images or take CSS from a different server. In many cases your JS only + * comes from your server as do the image sources and CSS, so that is what you + * want... attackers hoping to inject JS into your DOM are completely out of + * luck since even if they succeed, it will be rejected for execution by the + * browser according to the strict CSP. In other cases you have to deviate from + * the complete strictness, in which case don't use this flag: use the .headers + * member in the vhost init described in struct lws_context_creation_info + * instead to send the adapted headers yourself. + */ /****** add new things just above ---^ ******/ }; diff --git a/include/libwebsockets/lws-http.h b/include/libwebsockets/lws-http.h index 97a2c712c..9319ac98f 100644 --- a/include/libwebsockets/lws-http.h +++ b/include/libwebsockets/lws-http.h @@ -21,6 +21,9 @@ * included from libwebsockets.h */ +/* minimal space for typical headers and CSP stuff */ + +#define LWS_RECOMMENDED_MIN_HEADER_SPACE 2048 /*! \defgroup http HTTP diff --git a/lib/roles/h2/ops-h2.c b/lib/roles/h2/ops-h2.c index 76d5a62b7..ea3f69d45 100644 --- a/lib/roles/h2/ops-h2.c +++ b/lib/roles/h2/ops-h2.c @@ -739,11 +739,10 @@ rops_callback_on_writable_h2(struct lws *wsi) /* for network action, act only on the network wsi */ - wsi = network_wsi; if (already #if !defined(LWS_NO_CLIENT) - && !wsi->client_h2_alpn - && !wsi->client_h2_substream + && !network_wsi->client_h2_alpn + && !network_wsi->client_h2_substream #endif ) return 1; diff --git a/lib/roles/http/header.c b/lib/roles/http/header.c index 0a7d92e04..2fbed12ce 100644 --- a/lib/roles/http/header.c +++ b/lib/roles/http/header.c @@ -242,6 +242,26 @@ static const char * const err500[] = { "HTTP Version Not Supported" }; +/* security best practices from Mozilla Observatory */ + +static const +struct lws_protocol_vhost_options pvo_hsbph[] = {{ + NULL, NULL, "referrer-policy:", "no-referrer" +}, { + &pvo_hsbph[0], NULL, "x-frame-options:", "deny" +}, { + &pvo_hsbph[1], NULL, "x-xss-protection:", "1; mode=block" +}, { + &pvo_hsbph[2], NULL, "x-content-type-options:", "nosniff" +}, { + &pvo_hsbph[3], NULL, "content-security-policy:", + "default-src 'none'; img-src 'self' data: ; " + "script-src 'self'; font-src 'self'; " + "style-src 'self'; connect-src 'self'; " + "frame-ancestors 'none'; base-uri 'none';" + "form-action 'self';" +}}; + int lws_add_http_header_status(struct lws *wsi, unsigned int _code, unsigned char **p, unsigned char *end) @@ -306,6 +326,20 @@ lws_add_http_header_status(struct lws *wsi, unsigned int _code, headers = headers->next; } + if (wsi->vhost->options & + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE) { + headers = &pvo_hsbph[LWS_ARRAY_SIZE(pvo_hsbph) - 1]; + while (headers) { + if (lws_add_http_header_by_name(wsi, + (const unsigned char *)headers->name, + (unsigned char *)headers->value, + (int)strlen(headers->value), p, end)) + return 1; + + headers = headers->next; + } + } + if (wsi->context->server_string && !(_code & LWSAHH_FLAG_NO_SERVER_NAME)) if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_SERVER, diff --git a/minimal-examples/client-server/minimal-ws-proxy/minimal-ws-proxy.c b/minimal-examples/client-server/minimal-ws-proxy/minimal-ws-proxy.c index 6c9eaab85..f7c25fc38 100644 --- a/minimal-examples/client-server/minimal-ws-proxy/minimal-ws-proxy.c +++ b/minimal-examples/client-server/minimal-ws-proxy/minimal-ws-proxy.c @@ -78,7 +78,8 @@ int main(int argc, const char **argv) lwsl_user("LWS minimal ws proxy | visit http://localhost:7681\n"); memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ - info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT | + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; info.port = 7681; info.mounts = &mount; info.protocols = protocols; diff --git a/minimal-examples/client-server/minimal-ws-proxy/mount-origin/example.js b/minimal-examples/client-server/minimal-ws-proxy/mount-origin/example.js new file mode 100644 index 000000000..a25a3cd44 --- /dev/null +++ b/minimal-examples/client-server/minimal-ws-proxy/mount-origin/example.js @@ -0,0 +1,70 @@ +var head = 0, tail = 0, ring = new Array(); + +function get_appropriate_ws_url(extra_url) +{ + var pcol; + var u = document.URL; + + /* + * We open the websocket encrypted if this page came on an + * https:// url itself, otherwise unencrypted + */ + + if (u.substring(0, 5) === "https") { + pcol = "wss://"; + u = u.substr(8); + } else { + pcol = "ws://"; + if (u.substring(0, 4) === "http") + u = u.substr(7); + } + + u = u.split("/"); + + /* + "/xxx" bit is for IE10 workaround */ + + return pcol + u[0] + "/" + extra_url; +} + +function new_ws(urlpath, protocol) +{ + if (typeof MozWebSocket != "undefined") + return new MozWebSocket(urlpath, protocol); + + return new WebSocket(urlpath, protocol); +} + +document.addEventListener("DOMContentLoaded", function() { + + ws = new_ws(get_appropriate_ws_url(""), "lws-minimal-proxy"); + try { + ws.onopen = function() { + document.getElementById("r").disabled = 0; + }; + + ws.onmessage =function got_packet(msg) { + var n, s = ""; + + ring[head] = msg.data + "\n"; + head = (head + 1) % 20; + if (tail === head) + tail = (tail + 1) % 20; + + n = tail; + do { + s = s + ring[n]; + n = (n + 1) % 20; + } while (n !== head); + + document.getElementById("r").value = s; + document.getElementById("r").scrollTop = + document.getElementById("r").scrollHeight; + }; + + ws.onclose = function(){ + document.getElementById("r").disabled = 1; + }; + } catch(exception) { + alert("

Error " + exception); + } +}, false); diff --git a/minimal-examples/client-server/minimal-ws-proxy/mount-origin/index.html b/minimal-examples/client-server/minimal-ws-proxy/mount-origin/index.html index 0a312d88c..9df7cf8c8 100644 --- a/minimal-examples/client-server/minimal-ws-proxy/mount-origin/index.html +++ b/minimal-examples/client-server/minimal-ws-proxy/mount-origin/index.html @@ -1,7 +1,11 @@ - + + + + -
+ +
Minimal ws server proxy example.
The server makes a dumb-increment-protocol wss connection
@@ -12,80 +16,4 @@

- - - - diff --git a/minimal-examples/client-server/minimal-ws-proxy/mount-origin/libwebsockets.org-logo.png b/minimal-examples/client-server/minimal-ws-proxy/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/client-server/minimal-ws-proxy/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/client-server/minimal-ws-proxy/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/client-server/minimal-ws-proxy/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/client-server/minimal-ws-proxy/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/client-server/minimal-ws-proxy/mount-origin/strict-csp.svg b/minimal-examples/client-server/minimal-ws-proxy/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/client-server/minimal-ws-proxy/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/dbus-client/minimal-dbus-ws-proxy-testclient/minimal-dbus-ws-proxy-testclient.c b/minimal-examples/dbus-client/minimal-dbus-ws-proxy-testclient/minimal-dbus-ws-proxy-testclient.c index 8e688f403..051bae717 100644 --- a/minimal-examples/dbus-client/minimal-dbus-ws-proxy-testclient/minimal-dbus-ws-proxy-testclient.c +++ b/minimal-examples/dbus-client/minimal-dbus-ws-proxy-testclient/minimal-dbus-ws-proxy-testclient.c @@ -411,6 +411,9 @@ int main(int argc, const char **argv) return 1; } + info.options |= + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; + vh = lws_create_vhost(context, &info); if (!vh) goto bail; diff --git a/minimal-examples/dbus-server/minimal-dbus-server/main.c b/minimal-examples/dbus-server/minimal-dbus-server/main.c index 863439c42..911989626 100644 --- a/minimal-examples/dbus-server/minimal-dbus-server/main.c +++ b/minimal-examples/dbus-server/minimal-dbus-server/main.c @@ -482,6 +482,9 @@ int main(int argc, const char **argv) return 1; } + info.options |= + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; + dbus_ctx.tsi = 0; ctx_listener.tsi = 0; ctx_listener.vh = dbus_ctx.vh = lws_create_vhost(context, &info); diff --git a/minimal-examples/dbus-server/minimal-dbus-ws-proxy/main.c b/minimal-examples/dbus-server/minimal-dbus-ws-proxy/main.c index 4510fd80a..2310c8229 100644 --- a/minimal-examples/dbus-server/minimal-dbus-ws-proxy/main.c +++ b/minimal-examples/dbus-server/minimal-dbus-ws-proxy/main.c @@ -76,7 +76,8 @@ int main(int argc, const char **argv) lwsl_user("LWS DBUS ws client proxy\n"); memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ - info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT | + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; info.port = CONTEXT_PORT_NO_LISTEN; info.ws_ping_pong_interval = 30; info.protocols = protocols; diff --git a/minimal-examples/http-server/minimal-http-server-basicauth/minimal-http-server-basicauth.c b/minimal-examples/http-server/minimal-http-server-basicauth/minimal-http-server-basicauth.c index 843a48b6f..f6cfefbc3 100644 --- a/minimal-examples/http-server/minimal-http-server-basicauth/minimal-http-server-basicauth.c +++ b/minimal-examples/http-server/minimal-http-server-basicauth/minimal-http-server-basicauth.c @@ -95,6 +95,8 @@ int main(int argc, const char **argv) memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ info.port = 7681; info.mounts = &mount; + info.options = + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; context = lws_create_context(&info); if (!context) { diff --git a/minimal-examples/http-server/minimal-http-server-basicauth/mount-origin/404.html b/minimal-examples/http-server/minimal-http-server-basicauth/mount-origin/404.html index 1f7ae66e8..3e5a14b9f 100644 --- a/minimal-examples/http-server/minimal-http-server-basicauth/mount-origin/404.html +++ b/minimal-examples/http-server/minimal-http-server-basicauth/mount-origin/404.html @@ -1,7 +1,7 @@ -
+

404

Sorry, that file doesn't exist. diff --git a/minimal-examples/http-server/minimal-http-server-basicauth/mount-origin/index.html b/minimal-examples/http-server/minimal-http-server-basicauth/mount-origin/index.html index 5813719e8..0b353686d 100644 --- a/minimal-examples/http-server/minimal-http-server-basicauth/mount-origin/index.html +++ b/minimal-examples/http-server/minimal-http-server-basicauth/mount-origin/index.html @@ -1,7 +1,10 @@ - + + + -
+ +
Hello from the minimal http server basic auth example.

diff --git a/minimal-examples/http-server/minimal-http-server-basicauth/mount-origin/libwebsockets.org-logo.png b/minimal-examples/http-server/minimal-http-server-basicauth/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-basicauth/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-basicauth/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/http-server/minimal-http-server-basicauth/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-basicauth/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-basicauth/mount-origin/strict-csp.svg b/minimal-examples/http-server/minimal-http-server-basicauth/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-basicauth/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-basicauth/mount-secret-origin/index.html b/minimal-examples/http-server/minimal-http-server-basicauth/mount-secret-origin/index.html index ba2d3e6e8..a0bb44167 100644 --- a/minimal-examples/http-server/minimal-http-server-basicauth/mount-secret-origin/index.html +++ b/minimal-examples/http-server/minimal-http-server-basicauth/mount-secret-origin/index.html @@ -1,7 +1,9 @@ - + + + -
+
This is the big secret protected by basic auth. diff --git a/minimal-examples/http-server/minimal-http-server-basicauth/mount-secret-origin/libwebsockets.org-logo.png b/minimal-examples/http-server/minimal-http-server-basicauth/mount-secret-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-basicauth/mount-secret-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-basicauth/mount-secret-origin/libwebsockets.org-logo.svg b/minimal-examples/http-server/minimal-http-server-basicauth/mount-secret-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-basicauth/mount-secret-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c b/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c index ee12ccd2a..eda6d5b35 100644 --- a/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c +++ b/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c @@ -127,10 +127,13 @@ callback_dynamic_http(struct lws *wsi, enum lws_callback_reasons reason, * valid behind the buffer we will send. */ p += lws_snprintf((char *)p, end - p, "" - "" + "" + "" "
Dynamic content for '%s' from mountpoint." "
Time: %s

" - "", pss->path, ctime(&t)); + "", pss->path, ctime(&t)); } else { /* * after the first time, we create bulk content. @@ -249,7 +252,8 @@ int main(int argc, const char **argv) memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT | - LWS_SERVER_OPTION_EXPLICIT_VHOSTS; + LWS_SERVER_OPTION_EXPLICIT_VHOSTS | + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; /* for testing ah queue, not useful in real world */ if (lws_cmdline_option(argc, argv, "--ah1")) diff --git a/minimal-examples/http-server/minimal-http-server-dynamic/mount-origin/404.html b/minimal-examples/http-server/minimal-http-server-dynamic/mount-origin/404.html index 1f7ae66e8..3e5a14b9f 100644 --- a/minimal-examples/http-server/minimal-http-server-dynamic/mount-origin/404.html +++ b/minimal-examples/http-server/minimal-http-server-dynamic/mount-origin/404.html @@ -1,7 +1,7 @@ -
+

404

Sorry, that file doesn't exist. diff --git a/minimal-examples/http-server/minimal-http-server-dynamic/mount-origin/index.html b/minimal-examples/http-server/minimal-http-server-dynamic/mount-origin/index.html index f05216bc7..8fe93d772 100644 --- a/minimal-examples/http-server/minimal-http-server-dynamic/mount-origin/index.html +++ b/minimal-examples/http-server/minimal-http-server-dynamic/mount-origin/index.html @@ -1,8 +1,11 @@ - + + + -
- + +
+ Hello from the minimal http server dynamic content example.

This is a static page served from ./mount-origin/index.html. diff --git a/minimal-examples/http-server/minimal-http-server-dynamic/mount-origin/libwebsockets.org-logo.png b/minimal-examples/http-server/minimal-http-server-dynamic/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-dynamic/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-dynamic/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/http-server/minimal-http-server-dynamic/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-dynamic/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-dynamic/mount-origin/strict-csp.svg b/minimal-examples/http-server/minimal-http-server-dynamic/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-dynamic/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-eventlib-demos/minimal-http-server-eventlib-demos.c b/minimal-examples/http-server/minimal-http-server-eventlib-demos/minimal-http-server-eventlib-demos.c index f624fa519..7ebe0ced1 100644 --- a/minimal-examples/http-server/minimal-http-server-eventlib-demos/minimal-http-server-eventlib-demos.c +++ b/minimal-examples/http-server/minimal-http-server-eventlib-demos/minimal-http-server-eventlib-demos.c @@ -152,6 +152,8 @@ int main(int argc, const char **argv) info.pcontext = &context; info.protocols = protocols; info.signal_cb = signal_cb; + info.options = + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; if (lws_cmdline_option(argc, argv, "-s")) { info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; diff --git a/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/404.html b/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/404.html index 1f7ae66e8..3e5a14b9f 100644 --- a/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/404.html +++ b/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/404.html @@ -1,7 +1,7 @@ -
+

404

Sorry, that file doesn't exist. diff --git a/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/libwebsockets.org-logo.png b/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/strict-csp.svg b/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/test.html b/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/test.html index 73aed25e0..047bcc8c6 100644 --- a/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/test.html +++ b/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/test.html @@ -14,11 +14,14 @@
- +
+ + diff --git a/minimal-examples/http-server/minimal-http-server-eventlib-foreign/minimal-http-server-eventlib-foreign.c b/minimal-examples/http-server/minimal-http-server-eventlib-foreign/minimal-http-server-eventlib-foreign.c index f31b7bd28..5d7ab90b3 100644 --- a/minimal-examples/http-server/minimal-http-server-eventlib-foreign/minimal-http-server-eventlib-foreign.c +++ b/minimal-examples/http-server/minimal-http-server-eventlib-foreign/minimal-http-server-eventlib-foreign.c @@ -351,6 +351,8 @@ int main(int argc, const char **argv) info.mounts = &mount; info.error_document_404 = "/404.html"; info.pcontext = &context; + info.options = + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; if (lws_cmdline_option(argc, argv, "-s")) { info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; diff --git a/minimal-examples/http-server/minimal-http-server-eventlib-foreign/mount-origin/404.html b/minimal-examples/http-server/minimal-http-server-eventlib-foreign/mount-origin/404.html index 1f7ae66e8..3e5a14b9f 100644 --- a/minimal-examples/http-server/minimal-http-server-eventlib-foreign/mount-origin/404.html +++ b/minimal-examples/http-server/minimal-http-server-eventlib-foreign/mount-origin/404.html @@ -1,7 +1,7 @@ -
+

404

Sorry, that file doesn't exist. diff --git a/minimal-examples/http-server/minimal-http-server-eventlib-foreign/mount-origin/index.html b/minimal-examples/http-server/minimal-http-server-eventlib-foreign/mount-origin/index.html index 3ec21dffb..bee267a97 100644 --- a/minimal-examples/http-server/minimal-http-server-eventlib-foreign/mount-origin/index.html +++ b/minimal-examples/http-server/minimal-http-server-eventlib-foreign/mount-origin/index.html @@ -1,7 +1,10 @@ - + + + -
+ +
Hello from the minimal http server eventlib foreign loop example.
diff --git a/minimal-examples/http-server/minimal-http-server-eventlib-foreign/mount-origin/libwebsockets.org-logo.png b/minimal-examples/http-server/minimal-http-server-eventlib-foreign/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-eventlib-foreign/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-eventlib-foreign/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/http-server/minimal-http-server-eventlib-foreign/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-eventlib-foreign/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-eventlib-foreign/mount-origin/strict-csp.svg b/minimal-examples/http-server/minimal-http-server-eventlib-foreign/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-eventlib-foreign/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-eventlib/minimal-http-server-eventlib.c b/minimal-examples/http-server/minimal-http-server-eventlib/minimal-http-server-eventlib.c index 4b9d3c996..e28a5a88c 100644 --- a/minimal-examples/http-server/minimal-http-server-eventlib/minimal-http-server-eventlib.c +++ b/minimal-examples/http-server/minimal-http-server-eventlib/minimal-http-server-eventlib.c @@ -83,6 +83,8 @@ int main(int argc, const char **argv) info.error_document_404 = "/404.html"; info.pcontext = &context; info.signal_cb = signal_cb; + info.options = + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; if (lws_cmdline_option(argc, argv, "-s")) { info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; diff --git a/minimal-examples/http-server/minimal-http-server-eventlib/mount-origin/404.html b/minimal-examples/http-server/minimal-http-server-eventlib/mount-origin/404.html index 1f7ae66e8..3e5a14b9f 100644 --- a/minimal-examples/http-server/minimal-http-server-eventlib/mount-origin/404.html +++ b/minimal-examples/http-server/minimal-http-server-eventlib/mount-origin/404.html @@ -1,7 +1,7 @@ -
+

404

Sorry, that file doesn't exist. diff --git a/minimal-examples/http-server/minimal-http-server-eventlib/mount-origin/index.html b/minimal-examples/http-server/minimal-http-server-eventlib/mount-origin/index.html index d9e27c293..8da5b6619 100644 --- a/minimal-examples/http-server/minimal-http-server-eventlib/mount-origin/index.html +++ b/minimal-examples/http-server/minimal-http-server-eventlib/mount-origin/index.html @@ -1,9 +1,12 @@ - + + + -
+ +
- Hello from the minimal http server libuv example. + Hello from the minimal http server event loop example.
You can confirm the 404 page handler by going to this nonexistant page. diff --git a/minimal-examples/http-server/minimal-http-server-eventlib/mount-origin/libwebsockets.org-logo.png b/minimal-examples/http-server/minimal-http-server-eventlib/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-eventlib/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-eventlib/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/http-server/minimal-http-server-eventlib/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-eventlib/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-eventlib/mount-origin/strict-csp.svg b/minimal-examples/http-server/minimal-http-server-eventlib/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-eventlib/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-form-get/minimal-http-server-form-get.c b/minimal-examples/http-server/minimal-http-server-form-get/minimal-http-server-form-get.c index ae2380ce9..1f114c67a 100644 --- a/minimal-examples/http-server/minimal-http-server-form-get/minimal-http-server-form-get.c +++ b/minimal-examples/http-server/minimal-http-server-form-get/minimal-http-server-form-get.c @@ -26,7 +26,8 @@ static int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len) { - uint8_t buf[LWS_PRE + 256], *start = &buf[LWS_PRE], *p = start, + uint8_t buf[LWS_PRE + LWS_RECOMMENDED_MIN_HEADER_SPACE], + *start = &buf[LWS_PRE], *p = start, *end = &buf[sizeof(buf) - 1]; const char *val; int n; @@ -37,6 +38,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, if (!lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI)) /* not a GET */ break; + lwsl_err("%s: %s\n", __func__, (const char *)in); if (strcmp((const char *)in, "/form1")) /* not our form URL */ break; @@ -128,6 +130,8 @@ int main(int argc, const char **argv) info.port = 7681; info.protocols = protocols; info.mounts = &mount; + info.options = + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; context = lws_create_context(&info); if (!context) { diff --git a/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/404.html b/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/404.html index 9ad5a3344..6f85f256f 100644 --- a/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/404.html +++ b/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/404.html @@ -1,7 +1,7 @@ -
+

404

Sorry, that file doesn't exist. diff --git a/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/after-form1.html b/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/after-form1.html index 6009273a7..938ccb706 100644 --- a/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/after-form1.html +++ b/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/after-form1.html @@ -1,7 +1,10 @@ - + + + -
+ +
Thanks for posting the form. diff --git a/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/index.html b/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/index.html index c74a95354..147ce5f91 100644 --- a/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/index.html +++ b/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/index.html @@ -1,7 +1,10 @@ - + + + -
+ +
Hello from the minimal http form GET example.

diff --git a/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/libwebsockets.org-logo.png b/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/strict-csp.svg b/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-form-post-file/minimal-http-server-form-post-file.c b/minimal-examples/http-server/minimal-http-server-form-post-file/minimal-http-server-form-post-file.c index f0a0b9c22..9c500edae 100644 --- a/minimal-examples/http-server/minimal-http-server-form-post-file/minimal-http-server-form-post-file.c +++ b/minimal-examples/http-server/minimal-http-server-form-post-file/minimal-http-server-form-post-file.c @@ -97,8 +97,8 @@ static int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len) { - uint8_t buf[LWS_PRE + 256], *start = &buf[LWS_PRE], *p = start, - *end = &buf[sizeof(buf) - 1]; + uint8_t buf[LWS_PRE + LWS_RECOMMENDED_MIN_HEADER_SPACE], *start = &buf[LWS_PRE], + *p = start, *end = &buf[sizeof(buf) - 1]; struct pss *pss = (struct pss *)user; int n; @@ -240,6 +240,8 @@ int main(int argc, const char **argv) info.port = 7681; info.protocols = protocols; info.mounts = &mount; + info.options = + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; context = lws_create_context(&info); if (!context) { diff --git a/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/404.html b/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/404.html index 9ad5a3344..6f85f256f 100644 --- a/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/404.html +++ b/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/404.html @@ -1,7 +1,7 @@ -
+

404

Sorry, that file doesn't exist. diff --git a/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/after-form1.html b/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/after-form1.html index 066f63ac5..b01062e20 100644 --- a/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/after-form1.html +++ b/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/after-form1.html @@ -1,7 +1,10 @@ - + + + -
+ +
Thanks for posting the form.

diff --git a/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/index.html b/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/index.html index 9676a0ff3..06ffd240d 100644 --- a/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/index.html +++ b/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/index.html @@ -1,7 +1,10 @@ - + + + -
+ +
Hello from the minimal http form POST file example.

diff --git a/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/libwebsockets.org-logo.png b/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/strict-csp.svg b/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-form-post/minimal-http-server-form-post.c b/minimal-examples/http-server/minimal-http-server-form-post/minimal-http-server-form-post.c index d6cfc6b78..e7340d63a 100644 --- a/minimal-examples/http-server/minimal-http-server-form-post/minimal-http-server-form-post.c +++ b/minimal-examples/http-server/minimal-http-server-form-post/minimal-http-server-form-post.c @@ -41,8 +41,8 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len) { struct pss *pss = (struct pss *)user; - uint8_t buf[LWS_PRE + 256], *start = &buf[LWS_PRE], *p = start, - *end = &buf[sizeof(buf) - 1]; + uint8_t buf[LWS_PRE + LWS_RECOMMENDED_MIN_HEADER_SPACE], *start = &buf[LWS_PRE], + *p = start, *end = &buf[sizeof(buf) - 1]; int n; switch (reason) { @@ -182,6 +182,8 @@ int main(int argc, const char **argv) info.port = 7681; info.protocols = protocols; info.mounts = &mount; + info.options = + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; context = lws_create_context(&info); if (!context) { diff --git a/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/404.html b/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/404.html index 9ad5a3344..6f85f256f 100644 --- a/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/404.html +++ b/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/404.html @@ -1,7 +1,7 @@ -
+

404

Sorry, that file doesn't exist. diff --git a/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/after-form1.html b/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/after-form1.html index 6009273a7..938ccb706 100644 --- a/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/after-form1.html +++ b/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/after-form1.html @@ -1,7 +1,10 @@ - + + + -
+ +
Thanks for posting the form. diff --git a/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/index.html b/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/index.html index 1897db2e8..12ab4f4fd 100644 --- a/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/index.html +++ b/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/index.html @@ -1,7 +1,10 @@ - + + + -
+ +
Hello from the minimal http POST example.

diff --git a/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/libwebsockets.org-logo.png b/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/strict-csp.svg b/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-fulltext-search/minimal-http-server.c b/minimal-examples/http-server/minimal-http-server-fulltext-search/minimal-http-server.c index 76b35153a..c1582b979 100644 --- a/minimal-examples/http-server/minimal-http-server-fulltext-search/minimal-http-server.c +++ b/minimal-examples/http-server/minimal-http-server-fulltext-search/minimal-http-server.c @@ -106,6 +106,8 @@ int main(int argc, const char **argv) info.mounts = &mount; info.protocols = protocols; info.pvo = &pvo; + info.options = + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; pvo_idx.value = index_filepath; diff --git a/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/404.html b/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/404.html index 1f7ae66e8..3e5a14b9f 100644 --- a/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/404.html +++ b/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/404.html @@ -1,7 +1,7 @@ -
+

404

Sorry, that file doesn't exist. diff --git a/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/index.html b/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/index.html index 4e17414b7..d1f7d257c 100644 --- a/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/index.html +++ b/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/index.html @@ -8,7 +8,8 @@ -
+ +
The Picture of Dorian Gray
diff --git a/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/libwebsockets.org-logo.png b/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/strict-csp.svg b/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-mimetypes/minimal-http-server-mimetypes.c b/minimal-examples/http-server/minimal-http-server-mimetypes/minimal-http-server-mimetypes.c index e97a5661a..b64726f4c 100644 --- a/minimal-examples/http-server/minimal-http-server-mimetypes/minimal-http-server-mimetypes.c +++ b/minimal-examples/http-server/minimal-http-server-mimetypes/minimal-http-server-mimetypes.c @@ -76,6 +76,8 @@ int main(int argc, const char **argv) info.port = 7681; info.mounts = &mount; info.error_document_404 = "/404.html"; + info.options = + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; context = lws_create_context(&info); if (!context) { diff --git a/minimal-examples/http-server/minimal-http-server-mimetypes/mount-origin/404.html b/minimal-examples/http-server/minimal-http-server-mimetypes/mount-origin/404.html index 1f7ae66e8..3e5a14b9f 100644 --- a/minimal-examples/http-server/minimal-http-server-mimetypes/mount-origin/404.html +++ b/minimal-examples/http-server/minimal-http-server-mimetypes/mount-origin/404.html @@ -1,7 +1,7 @@ -
+

404

Sorry, that file doesn't exist. diff --git a/minimal-examples/http-server/minimal-http-server-mimetypes/mount-origin/index.html b/minimal-examples/http-server/minimal-http-server-mimetypes/mount-origin/index.html index 8201c5fa0..5c60e8849 100644 --- a/minimal-examples/http-server/minimal-http-server-mimetypes/mount-origin/index.html +++ b/minimal-examples/http-server/minimal-http-server-mimetypes/mount-origin/index.html @@ -1,8 +1,12 @@ - + + + + -
- + +
+ Hello from the minimal http server + mimetypes example.
This shows how to teach a mount new bindings between file
diff --git a/minimal-examples/http-server/minimal-http-server-mimetypes/mount-origin/libwebsockets.org-logo.png b/minimal-examples/http-server/minimal-http-server-mimetypes/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-mimetypes/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-mimetypes/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/http-server/minimal-http-server-mimetypes/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-mimetypes/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-mimetypes/mount-origin/strict-csp.svg b/minimal-examples/http-server/minimal-http-server-mimetypes/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-mimetypes/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-multivhost/minimal-http-server.c b/minimal-examples/http-server/minimal-http-server-multivhost/minimal-http-server.c index 966616fde..7349eab12 100644 --- a/minimal-examples/http-server/minimal-http-server-multivhost/minimal-http-server.c +++ b/minimal-examples/http-server/minimal-http-server-multivhost/minimal-http-server.c @@ -107,7 +107,8 @@ int main(int argc, const char **argv) signal(SIGINT, sigint_handler); memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ - info.options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS; + info.options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS | + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; /* * Because of LWS_SERVER_OPTION_EXPLICIT_VHOSTS, this only creates diff --git a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost1/404.html b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost1/404.html index ab9486582..8f6628711 100644 --- a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost1/404.html +++ b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost1/404.html @@ -1,7 +1,7 @@ -
+

404 (vhost localhost1)

Sorry, that file doesn't exist. diff --git a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost1/index.html b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost1/index.html index df01441e5..042a0b9b7 100644 --- a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost1/index.html +++ b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost1/index.html @@ -1,8 +1,12 @@ - - + + + + -
- + +
+ + Hello from the minimal http server multivhost example.

This was served from ./mount-origin-localhost1/index.html
diff --git a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost1/libwebsockets.org-logo.png b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost1/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost1/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost1/libwebsockets.org-logo.svg b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost1/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost1/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost1/strict-csp.svg b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost1/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost1/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost2/404.html b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost2/404.html index 1591faf5a..3f1a438c6 100644 --- a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost2/404.html +++ b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost2/404.html @@ -1,7 +1,7 @@ -
+

404 (vhost localhost2)

Sorry, that file doesn't exist. diff --git a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost2/index.html b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost2/index.html index 33caf445c..2a12308a4 100644 --- a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost2/index.html +++ b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost2/index.html @@ -1,8 +1,11 @@ - + + + -
- + +
+ Hello from the minimal http server multivhost example.

This was served from ./mount-origin-localhost2/index.html
diff --git a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost2/libwebsockets.org-logo.png b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost2/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost2/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost2/libwebsockets.org-logo.svg b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost2/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost2/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost2/strict-csp.svg b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost2/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost2/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost3/404.html b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost3/404.html index 0c054569c..c891f79bf 100644 --- a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost3/404.html +++ b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost3/404.html @@ -1,7 +1,7 @@ -
+

404 (vhost localhost3)

Sorry, that file doesn't exist. diff --git a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost3/index.html b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost3/index.html index 85ca5027e..a38b75c8d 100644 --- a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost3/index.html +++ b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost3/index.html @@ -1,8 +1,11 @@ - + + + -
- + +
+ Hello from the minimal http server multivhost example.

This was served from ./mount-origin-localhost3/index.html
diff --git a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost3/libwebsockets.org-logo.png b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost3/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost3/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost3/libwebsockets.org-logo.svg b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost3/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost3/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost3/strict-csp.svg b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost3/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost3/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c b/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c index 6df28f9cc..7b687ad96 100644 --- a/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c +++ b/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c @@ -89,6 +89,8 @@ int main(int argc, const char **argv) memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ info.port = 7681; info.mounts = &mount; + info.options = + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; if ((p = lws_cmdline_option(argc, argv, "-t"))) info.count_threads = atoi(p); else diff --git a/minimal-examples/http-server/minimal-http-server-smp/mount-origin/index.html b/minimal-examples/http-server/minimal-http-server-smp/mount-origin/index.html index 004e31d16..e67792635 100644 --- a/minimal-examples/http-server/minimal-http-server-smp/mount-origin/index.html +++ b/minimal-examples/http-server/minimal-http-server-smp/mount-origin/index.html @@ -1,8 +1,11 @@ - + + + -
- + +
+ Hello from the minimal http server SMP example. diff --git a/minimal-examples/http-server/minimal-http-server-smp/mount-origin/libwebsockets.org-logo.png b/minimal-examples/http-server/minimal-http-server-smp/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-smp/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-smp/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/http-server/minimal-http-server-smp/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-smp/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-smp/mount-origin/strict-csp.svg b/minimal-examples/http-server/minimal-http-server-smp/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-smp/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-sse-ring/minimal-http-server-sse-ring.c b/minimal-examples/http-server/minimal-http-server-sse-ring/minimal-http-server-sse-ring.c index 616300c6b..7bccb990e 100644 --- a/minimal-examples/http-server/minimal-http-server-sse-ring/minimal-http-server-sse-ring.c +++ b/minimal-examples/http-server/minimal-http-server-sse-ring/minimal-http-server-sse-ring.c @@ -138,7 +138,8 @@ callback_sse(struct lws *wsi, enum lws_callback_reasons reason, void *user, struct pss *pss = (struct pss *)user; struct vhd *vhd = (struct vhd *)lws_protocol_vh_priv_get( lws_get_vhost(wsi), lws_get_protocol(wsi)); - uint8_t buf[LWS_PRE + 256], *start = &buf[LWS_PRE], *p = start, + uint8_t buf[LWS_PRE + LWS_RECOMMENDED_MIN_HEADER_SPACE], + *start = &buf[LWS_PRE], *p = start, *end = &buf[sizeof(buf) - 1]; const struct msg *pmsg; void *retval; @@ -266,6 +267,8 @@ callback_sse(struct lws *wsi, enum lws_callback_reasons reason, void *user, return 0; case LWS_CALLBACK_EVENT_WAIT_CANCELLED: + if (!vhd) + break; /* * let everybody know we want to write something on them * as soon as they are ready @@ -362,6 +365,8 @@ int main(int argc, const char **argv) info.port = 7681; info.protocols = protocols; info.mounts = &mount; + info.options = + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; context = lws_create_context(&info); if (!context) { diff --git a/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/404.html b/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/404.html index 1f7ae66e8..3e5a14b9f 100644 --- a/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/404.html +++ b/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/404.html @@ -1,7 +1,7 @@ -
+

404

Sorry, that file doesn't exist. diff --git a/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/example.js b/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/example.js new file mode 100644 index 000000000..b32bf0bfb --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/example.js @@ -0,0 +1,38 @@ +document.addEventListener("DOMContentLoaded", function() { + + var head = 0, tail = 0, ring = new Array(); + + es = new EventSource("/sse/sourcename"); + try { + es.onopen = function() { + // console.log("EventSource opened"); + document.getElementById("r").disabled = 0; + }; + + es.onmessage = function got_packet(msg) { + var n, s = ""; + + // console.log(msg.data); + ring[head] = msg.data + "\n"; + head = (head + 1) % 50; + if (tail === head) + tail = (tail + 1) % 50; + + n = tail; + do { + s = s + ring[n]; + n = (n + 1) % 50; + } while (n !== head); + + document.getElementById("r").value = s; + document.getElementById("r").scrollTop = + document.getElementById("r").scrollHeight; + }; + + /* there is no onclose() for EventSource */ + + } catch(exception) { + alert("

Error " + exception); + } + +}, false); diff --git a/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/index.html b/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/index.html index 3a7318a5a..576c9eb1f 100644 --- a/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/index.html +++ b/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/index.html @@ -1,8 +1,12 @@ - + + + + -
- + +
+ Hello from the minimal http Server Side Events + Ring example.

This is a static page served from ./mount-origin/index.html. @@ -15,44 +19,5 @@


- - diff --git a/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/libwebsockets.org-logo.png b/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/strict-csp.svg b/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-sse/minimal-http-server-sse.c b/minimal-examples/http-server/minimal-http-server-sse/minimal-http-server-sse.c index 626fe57ec..1092dd56a 100644 --- a/minimal-examples/http-server/minimal-http-server-sse/minimal-http-server-sse.c +++ b/minimal-examples/http-server/minimal-http-server-sse/minimal-http-server-sse.c @@ -39,8 +39,8 @@ callback_sse(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len) { struct pss *pss = (struct pss *)user; - uint8_t buf[LWS_PRE + 256], *start = &buf[LWS_PRE], *p = start, - *end = &buf[sizeof(buf) - 1]; + uint8_t buf[LWS_PRE + LWS_RECOMMENDED_MIN_HEADER_SPACE], *start = &buf[LWS_PRE], + *p = start, *end = &buf[sizeof(buf) - 1]; switch (reason) { case LWS_CALLBACK_HTTP: @@ -195,6 +195,8 @@ int main(int argc, const char **argv) info.port = 7681; info.protocols = protocols; info.mounts = &mount; + info.options = + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; context = lws_create_context(&info); if (!context) { diff --git a/minimal-examples/http-server/minimal-http-server-sse/mount-origin/404.html b/minimal-examples/http-server/minimal-http-server-sse/mount-origin/404.html index 1f7ae66e8..3e5a14b9f 100644 --- a/minimal-examples/http-server/minimal-http-server-sse/mount-origin/404.html +++ b/minimal-examples/http-server/minimal-http-server-sse/mount-origin/404.html @@ -1,7 +1,7 @@ -
+

404

Sorry, that file doesn't exist. diff --git a/minimal-examples/http-server/minimal-http-server-sse/mount-origin/example.js b/minimal-examples/http-server/minimal-http-server-sse/mount-origin/example.js new file mode 100644 index 000000000..af73512ec --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-sse/mount-origin/example.js @@ -0,0 +1,38 @@ +document.addEventListener("DOMContentLoaded", function() { + +var head = 0, tail = 0, ring = new Array(); + + es = new EventSource("/sse/sourcename"); + try { + es.onopen = function() { + // console.log("EventSource opened"); + document.getElementById("r").disabled = 0; + }; + + es.onmessage = function got_packet(msg) { + var n, s = ""; + + // console.log(msg.data); + ring[head] = msg.data + "\n"; + head = (head + 1) % 50; + if (tail === head) + tail = (tail + 1) % 50; + + n = tail; + do { + s = s + ring[n]; + n = (n + 1) % 50; + } while (n !== head); + + document.getElementById("r").value = s; + document.getElementById("r").scrollTop = + document.getElementById("r").scrollHeight; + }; + + /* there is no onclose() for EventSource */ + + } catch(exception) { + alert("

Error" + exception); + } + +}, false); diff --git a/minimal-examples/http-server/minimal-http-server-sse/mount-origin/index.html b/minimal-examples/http-server/minimal-http-server-sse/mount-origin/index.html index 5efff5235..42f6b8309 100644 --- a/minimal-examples/http-server/minimal-http-server-sse/mount-origin/index.html +++ b/minimal-examples/http-server/minimal-http-server-sse/mount-origin/index.html @@ -1,55 +1,20 @@ - + + + + -
- + +
+ Hello from the minimal http Server Side Events example.

This is a static page served from ./mount-origin/index.html.

It connects back to the server at /sse/sourcename using EventSource()
- and displays the perioding incoming event data below. + and displays the periodic incoming event data below.


- - diff --git a/minimal-examples/http-server/minimal-http-server-sse/mount-origin/libwebsockets.org-logo.png b/minimal-examples/http-server/minimal-http-server-sse/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-sse/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-sse/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/http-server/minimal-http-server-sse/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-sse/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-sse/mount-origin/strict-csp.svg b/minimal-examples/http-server/minimal-http-server-sse/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-sse/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-tls-80/minimal-http-server-tls-80.c b/minimal-examples/http-server/minimal-http-server-tls-80/minimal-http-server-tls-80.c index 59614eaa4..adfa9fbcc 100644 --- a/minimal-examples/http-server/minimal-http-server-tls-80/minimal-http-server-tls-80.c +++ b/minimal-examples/http-server/minimal-http-server-tls-80/minimal-http-server-tls-80.c @@ -95,7 +95,8 @@ int main(int argc, const char **argv) memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT | - LWS_SERVER_OPTION_EXPLICIT_VHOSTS; + LWS_SERVER_OPTION_EXPLICIT_VHOSTS | + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; context = lws_create_context(&info); if (!context) { diff --git a/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/404.html b/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/404.html index 1f7ae66e8..aa63b7139 100644 --- a/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/404.html +++ b/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/404.html @@ -1,7 +1,11 @@ - + + + + -
+ +

404

Sorry, that file doesn't exist. diff --git a/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/example.js b/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/example.js new file mode 100644 index 000000000..389dc7f35 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/example.js @@ -0,0 +1,21 @@ +document.addEventListener("DOMContentLoaded", function() { + + var transport_protocol = ""; + + if (performance && performance.timing.nextHopProtocol) { + transport_protocol = performance.timing.nextHopProtocol; + } else if (window.chrome && window.chrome.loadTimes) { + transport_protocol = window.chrome.loadTimes().connectionInfo; + } else { + var p = performance.getEntriesByType("resource"); + for (var i = 0; i < p.length; i++) { + var value = "nextHopProtocol" in p[i]; + if (value) + transport_protocol = p[i].nextHopProtocol; + } + } + + if (transport_protocol === "h2") + document.getElementById("transport").innerHTML = ""; + +}, false); diff --git a/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/index.html b/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/index.html index d245a57dc..0753551eb 100644 --- a/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/index.html +++ b/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/index.html @@ -1,8 +1,12 @@ - + + + + -
- + +
+ Hello from the minimal https server example.
You can confirm the 404 page handler by going to this @@ -10,30 +14,5 @@
- - diff --git a/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/libwebsockets.org-logo.png b/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/strict-csp.svg b/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-tls/minimal-http-server-tls.c b/minimal-examples/http-server/minimal-http-server-tls/minimal-http-server-tls.c index 9ab2140ac..b03441993 100644 --- a/minimal-examples/http-server/minimal-http-server-tls/minimal-http-server-tls.c +++ b/minimal-examples/http-server/minimal-http-server-tls/minimal-http-server-tls.c @@ -72,7 +72,8 @@ int main(int argc, const char **argv) info.port = 7681; info.mounts = &mount; info.error_document_404 = "/404.html"; - info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT | + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; info.ssl_cert_filepath = "localhost-100y.cert"; info.ssl_private_key_filepath = "localhost-100y.key"; diff --git a/minimal-examples/http-server/minimal-http-server-tls/mount-origin/404.html b/minimal-examples/http-server/minimal-http-server-tls/mount-origin/404.html index 1f7ae66e8..6fdd6bf33 100644 --- a/minimal-examples/http-server/minimal-http-server-tls/mount-origin/404.html +++ b/minimal-examples/http-server/minimal-http-server-tls/mount-origin/404.html @@ -1,7 +1,9 @@ -
+ +
+

404

Sorry, that file doesn't exist. diff --git a/minimal-examples/http-server/minimal-http-server-tls/mount-origin/example.js b/minimal-examples/http-server/minimal-http-server-tls/mount-origin/example.js new file mode 100644 index 000000000..1606ea03a --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-tls/mount-origin/example.js @@ -0,0 +1,22 @@ +document.addEventListener("DOMContentLoaded", function() { + + var transport_protocol = ""; + + if ( performance && performance.timing.nextHopProtocol ) { + transport_protocol = performance.timing.nextHopProtocol; + } else if ( window.chrome && window.chrome.loadTimes ) { + transport_protocol = window.chrome.loadTimes().connectionInfo; + } else { + + var p = performance.getEntriesByType("resource"); + for (var i=0; i < p.length; i++) { + var value = "nextHopProtocol" in p[i]; + if (value) + transport_protocol = p[i].nextHopProtocol; + } + } + + if (transport_protocol == "h2") + document.getElementById("transport").innerHTML = ""; + } +}, false); \ No newline at end of file diff --git a/minimal-examples/http-server/minimal-http-server-tls/mount-origin/index.html b/minimal-examples/http-server/minimal-http-server-tls/mount-origin/index.html index d245a57dc..c9a1293c4 100644 --- a/minimal-examples/http-server/minimal-http-server-tls/mount-origin/index.html +++ b/minimal-examples/http-server/minimal-http-server-tls/mount-origin/index.html @@ -1,8 +1,12 @@ - + + + + -
- + +
+ Hello from the minimal https server example.
You can confirm the 404 page handler by going to this @@ -10,30 +14,4 @@
- - - diff --git a/minimal-examples/http-server/minimal-http-server-tls/mount-origin/libwebsockets.org-logo.png b/minimal-examples/http-server/minimal-http-server-tls/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-tls/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-tls/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/http-server/minimal-http-server-tls/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-tls/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server-tls/mount-origin/strict-csp.svg b/minimal-examples/http-server/minimal-http-server-tls/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-tls/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server/minimal-http-server.c b/minimal-examples/http-server/minimal-http-server/minimal-http-server.c index 20b59e8b6..0f083dd88 100644 --- a/minimal-examples/http-server/minimal-http-server/minimal-http-server.c +++ b/minimal-examples/http-server/minimal-http-server/minimal-http-server.c @@ -69,6 +69,8 @@ int main(int argc, const char **argv) info.port = 7681; info.mounts = &mount; info.error_document_404 = "/404.html"; + info.options = + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; context = lws_create_context(&info); if (!context) { diff --git a/minimal-examples/http-server/minimal-http-server/mount-origin/404.html b/minimal-examples/http-server/minimal-http-server/mount-origin/404.html index 1f7ae66e8..3e5a14b9f 100644 --- a/minimal-examples/http-server/minimal-http-server/mount-origin/404.html +++ b/minimal-examples/http-server/minimal-http-server/mount-origin/404.html @@ -1,7 +1,7 @@ -
+

404

Sorry, that file doesn't exist. diff --git a/minimal-examples/http-server/minimal-http-server/mount-origin/index.html b/minimal-examples/http-server/minimal-http-server/mount-origin/index.html index cc294bf6f..bc9ffa442 100644 --- a/minimal-examples/http-server/minimal-http-server/mount-origin/index.html +++ b/minimal-examples/http-server/minimal-http-server/mount-origin/index.html @@ -1,8 +1,11 @@ - + + + -
- + +
+ Hello from the minimal http server example.
You can confirm the 404 page handler by going to this diff --git a/minimal-examples/http-server/minimal-http-server/mount-origin/libwebsockets.org-logo.png b/minimal-examples/http-server/minimal-http-server/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/http-server/minimal-http-server/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/http-server/minimal-http-server/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/http-server/minimal-http-server/mount-origin/strict-csp.svg b/minimal-examples/http-server/minimal-http-server/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/selftests-library.sh b/minimal-examples/selftests-library.sh index 2b6e4fbb6..9a0847456 100755 --- a/minimal-examples/selftests-library.sh +++ b/minimal-examples/selftests-library.sh @@ -63,12 +63,12 @@ dotest() { ) >/dev/null 2> /dev/null & W=$! WT=0 - while [ $WT -le 220 ] ; do + while [ $WT -le 420 ] ; do kill -0 $W 2>/dev/null if [ $? -ne 0 ] ; then WT=10000 else - if [ $WT -ge 200 ] ; then + if [ $WT -ge 400 ] ; then WT=10000 kill $W 2>/dev/null wait $W 2>/dev/null diff --git a/minimal-examples/ws-server/minimal-ws-broker/minimal-ws-broker.c b/minimal-examples/ws-server/minimal-ws-broker/minimal-ws-broker.c index 5e6de4a19..31a80d365 100644 --- a/minimal-examples/ws-server/minimal-ws-broker/minimal-ws-broker.c +++ b/minimal-examples/ws-server/minimal-ws-broker/minimal-ws-broker.c @@ -79,6 +79,8 @@ int main(int argc, const char **argv) info.port = 7681; info.mounts = &mount; info.protocols = protocols; + info.options = + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; context = lws_create_context(&info); if (!context) { diff --git a/minimal-examples/ws-server/minimal-ws-broker/mount-origin/example.js b/minimal-examples/ws-server/minimal-ws-broker/mount-origin/example.js new file mode 100644 index 000000000..61c76171e --- /dev/null +++ b/minimal-examples/ws-server/minimal-ws-broker/mount-origin/example.js @@ -0,0 +1,83 @@ + +function get_appropriate_ws_url(extra_url) +{ + var pcol; + var u = document.URL; + + /* + * We open the websocket encrypted if this page came on an + * https:// url itself, otherwise unencrypted + */ + + if (u.substring(0, 5) === "https") { + pcol = "wss://"; + u = u.substr(8); + } else { + pcol = "ws://"; + if (u.substring(0, 4) === "http") + u = u.substr(7); + } + + u = u.split("/"); + + /* + "/xxx" bit is for IE10 workaround */ + + return pcol + u[0] + "/" + extra_url; +} + +function new_ws(urlpath, protocol) +{ + if (typeof MozWebSocket != "undefined") + return new MozWebSocket(urlpath, protocol); + + return new WebSocket(urlpath, protocol); +} + +document.addEventListener("DOMContentLoaded", function() { + + subscriber_ws = new_ws(get_appropriate_ws_url(""), "lws-minimal-broker"); + try { + subscriber_ws.onopen = function() { + document.getElementById("b").disabled = 0; + }; + + subscriber_ws.onmessage =function got_packet(msg) { + document.getElementById("r").value = + document.getElementById("r").value + msg.data + "\n"; + document.getElementById("r").scrollTop = + document.getElementById("r").scrollHeight; + }; + + subscriber_ws.onclose = function(){ + document.getElementById("b").disabled = 1; + }; + } catch(exception) { + alert("

Error " + exception); + } + + publisher_ws = new_ws(get_appropriate_ws_url("/publisher"), "lws-minimal-broker"); + try { + publisher_ws.onopen = function() { + document.getElementById("m").disabled = 0; + }; + + publisher_ws.onmessage =function got_packet(msg) { + }; + + publisher_ws.onclose = function(){ + document.getElementById("m").disabled = 1; + }; + } catch(exception) { + alert("

Error " + exception); + } + + function sendmsg() + { + publisher_ws.send(document.getElementById("m").value); + document.getElementById("m").value = ""; + } + + document.getElementById("b").addEventListener("click", sendmsg); + +}, false); + diff --git a/minimal-examples/ws-server/minimal-ws-broker/mount-origin/index.html b/minimal-examples/ws-server/minimal-ws-broker/mount-origin/index.html index 4dc589aaf..c733b9529 100644 --- a/minimal-examples/ws-server/minimal-ws-broker/mount-origin/index.html +++ b/minimal-examples/ws-server/minimal-ws-broker/mount-origin/index.html @@ -1,9 +1,12 @@ - + + + + - -
- + +
+ LWS chat minimal ws broker example.
This page opens two separate ws connections...
A subscriber ws connection fills this textarea
@@ -15,88 +18,7 @@ ... and a publisher ws connection sends the string
in the box below to the broker when you press Send.
- + - - - - diff --git a/minimal-examples/ws-server/minimal-ws-broker/mount-origin/libwebsockets.org-logo.png b/minimal-examples/ws-server/minimal-ws-broker/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/ws-server/minimal-ws-broker/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/ws-server/minimal-ws-broker/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/ws-server/minimal-ws-broker/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/ws-server/minimal-ws-broker/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/ws-server/minimal-ws-broker/mount-origin/strict-csp.svg b/minimal-examples/ws-server/minimal-ws-broker/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/ws-server/minimal-ws-broker/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/ws-server/minimal-ws-server-echo/minimal-ws-server-echo.c b/minimal-examples/ws-server/minimal-ws-server-echo/minimal-ws-server-echo.c index 9e4ed4554..6049f1ae6 100644 --- a/minimal-examples/ws-server/minimal-ws-server-echo/minimal-ws-server-echo.c +++ b/minimal-examples/ws-server/minimal-ws-server-echo/minimal-ws-server-echo.c @@ -98,7 +98,8 @@ int main(int argc, const char **argv) if (!lws_cmdline_option(argc, argv, "-n")) info.extensions = extensions; info.pt_serv_buf_size = 32 * 1024; - info.options = LWS_SERVER_OPTION_VALIDATE_UTF8; + info.options = LWS_SERVER_OPTION_VALIDATE_UTF8 | + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; context = lws_create_context(&info); if (!context) { diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/minimal-ws-server-pmd-bulk.c b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/minimal-ws-server-pmd-bulk.c index f74309c3d..046ec1e41 100644 --- a/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/minimal-ws-server-pmd-bulk.c +++ b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/minimal-ws-server-pmd-bulk.c @@ -114,6 +114,8 @@ int main(int argc, const char **argv) info.mounts = &mount; info.protocols = protocols; info.pvo = &pvo; + info.options = + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; if (!lws_cmdline_option(argc, argv, "-n")) info.extensions = extensions; diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/example.js b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/example.js new file mode 100644 index 000000000..d1c49a77f --- /dev/null +++ b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/example.js @@ -0,0 +1,65 @@ + +function get_appropriate_ws_url(extra_url) +{ + var pcol; + var u = document.URL; + + /* + * We open the websocket encrypted if this page came on an + * https:// url itself, otherwise unencrypted + */ + + if (u.substring(0, 5) === "https") { + pcol = "wss://"; + u = u.substr(8); + } else { + pcol = "ws://"; + if (u.substring(0, 4) === "http") + u = u.substr(7); + } + + u = u.split("/"); + + /* + "/xxx" bit is for IE10 workaround */ + + return pcol + u[0] + "/" + extra_url; +} + +function new_ws(urlpath, protocol) +{ + if (typeof MozWebSocket != "undefined") + return new MozWebSocket(urlpath, protocol); + + return new WebSocket(urlpath, protocol); +} + +document.addEventListener("DOMContentLoaded", function() { + + ws = new_ws(get_appropriate_ws_url(""), "lws-minimal-pmd-bulk"); + try { + ws.onopen = function() { + document.getElementById("r").disabled = 0; + document.getElementById("status").textContent = "ws open "+ ws.extensions; + }; + + ws.onmessage = function got_packet(msg) { + console.log("Received ws message len " + msg.data.size); + document.getElementById("r").value = + document.getElementById("r").value + "\nReceived: " + msg.data.size + " bytes\n"; + document.getElementById("r").scrollTop = + document.getElementById("r").scrollHeight; + + /* echo it back */ + ws.send(msg.data); + }; + + ws.onclose = function(){ + document.getElementById("r").disabled = 1; + document.getElementById("status").textContent = "ws closed"; + }; + } catch(exception) { + alert("

Error " + exception); + } + +}, false); + diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/index.html b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/index.html index c123699f8..f54f1cc58 100644 --- a/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/index.html +++ b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/index.html @@ -1,9 +1,12 @@ - + + + + - -
- + +
+ LWS bulk transfer example.
A large ws message is sent to all browsers open on this page.
The browser js echoes the large ws message back to the server.
@@ -11,81 +14,6 @@ Ws closed


- - - - - - diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/libwebsockets.org-logo.png b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/strict-csp.svg b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd/minimal-ws-server-pmd.c b/minimal-examples/ws-server/minimal-ws-server-pmd/minimal-ws-server-pmd.c index 25cded376..40e3b85cf 100644 --- a/minimal-examples/ws-server/minimal-ws-server-pmd/minimal-ws-server-pmd.c +++ b/minimal-examples/ws-server/minimal-ws-server-pmd/minimal-ws-server-pmd.c @@ -90,6 +90,8 @@ int main(int argc, const char **argv) info.mounts = &mount; info.protocols = protocols; info.extensions = extensions; + info.options = + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; context = lws_create_context(&info); if (!context) { diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/example.js b/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/example.js new file mode 100644 index 000000000..4760a20f8 --- /dev/null +++ b/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/example.js @@ -0,0 +1,71 @@ + +function get_appropriate_ws_url(extra_url) +{ + var pcol; + var u = document.URL; + + /* + * We open the websocket encrypted if this page came on an + * https:// url itself, otherwise unencrypted + */ + + if (u.substring(0, 5) === "https") { + pcol = "wss://"; + u = u.substr(8); + } else { + pcol = "ws://"; + if (u.substring(0, 4) === "http") + u = u.substr(7); + } + + u = u.split("/"); + + /* + "/xxx" bit is for IE10 workaround */ + + return pcol + u[0] + "/" + extra_url; +} + +function new_ws(urlpath, protocol) +{ + if (typeof MozWebSocket != "undefined") + return new MozWebSocket(urlpath, protocol); + + return new WebSocket(urlpath, protocol); +} + +document.addEventListener("DOMContentLoaded", function() { + + ws = new_ws(get_appropriate_ws_url(""), "lws-minimal"); + try { + ws.onopen = function() { + document.getElementById("m").disabled = 0; + document.getElementById("b").disabled = 0; + document.getElementById("status").textContent = "ws open "+ ws.extensions; + }; + + ws.onmessage =function got_packet(msg) { + document.getElementById("r").value = + document.getElementById("r").value + msg.data + "\n"; + document.getElementById("r").scrollTop = + document.getElementById("r").scrollHeight; + }; + + ws.onclose = function(){ + document.getElementById("m").disabled = 1; + document.getElementById("b").disabled = 1; + document.getElementById("status").textContent = "ws closed"; + }; + } catch(exception) { + alert("

Error " + exception); + } + + function sendmsg() + { + ws.send(document.getElementById("m").value); + document.getElementById("m").value = ""; + } + + document.getElementById("b").addEventListener("click", sendmsg); + +}, false); + diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/index.html b/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/index.html index 74750344e..43c548aeb 100644 --- a/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/index.html +++ b/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/index.html @@ -1,8 +1,12 @@ - + + + + -
+ +
LWS chat minimal ws server example.
Chat is sent to all browsers open on this page.
@@ -11,76 +15,7 @@

- + - - - - diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/libwebsockets.org-logo.png b/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/strict-csp.svg b/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/ws-server/minimal-ws-server-ring/minimal-ws-server-ring.c b/minimal-examples/ws-server/minimal-ws-server-ring/minimal-ws-server-ring.c index 1da75383b..2a90431d5 100644 --- a/minimal-examples/ws-server/minimal-ws-server-ring/minimal-ws-server-ring.c +++ b/minimal-examples/ws-server/minimal-ws-server-ring/minimal-ws-server-ring.c @@ -79,6 +79,8 @@ int main(int argc, const char **argv) info.port = 7681; info.mounts = &mount; info.protocols = protocols; + info.options = + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; context = lws_create_context(&info); if (!context) { diff --git a/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/example.js b/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/example.js new file mode 100644 index 000000000..be1037fd9 --- /dev/null +++ b/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/example.js @@ -0,0 +1,68 @@ +function get_appropriate_ws_url(extra_url) +{ + var pcol; + var u = document.URL; + + /* + * We open the websocket encrypted if this page came on an + * https:// url itself, otherwise unencrypted + */ + + if (u.substring(0, 5) === "https") { + pcol = "wss://"; + u = u.substr(8); + } else { + pcol = "ws://"; + if (u.substring(0, 4) === "http") + u = u.substr(7); + } + + u = u.split("/"); + + /* + "/xxx" bit is for IE10 workaround */ + + return pcol + u[0] + "/" + extra_url; +} + +function new_ws(urlpath, protocol) +{ + if (typeof MozWebSocket != "undefined") + return new MozWebSocket(urlpath, protocol); + + return new WebSocket(urlpath, protocol); +} + +document.addEventListener("DOMContentLoaded", function() { + + ws = new_ws(get_appropriate_ws_url(""), "lws-minimal"); + try { + ws.onopen = function() { + document.getElementById("m").disabled = 0; + document.getElementById("b").disabled = 0; + }; + + ws.onmessage =function got_packet(msg) { + document.getElementById("r").value = + document.getElementById("r").value + msg.data + "\n"; + document.getElementById("r").scrollTop = + document.getElementById("r").scrollHeight; + }; + + ws.onclose = function(){ + document.getElementById("m").disabled = 1; + document.getElementById("b").disabled = 1; + }; + } catch(exception) { + alert("

Error " + exception); + } + + function sendmsg() + { + ws.send(document.getElementById("m").value); + document.getElementById("m").value = ""; + } + + document.getElementById("b").addEventListener("click", sendmsg); + +}, false); + diff --git a/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/index.html b/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/index.html index fed76a1bf..7081c31fc 100644 --- a/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/index.html +++ b/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/index.html @@ -1,8 +1,11 @@ - + + + + - -
+ +
LWS chat minimal ws server example.
Chat is sent to all browsers open on this page. @@ -11,74 +14,7 @@
- + - - - - diff --git a/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/libwebsockets.org-logo.png b/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/strict-csp.svg b/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/ws-server/minimal-ws-server-threadpool/minimal-ws-server-threadpool.c b/minimal-examples/ws-server/minimal-ws-server-threadpool/minimal-ws-server-threadpool.c index 3b4ad7a85..2c6063389 100644 --- a/minimal-examples/ws-server/minimal-ws-server-threadpool/minimal-ws-server-threadpool.c +++ b/minimal-examples/ws-server/minimal-ws-server-threadpool/minimal-ws-server-threadpool.c @@ -108,6 +108,8 @@ int main(int argc, const char **argv) info.mounts = &mount; info.protocols = protocols; info.pvo = &pvo; /* per-vhost options */ + info.options = + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; context = lws_create_context(&info); if (!context) { diff --git a/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/example.js b/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/example.js new file mode 100644 index 000000000..783ae136b --- /dev/null +++ b/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/example.js @@ -0,0 +1,78 @@ +var head = 0, tail = 0, ring = new Array(); + +function get_appropriate_ws_url(extra_url) +{ + var pcol; + var u = document.URL; + + /* + * We open the websocket encrypted if this page came on an + * https:// url itself, otherwise unencrypted + */ + + if (u.substring(0, 5) === "https") { + pcol = "wss://"; + u = u.substr(8); + } else { + pcol = "ws://"; + if (u.substring(0, 4) === "http") + u = u.substr(7); + } + + u = u.split("/"); + + /* + "/xxx" bit is for IE10 workaround */ + + return pcol + u[0] + "/" + extra_url; +} + +function new_ws(urlpath, protocol) +{ + if (typeof MozWebSocket != "undefined") + return new MozWebSocket(urlpath, protocol); + + return new WebSocket(urlpath, protocol); +} + +document.addEventListener("DOMContentLoaded", function() { + + var n, wsa = new Array, alive = 0; + + for (n = 0; n < 8; n++) { + + ws = new_ws(get_appropriate_ws_url(""), "lws-minimal"); + wsa.push(ws); + try { + ws.onopen = function() { + document.getElementById("r").disabled = 0; + alive++; + }; + + ws.onmessage = function got_packet(msg) { + var n, s = ""; + + ring[head] = msg.data + "\n"; + head = (head + 1) % 50; + if (tail === head) + tail = (tail + 1) % 50; + + n = tail; + do { + s = s + ring[n]; + n = (n + 1) % 50; + } while (n !== head); + + document.getElementById("r").value = s; + document.getElementById("r").scrollTop = + document.getElementById("r").scrollHeight; + }; + + ws.onclose = function(){ + if (--alive === 0) + document.getElementById("r").disabled = 1; + }; + } catch(exception) { + alert("

Error " + exception); + } + } +}, false); diff --git a/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/index.html b/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/index.html index 47fb96b7f..ab3a306e9 100644 --- a/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/index.html +++ b/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/index.html @@ -1,8 +1,12 @@ - - + + + + + -
- + +
+ Minimal ws server threadpool example.
8 x ws connections are opened back to the example server.
There are three threads in the pool to service them, the
@@ -12,86 +16,4 @@

- - - - diff --git a/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/libwebsockets.org-logo.png b/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/strict-csp.svg b/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c b/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c index 1632626a4..0f2e9fa6a 100644 --- a/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c +++ b/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c @@ -108,6 +108,8 @@ int main(int argc, const char **argv) info.mounts = &mount; info.protocols = protocols; info.pvo = &pvo; /* per-vhost options */ + info.options = + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; context = lws_create_context(&info); if (!context) { diff --git a/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/example.js b/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/example.js new file mode 100644 index 000000000..a6ff6630f --- /dev/null +++ b/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/example.js @@ -0,0 +1,71 @@ +var head = 0, tail = 0, ring = new Array(); + +function get_appropriate_ws_url(extra_url) +{ + var pcol; + var u = document.URL; + + /* + * We open the websocket encrypted if this page came on an + * https:// url itself, otherwise unencrypted + */ + + if (u.substring(0, 5) === "https") { + pcol = "wss://"; + u = u.substr(8); + } else { + pcol = "ws://"; + if (u.substring(0, 4) === "http") + u = u.substr(7); + } + + u = u.split("/"); + + /* + "/xxx" bit is for IE10 workaround */ + + return pcol + u[0] + "/" + extra_url; +} + +function new_ws(urlpath, protocol) +{ + if (typeof MozWebSocket != "undefined") + return new MozWebSocket(urlpath, protocol); + + return new WebSocket(urlpath, protocol); +} + +document.addEventListener("DOMContentLoaded", function() { + + ws = new_ws(get_appropriate_ws_url(""), "lws-minimal"); + try { + ws.onopen = function() { + document.getElementById("r").disabled = 0; + }; + + ws.onmessage =function got_packet(msg) { + var n, s = ""; + + ring[head] = msg.data + "\n"; + head = (head + 1) % 50; + if (tail === head) + tail = (tail + 1) % 50; + + n = tail; + do { + s = s + ring[n]; + n = (n + 1) % 50; + } while (n !== head); + + document.getElementById("r").value = s; + document.getElementById("r").scrollTop = + document.getElementById("r").scrollHeight; + }; + + ws.onclose = function(){ + document.getElementById("r").disabled = 1; + }; + } catch(exception) { + alert("

Error " + exception); + } + +}, false); diff --git a/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/index.html b/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/index.html index 928eaf906..8bd248c31 100644 --- a/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/index.html +++ b/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/index.html @@ -1,8 +1,12 @@ - + + + + -
- +
+
+ Minimal ws server threads example.
Strings generated by server threads are sent to all browsers open on this page.
@@ -11,78 +15,5 @@

- - - diff --git a/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/libwebsockets.org-logo.png b/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/strict-csp.svg b/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c index 61dcd2f9d..0537d0c2b 100644 --- a/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c @@ -254,6 +254,8 @@ init_fail: break; case LWS_CALLBACK_EVENT_WAIT_CANCELLED: + if (!vhd) + break; /* * When the "spam" threads add a message to the ringbuffer, * they create this event in the lws service thread context diff --git a/minimal-examples/ws-server/minimal-ws-server/minimal-ws-server.c b/minimal-examples/ws-server/minimal-ws-server/minimal-ws-server.c index fe7fd2989..1d5438c4b 100644 --- a/minimal-examples/ws-server/minimal-ws-server/minimal-ws-server.c +++ b/minimal-examples/ws-server/minimal-ws-server/minimal-ws-server.c @@ -81,10 +81,12 @@ int main(int argc, const char **argv) info.protocols = protocols; info.vhost_name = "localhost"; info.ws_ping_pong_interval = 10; + info.options = + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; if (lws_cmdline_option(argc, argv, "-s")) { lwsl_user("Server using TLS\n"); - info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; info.ssl_cert_filepath = "localhost-100y.cert"; info.ssl_private_key_filepath = "localhost-100y.key"; } diff --git a/minimal-examples/ws-server/minimal-ws-server/mount-origin/example.js b/minimal-examples/ws-server/minimal-ws-server/mount-origin/example.js new file mode 100644 index 000000000..189f4640b --- /dev/null +++ b/minimal-examples/ws-server/minimal-ws-server/mount-origin/example.js @@ -0,0 +1,69 @@ + +function get_appropriate_ws_url(extra_url) +{ + var pcol; + var u = document.URL; + + /* + * We open the websocket encrypted if this page came on an + * https:// url itself, otherwise unencrypted + */ + + if (u.substring(0, 5) === "https") { + pcol = "wss://"; + u = u.substr(8); + } else { + pcol = "ws://"; + if (u.substring(0, 4) === "http") + u = u.substr(7); + } + + u = u.split("/"); + + /* + "/xxx" bit is for IE10 workaround */ + + return pcol + u[0] + "/" + extra_url; +} + +function new_ws(urlpath, protocol) +{ + if (typeof MozWebSocket != "undefined") + return new MozWebSocket(urlpath, protocol); + + return new WebSocket(urlpath, protocol); +} + +document.addEventListener("DOMContentLoaded", function() { + + ws = new_ws(get_appropriate_ws_url(""), "lws-minimal"); + try { + ws.onopen = function() { + document.getElementById("m").disabled = 0; + document.getElementById("b").disabled = 0; + }; + + ws.onmessage =function got_packet(msg) { + document.getElementById("r").value = + document.getElementById("r").value + msg.data + "\n"; + document.getElementById("r").scrollTop = + document.getElementById("r").scrollHeight; + }; + + ws.onclose = function(){ + document.getElementById("m").disabled = 1; + document.getElementById("b").disabled = 1; + }; + } catch(exception) { + alert("

Error " + exception); + } + + function sendmsg() + { + ws.send(document.getElementById("m").value); + document.getElementById("m").value = ""; + } + + document.getElementById("b").addEventListener("click", sendmsg); + +}, false); + diff --git a/minimal-examples/ws-server/minimal-ws-server/mount-origin/index.html b/minimal-examples/ws-server/minimal-ws-server/mount-origin/index.html index 5f42336b8..9c1dc9a49 100644 --- a/minimal-examples/ws-server/minimal-ws-server/mount-origin/index.html +++ b/minimal-examples/ws-server/minimal-ws-server/mount-origin/index.html @@ -1,8 +1,11 @@ - + + + + - -
+ +
LWS chat minimal ws server example.
Chat is sent to all browsers open on this page. @@ -10,74 +13,7 @@

- + - - - - diff --git a/minimal-examples/ws-server/minimal-ws-server/mount-origin/libwebsockets.org-logo.png b/minimal-examples/ws-server/minimal-ws-server/mount-origin/libwebsockets.org-logo.png deleted file mode 100644 index 2060a10c9..000000000 Binary files a/minimal-examples/ws-server/minimal-ws-server/mount-origin/libwebsockets.org-logo.png and /dev/null differ diff --git a/minimal-examples/ws-server/minimal-ws-server/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/ws-server/minimal-ws-server/mount-origin/libwebsockets.org-logo.svg new file mode 100644 index 000000000..7baea649f --- /dev/null +++ b/minimal-examples/ws-server/minimal-ws-server/mount-origin/libwebsockets.org-logo.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minimal-examples/ws-server/minimal-ws-server/mount-origin/strict-csp.svg b/minimal-examples/ws-server/minimal-ws-server/mount-origin/strict-csp.svg new file mode 100644 index 000000000..cd128f1d2 --- /dev/null +++ b/minimal-examples/ws-server/minimal-ws-server/mount-origin/strict-csp.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test-apps/test.html b/test-apps/test.html index 73aed25e0..f4b89a73a 100644 --- a/test-apps/test.html +++ b/test-apps/test.html @@ -18,7 +18,7 @@

- + +
...
- +
...