-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmake: add CUSTOM_HTTP_HEADERS for the automated minilex process #1499
Conversation
For accessing the http headers that lws doesn't support to read from the websocket server response, internal lextable for http protocol parser has to be re-generated by manually modifying the lextable-strings.h and the minilex tool. This change does automate this minilex process which updates lextable and adds relevant enums like WSI_TOKEN_XXX into public header in build time in safe/easy manner without modifying any original source code under the lib directory. Example: cmake .. -DCUSTOM_HTTP_HEADERS=X-Foo,X-Bar This CMake option is available on Unix/Linux/Mac OS X and Windows (MSYS/MinGW only)
Thanks... I appreciate what you're trying to do, but I don't really want to do this. There are a few reasons, some to do with the implementation:
There's often an existing header that can take the data in a standardized way (eg, whatever weirdo authentication token, it can use Lws takes the approach that if it's not one of the 100 or so headers it understands, it just drops the header content... the good way to deal with this I think is add stuff to the ah parser to make it keep the unknown header content and eg, reserve a few extra ah pointers to point to say the first 4 unknown headers it met (it will also need to be able to "point" to the header name part and know its length). Then similar to how you can create headers by index or name, add apis to return any 'unknown' header content if any by header name. This'd have to be implemented on both the h1 and h2 ah parsers... although quite different they use the same ah struct. For h2 dynamic indexed headers, you'd have to copy the indexed header name out of the index and into the ah headers region and point to it at parse time, because the dynamic index can change inbetween parsing and querying. That'll allow runtime extensible headers while keeping the current arrangements for common headers. |
fb11f27
to
b321a07
Compare
Hi Andy, Thanks for the comment for the PR. BTW, I've updated PR. If you are ok, can you please review the update on this PR again? The usage is same... add -DCUSTOM_HTTP_HEADERS=X-Foo,X-Bar in the cmake time and the custom header support is automatically applied while building. I tried to use the CMake macro instead of the previous bash command.. extended the minilex.c to get rid of the bash command in previous PR. here's update on your comment.
Now, the change has considered cross compilation.
applied cmake -E copy
added command line options into minilex.c. and replaced previous bash commands by minilex.
I'm not sure if I get your point correctly. but this PR defines LWS_WITH_CUSTOM_HTTP_HEADER in lws-config.h the option is given.
|
…lt ws binding On lwsws, incoming ws connections to the default vhost are not rejected by the dummy protocol handler and not really serviced either, leading to bots connecting to it to get immortal, idle ws connections with no timeout (since it's an established ws connection). Rejecting these connections by default by adding a handler for ESTABLISHED in the dummy handler will solve it nicely, but it will break an unknown number of dumb. protocol-less user implementations that rely on this behaviour by using break; from their own ESTABLISHED handler and calling through to the currently NOP dummy handler one. Add support to assertively disable the default protocol index used for subprotocol-less ws connections instead.
With SMP as soon as we add the new sockfd to the fds table, in the case we load-balanced the fd on to a different pt, service on it becomes live immediately and concurrently. This can lead to the unexpected situation that while we think we're still initing the new wsi from our thread, it can have lived out its whole life concurrently from another service thread. Add a volatile flag to inform the owning pt that if it wants to service the wsi during this init window, it must wait and retry next time around the event loop.
MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Setting m to 0 by default will prevent "error: ‘m’ may be used uninitialized in this function" while compiling with the option -DLWS_WITH_LIBUV=ON.
This seen in the wild... ==20578== Invalid read of size 1 ==20578== at 0x4D2E018: uv_poll_stop (poll.c:112) ==20578== by 0x48BC159: elops_io_uv (libuv.c:684) ==20578== by 0x4872F55: __remove_wsi_socket_from_fds (pollfd.c:326) ==20578== by 0x486EF1B: __lws_close_free_wsi (close.c:425) ==20578== by 0x486F3E2: lws_close_free_wsi (close.c:518) ==20578== by 0x487564C: lws_service_fd_tsi (service.c:1033) ==20578== by 0x48BAEA9: lws_io_cb (libuv.c:117) ==20578== by 0x4D3606F: uv__io_poll (linux-core.c:379) ==20578== by 0x4D27714: uv_run (core.c:361) ==20578== by 0x48BC347: elops_run_pt_uv (libuv.c:735) ==20578== by 0x4875746: lws_service (service.c:1080) ==20578== by 0x401A51: main (main.c:309) ==20578== Address 0x58 is not stack'd, malloc'd or (recently) free'd
The cmake config on the build system actually decides the release build optimization policy. On Fedora, it's -O2. On Ubuntu, it's -O3. Anything given in CMakeLists.txt is overridden by the build system policy since it goes at the end of the compiler commandline. When you are building cross, the build system's opinion of your cross binary optimization level is irrelevant, and at worst destructive. Some versions of gcc contain broken optimizations that are applied only at -O3. This patch removes any doomed attempt to set -O in CMakeLists.txt, which has no effect since the build system policy is still added at the end, but removes confusion; and adds code to all the cross build files to forcibly override release optimization level to -O2, removing the build system's opinion of how your cross build should look.
b321a07
to
4a72990
Compare
just pushed again with some fix like usage string of minilex, cmake dependency. |
Until now lws only parses headers it knows at build-time from its prebuilt lexical analyzer. This adds an on-by-default cmake option and a couple of apis to also store and query "custom", ie, unknown-to-lws headers. A minimal example is also provided. At the moment it only works on h1, h2 support needs improvements to the hpack implementation. Since it bloats ah memory usage compared to without it if custom headers are present, the related code and ah footprint can be disabled with the cmake option LWS_WITH_CUSTOM_HEADERS, but it's on by default normally. ESP32 platform disables it. #1499
Great.
I have a patch for it on h1 already. Doing it on h2 is going to need a larger rework of the hpack stuff to improve that first. I pushed the h1 support on master along with a minimal example, please give it a try. |
Until now lws only parses headers it knows at build-time from its prebuilt lexical analyzer. This adds an on-by-default cmake option and a couple of apis to also store and query "custom", ie, unknown-to-lws headers. A minimal example is also provided. At the moment it only works on h1, h2 support needs improvements to the hpack implementation. Since it bloats ah memory usage compared to without it if custom headers are present, the related code and ah footprint can be disabled with the cmake option LWS_WITH_CUSTOM_HEADERS, but it's on by default normally. ESP32 platform disables it. #1499
3fe1966
to
a4a701b
Compare
Until now lws only parses headers it knows at build-time from its prebuilt lexical analyzer. This adds an on-by-default cmake option and a couple of apis to also store and query "custom", ie, unknown-to-lws headers. A minimal example is also provided. At the moment it only works on h1, h2 support needs improvements to the hpack implementation. Since it bloats ah memory usage compared to without it if custom headers are present, the related code and ah footprint can be disabled with the cmake option LWS_WITH_CUSTOM_HEADERS, but it's on by default normally. ESP32 platform disables it. #1499
Until now lws only parses headers it knows at build-time from its prebuilt lexical analyzer. This adds an on-by-default cmake option and a couple of apis to also store and query "custom", ie, unknown-to-lws headers. A minimal example is also provided. At the moment it only works on h1, h2 support needs improvements to the hpack implementation. Since it bloats ah memory usage compared to without it if custom headers are present, the related code and ah footprint can be disabled with the cmake option LWS_WITH_CUSTOM_HEADERS, but it's on by default normally. ESP32 platform disables it. #1499
Hi Andy, the custom headers support for h1 you've added (f5e5c59) works well. |
Until now lws only parses headers it knows at build-time from its prebuilt lexical analyzer. This adds an on-by-default cmake option and a couple of apis to also store and query "custom", ie, unknown-to-lws headers. A minimal example is also provided. At the moment it only works on h1, h2 support needs improvements to the hpack implementation. Since it bloats ah memory usage compared to without it if custom headers are present, the related code and ah footprint can be disabled with the cmake option LWS_WITH_CUSTOM_HEADERS, but it's on by default normally. ESP32 platform disables it. #1499
For accessing the http headers that lws doesn't support to read
from the websocket server response, internal lextable for http
protocol parser has to be re-generated by manually modifying the
lextable-strings.h and the minilex tool.
This change does automate this minilex process which updates
lextable and adds relevant enums like WSI_TOKEN_XXX into public
header in build time in safe/easy manner without modifying any
original source code under the lib directory.
Example:
$ cmake .. -DCUSTOM_HTTP_HEADERS=X-Foo,X-Bar
This CMake option is available on Unix/Linux/Mac OS X and Windows
(MSYS/MinGW only)
Additional explanation for lws-team for better understanding
How it works:
Since this PR uses standard unix tools like grep/tr/head/sed for automation, it's not available option for the VS project. But it's available for the windows using the MSYS/MinGW.
I've tested this PR on Mac OS X Mojave, Ubuntu 18.04, Windows MSYS2 (with MinGW) and worked well.
I believe this helps 2 cases
a lws user who want to handle the custom http header from the web socket server response.
the lws-team whenever needs to add standard http header into the lextable.