#pragma once #include #include #include #include "esp_err.h" // Small blocking HTTP/1.x GET client on raw sockets. Unlike esp_http_client it // happily streams bodies with no Content-Length (MJPEG cameras, HTTP/1.0 servers), // de-chunks chunked bodies and follows a few redirects. typedef struct { int fd; int status; bool chunked; int64_t content_length; // -1 when unknown int64_t body_read; char content_type[80]; char host[128]; uint16_t port; uint8_t *buf; // receive buffer size_t cap, len, pos; int64_t chunk_left; bool eof; int rx_timeout_ms; } httpstream_t; #define HTTPSTREAM_EOF 0 #define HTTPSTREAM_ERR (-1) #define HTTPSTREAM_TIMEOUT (-2) esp_err_t httpstream_open(httpstream_t *s, const char *url, const char *user_agent, int connect_timeout_ms, int rx_timeout_ms); // Returns bytes copied (>0), HTTPSTREAM_EOF, HTTPSTREAM_ERR or HTTPSTREAM_TIMEOUT. int httpstream_read(httpstream_t *s, uint8_t *out, size_t n); void httpstream_close(httpstream_t *s);