[Libwebsockets] POST messages callbacks

mbargauan at comm5g.com mbargauan at comm5g.com
Wed Mar 3 16:03:18 CET 2021


   Thank you, Andy.

   After some more troubleshooting, I can say that my problem arise from having "/" as URI and default file is delivered as a normal GET even if it is a POST, never calling LWS_CALLBACK_HTTP_BODY.
   Same when  URI points to a file that exist in  LOCAL_RESOURCE_PATH - eg: duplicated index.html as index2.html, file delivered, no LWS_CALLBACK_HTTP_BODY.
   Any other URI works correctly. providing that protocol at LWS_CALLBACK_HTTP does nothing and returns with 0.
   I am not very deep in source code but it seems that decision on calling LWS_CALLBACK_HTTP_BODY is taken inside lws_http_action()
   line 1762  if (lwsi_state(wsi) == LRS_ISSUING_FILE)
   return 0;
   as lwsi_state is set to LRS_ISSUING_FILE any time a file is delivered.
   I cannot move from 4.1 to main branch now - but there is the same lines of code @row 1798.
   Mike
   p.s. : i attach a file (lws-callbacks2string.h) that helps me a lot -
   I do insert
   lwsl_notice("MIKE HTTP %d - %s\n", reason, lws_callback_strings[reason]);
   at beginning of each protocol to track callbacks
   and #insert "ws-callbacks2string.h" in main program.
   From "Andy Green" andy at warmcat.com
   To mbargauan at comm5g.com,"libwebsockets" libwebsockets at ml.libwebsockets.org
   Cc
   Date Wed, 3 Mar 2021 09:31:41 +0000
   Subject Re: [Libwebsockets] POST messages callbacks


   On 3/3/21 8:18 AM, mbargauan at comm5g.com wrote:
   > I am using version 4.1 and I need to process POST message attached.

   I assume lws is being the server.

   Does the same situation exist if you use the main branch of lws?

   > While in provided demo programs I see LWS_CALLBACK_HTTP_BODY +
   > LWS_CALLBACK_HTTP_BODY_COMPLETION reason callbacks when receiving POST

   Well, that's good.

   > message, with my POST message I do not get callbacks with these reason.
   > Decode URI is only / while should be /?event=up - as if ? is considered
   > invalid part of URI.

   No it's not invalid, the urlargs are parsed out separately so you can
   access them by name.

   https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-http.h?h=main#n497-508

   > Another difference is in content type.

   It doesn't care.

   > Obviously incoming POST come from other applications I cannot discuss.

   ...

   I attach "example-hack.diff" which changes a few lines in the existing
   minimal-http-server-form-post to stop it trying to interpret the form
   and add some logs.

   And I extracted your client transaction from the packet trace, just
   changed the URL from / to /form1 to match the expectation of the
   example, that's in the attached "txn".

   Then I built lws with -DLWS_WITH_MINIMAL_EXAMPLES=1 so it built the
   modified example, in a terminal

   $ cd minimal-examples/http-server/minimal-http-server-form-post
   $ ../../../build/bin/lws-minimal-http-server-form-post

   [2021/03/03 09:27:09:8712] U: LWS minimal http server POST | visit
   http://localhost:7681
   [2021/03/03 09:27:09:8714] N: LWS: 4.1.99-v4.1.0-294-g2776b4ce65,
   loglevel 1031
   [2021/03/03 09:27:09:8714] N: NET CLI SRV H1 H2 WS SS-JSON-POL SSPROX
   IPV6-on
   [2021/03/03 09:27:09:8724] N: ++ [2008974|wsi|0|pipe] (1)
   [2021/03/03 09:27:09:8726] N: ++ [2008974|vh|0|netlink] (1)
   [2021/03/03 09:27:09:8728] N: ++ [2008974|vh|1|default||7681] (2)
   [2021/03/03 09:27:09:8729] N: lws_socket_bind: nowsi: source ads ::
   [2021/03/03 09:27:09:8729] N: ++ [2008974|wsi|1|listen|default||7681] (2)

   Then in another terminal

   $ cat txn - | nc 127.0.0.1 7681

   [2021/03/03 09:27:12:1899] N: ++ [2008974|wsisrv|0|adopted] (1)
   [2021/03/03 09:27:12:1901] U: callback_http: HTTP_BODY
   [2021/03/03 09:27:12:1901] N:
   [2021/03/03 09:27:12:1901] N: 0000: 7B 22 61 70 70 6C 69 63 61 74 69 6F
   6E 49 44 22 {"applicationID"
   [2021/03/03 09:27:12:1901] N: 0010: 3A 22 32 22 2C 22 61 70 70 6C 69 63
   61 74 69 6F :"2","applicatio
   [2021/03/03 09:27:12:1902] N: 0020: 6E 4E 61 6D 65 22 3A 22 73 74 6D 57
   4C 61 70 70 nName":"stmWLapp
   [2021/03/03 09:27:12:1902] N: 0030: 22 2C 22 64 65 76 69 63 65 4E 61 6D
   65 22 3A 22 ","deviceName":"
   [2021/03/03 09:27:12:1902] N: 0040: 53 54 4D 33 32 57 4C 65 6E 64 6E 6F
   64 65 22 2C STM32WLendnode",
   [2021/03/03 09:27:12:1902] N: 0050: 22 64 65 76 45 55 49 22 3A 22 41 49
   44 68 46 51 "devEUI":"AIDhFQ
   [2021/03/03 09:27:12:1902] N: 0060: 55 41 58 69 34 3D 22 2C 22 72 78 49
   6E 66 6F 22 UAXi4=","rxInfo"
   [2021/03/03 09:27:12:1902] N: 0070: 3A 5B 7B 22 67 61 74 65 77 61 79 49
   44 22 3A 22 :[{"gatewayID":"
   [2021/03/03 09:27:12:1902] N: 0080: 71 45 42 42 48 73 32 73 51 56 41 3D
   22 2C 22 74 qEBBHs2sQVA=","t
   [2021/03/03 09:27:12:1902] N: 0090: 69 6D 65 22 3A 22 32 30 32 31 2D 30
   32 2D 32 35 ime":"2021-02-25
   [2021/03/03 09:27:12:1903] N: 00A0: 54 31 30 3A 32 37 3A 31 31 2E 32 33
   34 33 37 31 T10:27:11.234371
   [2021/03/03 09:27:12:1903] N: 00B0: 5A 22 2C 22 74 69 6D 65 53 69 6E 63
   65 47 50 53 Z","timeSinceGPS
   [2021/03/03 09:27:12:1903] N: 00C0: 45 70 6F 63 68 22 3A 6E 75 6C 6C 2C
   22 72 73 73 Epoch":null,"rss
   [2021/03/03 09:27:12:1903] N: 00D0: 69 22 3A 2D 38 34 2C 22 6C 6F 52 61
   53 4E 52 22 i":-84,"loRaSNR"
   [2021/03/03 09:27:12:1903] N: 00E0: 3A 39 2C 22 63 68 61 6E 6E 65 6C 22
   3A 34 2C 22 :9,"channel":4,"
   [2021/03/03 09:27:12:1903] N: 00F0: 72 66 43 68 61 69 6E 22 3A 30 2C 22
   62 6F 61 72 rfChain":0,"boar
   [2021/03/03 09:27:12:1903] N: 0100: 64 22 3A 30 2C 22 61 6E 74 65 6E 6E
   61 22 3A 30 d":0,"antenna":0
   [2021/03/03 09:27:12:1903] N: 0110: 2C 22 6C 6F 63 61 74 69 6F 6E 22 3A
   7B 22 6C 61 ,"location":{"la
   [2021/03/03 09:27:12:1903] N: 0120: 74 69 74 75 64 65 22 3A 30 2C 22 6C
   6F 6E 67 69 titude":0,"longi
   [2021/03/03 09:27:12:1903] N: 0130: 74 75 64 65 22 3A 30 2C 22 61 6C 74
   69 74 75 64 tude":0,"altitud
   [2021/03/03 09:27:12:1903] N: 0140: 65 22 3A 33 30 30 2C 22 73 6F 75 72
   63 65 22 3A e":300,"source":
   [2021/03/03 09:27:12:1904] N: 0150: 22 55 4E 4B 4E 4F 57 4E 22 2C 22 61
   63 63 75 72 "UNKNOWN","accur
   [2021/03/03 09:27:12:1904] N: 0160: 61 63 79 22 3A 30 7D 2C 22 66 69 6E
   65 54 69 6D acy":0},"fineTim
   [2021/03/03 09:27:12:1904] N: 0170: 65 73 74 61 6D 70 54 79 70 65 22 3A
   22 4E 4F 4E estampType":"NON
   [2021/03/03 09:27:12:1904] N: 0180: 45 22 2C 22 63 6F 6E 74 65 78 74 22
   3A 22 58 73 E","context":"Xs
   [2021/03/03 09:27:12:1904] N: 0190: 7A 6C 41 77 3D 3D 22 2C 22 75 70 6C
   69 6E 6B 49 zlAw==","uplinkI
   [2021/03/03 09:27:12:1904] N: 01A0: 44 22 3A 22 6C 66 64 33 69 70 61 52
   53 2F 36 64 D":"lfd3ipaRS/6d
   [2021/03/03 09:27:12:1904] N: 01B0: 54 70 33 4A 6A 7A 43 52 68 51 3D 3D
   22 2C 22 63 Tp3JjzCRhQ==","c
   [2021/03/03 09:27:12:1904] N: 01C0: 72 63 53 74 61 74 75 73 22 3A 22 43
   52 43 5F 4F rcStatus":"CRC_O
   [2021/03/03 09:27:12:1904] N: 01D0: 4B 22 7D 5D 2C 22 74 78 49 6E 66 6F
   22 3A 7B 22 K"}],"txInfo":{"
   [2021/03/03 09:27:12:1904] N: 01E0: 66 72 65 71 75 65 6E 63 79 22 3A 38
   36 37 33 30 frequency":86730
   [2021/03/03 09:27:12:1904] N: 01F0: 30 30 30 30 2C 22 6D 6F 64 75 6C 61
   74 69 6F 6E 0000,"modulation
   [2021/03/03 09:27:12:1905] N: 0200: 22 3A 22 4C 4F 52 41 22 2C 22 6C 6F
   52 61 4D 6F ":"LORA","loRaMo
   [2021/03/03 09:27:12:1905] N: 0210: 64 75 6C 61 74 69 6F 6E 49 6E 66 6F
   22 3A 7B 22 dulationInfo":{"
   [2021/03/03 09:27:12:1905] N: 0220: 62 61 6E 64 77 69 64 74 68 22 3A 31
   32 35 2C 22 bandwidth":125,"
   [2021/03/03 09:27:12:1905] N: 0230: 73 70 72 65 61 64 69 6E 67 46 61 63
   74 6F 72 22 spreadingFactor"
   [2021/03/03 09:27:12:1905] N: 0240: 3A 37 2C 22 63 6F 64 65 52 61 74 65
   22 3A 22 34 :7,"codeRate":"4
   [2021/03/03 09:27:12:1905] N: 0250: 2F 35 22 2C 22 70 6F 6C 61 72 69 7A
   61 74 69 6F /5","polarizatio
   [2021/03/03 09:27:12:1905] N: 0260: 6E 49 6E 76 65 72 73 69 6F 6E 22 3A
   66 61 6C 73 nInversion":fals
   [2021/03/03 09:27:12:1905] N: 0270: 65 7D 7D 2C 22 61 64 72 22 3A 74 72
   75 65 2C 22 e}},"adr":true,"
   [2021/03/03 09:27:12:1905] N: 0280: 64 72 22 3A 35 2C 22 66 43 6E 74 22
   3A 31 31 37 dr":5,"fCnt":117
   [2021/03/03 09:27:12:1905] N: 0290: 35 2C 22 66 50 6F 72 74 22 3A 32 2C
   22 64 61 74 5,"fPort":2,"dat
   [2021/03/03 09:27:12:1905] N: 02A0: 61 22 3A 22 41 47 63 41 33 41 45 43
   41 41 41 43 a":"AGcA3AECAAAC
   [2021/03/03 09:27:12:1905] N: 02B0: 41 50 34 44 41 41 51 45 41 51 41 3D
   22 2C 22 6F AP4DAAQEAQA=","o
   [2021/03/03 09:27:12:1905] N: 02C0: 62 6A 65 63 74 4A 53 4F 4E 22 3A 22
   7B 5C 22 64 bjectJSON":"{\"d
   [2021/03/03 09:27:12:1906] N: 02D0: 69 67 69 74 61 6C 49 6E 70 75 74 5C
   22 3A 7B 5C igitalInput\":{\
   [2021/03/03 09:27:12:1906] N: 02E0: 22 32 5C 22 3A 32 35 34 2C 5C 22 33
   5C 22 3A 34 "2\":254,\"3\":4
   [2021/03/03 09:27:12:1906] N: 02F0: 7D 2C 5C 22 64 69 67 69 74 61 6C 4F
   75 74 70 75 },\"digitalOutpu
   [2021/03/03 09:27:12:1906] N: 0300: 74 5C 22 3A 7B 5C 22 34 5C 22 3A 30
   7D 2C 5C 22 t\":{\"4\":0},\"
   [2021/03/03 09:27:12:1906] N: 0310: 61 6E 61 6C 6F 67 49 6E 70 75 74 5C
   22 3A 7B 5C analogInput\":{\
   [2021/03/03 09:27:12:1906] N: 0320: 22 31 5C 22 3A 30 7D 2C 5C 22 74 65
   6D 70 65 72 "1\":0},\"temper
   [2021/03/03 09:27:12:1906] N: 0330: 61 74 75 72 65 53 65 6E 73 6F 72 5C
   22 3A 7B 5C atureSensor\":{\
   [2021/03/03 09:27:12:1906] N: 0340: 22 30 5C 22 3A 32 32 7D 7D 22 2C 22
   74 61 67 73 "0\":22}}","tags
   [2021/03/03 09:27:12:1906] N: 0350: 22 3A 7B 7D 2C 22 63 6F 6E 66 69 72
   6D 65 64 55 ":{},"confirmedU
   [2021/03/03 09:27:12:1906] N: 0360: 70 6C 69 6E 6B 22 3A 66 61 6C 73 65
   2C 22 64 65 plink":false,"de
   [2021/03/03 09:27:12:1906] N: 0370: 76 41 64 64 72 22 3A 22 4C 2F 7A 61
   63 51 3D 3D vAddr":"L/zacQ==
   [2021/03/03 09:27:12:1906] N: 0380: 22 7D
   "}
   [2021/03/03 09:27:12:1906] N:
   [2021/03/03 09:27:12:1907] U: LWS_CALLBACK_HTTP_BODY_COMPLETION

   ie, at least on main, no problem with your packet.

   -Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20210303/4b1e4d29/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lws-callbacks2string.h
Type: text/x-chdr
Size: 5787 bytes
Desc: not available
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20210303/4b1e4d29/attachment-0001.bin>


More information about the Libwebsockets mailing list