[Libwebsockets] POST messages callbacks

Andy Green andy at warmcat.com
Wed Mar 3 10:31:41 CET 2021



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 --------------
POST /form1?event=up HTTP/1.1
Host: 192.168.1.42:7681
User-Agent: Go-http-client/1.1
Content-Length: 898
Content-Type: application/json
Accept-Encoding: gzip

{"applicationID":"2","applicationName":"stmWLapp","deviceName":"STM32WLendnode","devEUI":"AIDhFQUAXi4=","rxInfo":[{"gatewayID":"qEBBHs2sQVA=","time":"2021-02-25T10:27:11.234371Z","timeSinceGPSEpoch":null,"rssi":-84,"loRaSNR":9,"channel":4,"rfChain":0,"board":0,"antenna":0,"location":{"latitude":0,"longitude":0,"altitude":300,"source":"UNKNOWN","accuracy":0},"fineTimestampType":"NONE","context":"XszlAw==","uplinkID":"lfd3ipaRS/6dTp3JjzCRhQ==","crcStatus":"CRC_OK"}],"txInfo":{"frequency":867300000,"modulation":"LORA","loRaModulationInfo":{"bandwidth":125,"spreadingFactor":7,"codeRate":"4/5","polarizationInversion":false}},"adr":true,"dr":5,"fCnt":1175,"fPort":2,"data":"AGcA3AECAAACAP4DAAQEAQA=","objectJSON":"{\"digitalInput\":{\"2\":254,\"3\":4},\"digitalOutput\":{\"4\":0},\"analogInput\":{\"1\":0},\"temperatureSensor\":{\"0\":22}}","tags":{},"confirmedUplink":false,"devAddr":"L/zacQ=="}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: example-hack.diff
Type: text/x-patch
Size: 950 bytes
Desc: not available
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20210303/103ebf22/attachment.bin>


More information about the Libwebsockets mailing list