[Libwebsockets] Custom HTTP Headers

Andy Green andy at warmcat.com
Tue Aug 15 17:44:51 CEST 2017



On August 15, 2017 10:29:07 PM GMT+08:00, Mike Mathews <Mike.Mathews at comtechtel.com> wrote:
>Thanks.
>
>Ideally, I would do it with a standard header, but I'm stuck with
>legacy support of existing products.
>
>Is it a workable idea to put a simple accessor to ah.rx, which I see
>does contain the header values and extract them in the application
>code?  I would prefer to avoid changing libWebSockets too much for
>maintainability as well.

It's FOSS so you can do what you think suits your situation best.

However lws uses bytewise state machines for this stuff.  Working with the existing minilex scheme (which is really quite easy) regenerates the lexical parser for headers to include states for your new strings.  If you try to go around that 'to do it simpler' you will find it's actually much more difficult.

Using the general lws hdr accessors is also very simple and will 'just work' after taking only the steps I listed before.

-Andy

>Thanks again.
>
>Mike
>
>> On Aug 14, 2017, at 11:59 PM, Andy Green <andy at warmcat.com> wrote:
>>
>>
>>
>>> On 08/15/2017 02:03 PM, Mike Mathews wrote:
>>> Hi:
>>> We have an application of libwebsockets where we are passing custom
>headers, for example a header might include:
>>> POST /SomeEndpoint HTTP/1.1
>>> Host: localhost:3000
>>> api_key: Fv-xkmMYQ0OdEQH-TPbMUupFYuFpYTKl45r1tmpR
>>> Content-Type: application/json
>>> Cache-Control: no-cache
>>> Postman-Token: ae1e83a7-cd6a-f02c-d830-3f8c11f75e4b
>>>>>> What is the proper way to access the custom header elements?  The
>lws_hdr_copy(...) method requiring predefined tokens only works for
>predefined ‘standard’ headers.
>>
>> There are two ways you can go:
>>
>> 1) put your custom header content in an existing header; there's no
>real need for you own arbitrary-named headers.  Eg, for transparent
>compatibility you can put it as payload WSI_TOKEN_HTTP_SET_COOKIE with
>an expiry date in the past.
>>
>> 2) Add your own token index + header name string.  But if it's a
>proprietary name I am not really interested in adding it so it takes up
>memory for everyone, when nobody else will use it.
>>
>>    - edit lib/lextable-strings.h and add the new header string at the
>end before the empty string (after "connect" at the moment)
>>
>>    - add a matching entry in lib/libwebsockets.h, again after
>LWS_TOKEN_CONNECT at the moment
>>
>>    - cd into ./lib and run this two times
>>
>> $ gcc minilex.c -o minilex && ./minilex > lextable.h
>>
>> -Andy
>>
>>> Thank you,
>>> Mike M.
>>> NOTICE TO RECIPIENT: This email, including attachments, may contain
>information which is confidential, proprietary, attorney-client
>privileged and/or controlled under U.S. export laws and regulations and
>may be restricted from disclosure by applicable State and Federal law.
>Nothing in this email shall create any legal binding agreement between
>the parties unless expressly stated herein and provided by an
>authorized representative of Comtech Telecommunications Corp. or its
>subsidiaries. If you are not the intended recipient of this message, be
>advised that any dissemination, distribution, or use of the contents of
>this message is strictly prohibited. If you received this message in
>error, please notify us immediately by return email and permanently
>delete all copies of the original email and any attached documentation
>from any computer or other media.
>>> _______________________________________________
>>> Libwebsockets mailing list
>>> Libwebsockets at ml.libwebsockets.org
>>> https://libwebsockets.org/mailman/listinfo/libwebsockets
>>
>NOTICE TO RECIPIENT: This email, including attachments, may contain
>information which is confidential, proprietary, attorney-client
>privileged and/or controlled under U.S. export laws and regulations and
>may be restricted from disclosure by applicable State and Federal law.
>Nothing in this email shall create any legal binding agreement between
>the parties unless expressly stated herein and provided by an
>authorized representative of Comtech Telecommunications Corp. or its
>subsidiaries. If you are not the intended recipient of this message, be
>advised that any dissemination, distribution, or use of the contents of
>this message is strictly prohibited. If you received this message in
>error, please notify us immediately by return email and permanently
>delete all copies of the original email and any attached documentation
>from any computer or other media.



More information about the Libwebsockets mailing list