Skip to content
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

Is there a way to parse HTTP headers following a esp_http_client_fetch_headers() call (IDFGH-14204) #15002

Open
Dazza0 opened this issue Dec 9, 2024 · 3 comments
Labels
Status: Opened Issue is new Type: Feature Request Feature request for IDF

Comments

@Dazza0
Copy link
Contributor

Dazza0 commented Dec 9, 2024

Is your feature request related to a problem?

Hi, I'm currently trying to do a native HTTP request using the esp_http_client.h API i.e., without calling the esp_http_perform() function (similar to the http_native_request() function in the esp_http_client example. The reason being that I want to manually fetch headers and parse them, before conditionally sending a GET request for the actual data payload.

However, after calling esp_http_client_fetch_headers() to fetch the headers, the esp_http_client.h API doesn't provide a way to access the buffer storing the headers.

Is there a recommended way to get access to those headers and parse them?

Describe the solution you'd like.

No response

Describe alternatives you've considered.

No response

Additional context.

No response

@Dazza0 Dazza0 added the Type: Feature Request Feature request for IDF label Dec 9, 2024
@github-actions github-actions bot changed the title Is there a way to parse HTTP headers following a esp_http_client_fetch_headers() call Is there a way to parse HTTP headers following a esp_http_client_fetch_headers() call (IDFGH-14204) Dec 9, 2024
@espressif-bot espressif-bot added the Status: Opened Issue is new label Dec 9, 2024
@nopnop2002
Copy link

nopnop2002 commented Dec 10, 2024

Is this no good?
https://github.com/espressif/esp-idf/tree/master/examples/protocols/http_request

You can get HTTP headers.

HTTP/1.0 200 OK
Accept-Ranges: bytes
Age: 372137
Cache-Control: max-age=604800
Content-Type: text/html
Date: Tue, 10 Dec 2024 02:05:49 GMT
Etag: "3147526947"
Expires: Tue, 17 Dec 2024 02:05:49 GMT
Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
Server: ECAcc (lac/5598)
Vary: Accept-Encoding
X-Cache: HIT
Content-Length: 1256
Connection: close

You can still get the header with this.
https://github.com/espressif/esp-idf/tree/v5.3.2/examples/protocols/esp_http_client

I (9666) HTTP: HTTP_EVENT_ON_HEADER, key=Content-Type, value=application/rss+xml
I (9666) HTTP: HTTP_EVENT_ON_HEADER, key=Server, value=Apache/2.4.37 (Rocky Linux) OpenSSL/1.1.1k
I (9666) HTTP: HTTP_EVENT_ON_HEADER, key=ETag, value="b6752d053f69b6ed4c117feead10316d8937aad89bf27ee230b50b55a09f33a0"
I (9686) HTTP: HTTP_EVENT_ON_HEADER, key=Access-Control-Allow-Origin, value=*
I (9686) HTTP: HTTP_EVENT_ON_HEADER, key=expiry_extended_seconds, value=0
I (9696) HTTP: HTTP_EVENT_ON_HEADER, key=Cache-Control, value=no-transform, max-age=120
I (9706) HTTP: HTTP_EVENT_ON_HEADER, key=Date, value=Tue, 10 Dec 2024 02:34:07 GMT
I (9716) HTTP: HTTP_EVENT_ON_HEADER, key=Content-Length, value=3545
I (9716) HTTP: HTTP_EVENT_ON_HEADER, key=Connection, value=keep-alive

@Dazza0
Copy link
Contributor Author

Dazza0 commented Dec 10, 2024

@nopnop2002

Is this no good?
https://github.com/espressif/esp-idf/tree/master/examples/protocols/http_request

That also works, but that would be operating at a lower level of abstraction. I was hoping to operate that the ESP HTTP Client layer where TLS is handled.

You can still get the header with this.
https://github.com/espressif/esp-idf/tree/v5.3.2/examples/protocols/esp_http_client

I (9666) HTTP: HTTP_EVENT_ON_HEADER, key=Content-Type, value=application/rss+xml
I (9666) HTTP: HTTP_EVENT_ON_HEADER, key=Server, value=Apache/2.4.37 (Rocky Linux) OpenSSL/1.1.1k
I (9666) HTTP: HTTP_EVENT_ON_HEADER, key=ETag, value="b6752d053f69b6ed4c117feead10316d8937aad89bf27ee230b50b55a09f33a0"
I (9686) HTTP: HTTP_EVENT_ON_HEADER, key=Access-Control-Allow-Origin, value=*
I (9686) HTTP: HTTP_EVENT_ON_HEADER, key=expiry_extended_seconds, value=0
I (9696) HTTP: HTTP_EVENT_ON_HEADER, key=Cache-Control, value=no-transform, max-age=120
I (9706) HTTP: HTTP_EVENT_ON_HEADER, key=Date, value=Tue, 10 Dec 2024 02:34:07 GMT
I (9716) HTTP: HTTP_EVENT_ON_HEADER, key=Content-Length, value=3545
I (9716) HTTP: HTTP_EVENT_ON_HEADER, key=Connection, value=keep-alive

Is that done via the esp_http_client_perform() function?

@nopnop2002
Copy link

Is that done via the esp_http_client_perform() function?

Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new Type: Feature Request Feature request for IDF
Projects
None yet
Development

No branches or pull requests

3 participants