u-blox / ubxlib

Portable C libraries which provide APIs to build applications with u-blox products and services. Delivered as add-on to existing microcontroller and RTOS SDKs.
Apache License 2.0
287 stars 82 forks source link

HTTPlib not correctly parsing headers #162

Closed arnoutdekimo closed 8 months ago

arnoutdekimo commented 8 months ago

Hi,

I am running the assistnow example, and trying to use the httplib to parse the result of offline data. This -sometimes- works, but sometimes the API returns length 0, and sometimes it even returns wrong data.

(EDIT -- this is wrong -- see posts below ) _When further looking into the library code, and sniffing the UART bus, I noticed the following:

This is an incorrect way of parsing the data though. Note in what the first 64 bytes look like in my case:

image

The content-length header is already in there, and is cut in half. Meaning the subsequent parsing trying to find this length fails.

The correct way of parsing, is to read out chunks, and -bundle these-, and only discard the amount of data that is already parsed. In this case the bug is that in the first 64bytes useful data remained that was lost. It should have been appended to the subsequent data until all headers were found.

Depending on how fast data comes in over the bus, encapsulation methods (CMUX or not), how big the headers are, etc, this code might and might not have worked._

Kind regards, Arnout

arnoutdekimo commented 8 months ago

I seem to be wrong - the code reads from a file, at a given offset. Hence why it is able to read the same data multiple times..

arnoutdekimo commented 8 months ago

Analysis attempt #2

In the code that reads headers, it reads 1024 bytes from the file at the right offset:

image

It then returns 411 in that function

image

Below in the function, it (in this case) sets the correct length

image

And indeed, this time the code executes correctly. And every time I step through the code with the debugger, it seems to work.

When I don't hit breakpoints.. it does not work anymore, and things get corrupted.

=> Will look into the timing issue, but so never mind the first analysis..

RobMeades commented 8 months ago

You're not having an easy time with this are you? Sorry! Let me know as soon as I can usefully help.

arnoutdekimo commented 8 months ago

Man, ive lost time with this.

Stuff I did:

BUT, I seem to have found the trigger : the CMUX.

I'll make a new issue for this, and close this one, since othertwise this might get too confusing

RobMeades commented 8 months ago

Interesting; we do test running over CMUX, both with just the GNSS-inside-cellular case and more generically "CMUX used all of the time"; obviously not enough.