From 132b8d49fecedc1443c38082670e95f25e78a089 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Tue, 3 Jan 2023 17:04:37 +0100 Subject: [PATCH] WIP: bug hunting: get complete body! --- src/http_client.cpp | 25 ++++++++++++++++--------- src/http_client.h | 9 +++++---- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/http_client.cpp b/src/http_client.cpp index 347b3bb..347696f 100644 --- a/src/http_client.cpp +++ b/src/http_client.cpp @@ -1,6 +1,8 @@ #include "http_client.h" -/* +#include + + void result_callback(void *arg, httpc_result_t httpc_result, u32_t rx_content_len, u32_t srv_res, err_t err) { printf("Transfer complete\n"); @@ -14,19 +16,24 @@ err_t headers_callback(httpc_state_t *connection, void *arg, struct pbuf *hdr, u printf("Content length=%d\n", content_len); printf("Header length=%d\n", hdr_len); - pbuf_copy_partial(hdr, myBuffer, hdr->tot_len, 0); + pbuf_copy_partial(hdr, myHeaderBuffer, hdr->tot_len, 0); printf("Headers \n"); - printf("%s", myBuffer); + printf("%s", myHeaderBuffer); return ERR_OK; } -*/ + err_t body_callback(void *arg, struct altcp_pcb *conn, struct pbuf *p, err_t err) { bool *received = (bool *)arg; - pbuf_copy_partial(p, myBuffer, p->tot_len, 0); - // printf("%s", myBuffer); + if (err != ERR_OK) { + printf("PROBLEM!!\n"); + return err; + } + + pbuf_copy_partial(p, myBodyBuffer, p->tot_len, 0); + printf("HUHU:\n%s", myBodyBuffer); *received = true; @@ -35,8 +42,8 @@ err_t body_callback(void *arg, struct altcp_pcb *conn, struct pbuf *p, err_t err HttpClient::HttpClient() { m_settings.use_proxy = false; - m_settings.result_fn = nullptr; // result_callback; - m_settings.headers_done_fn = nullptr; // headers_callback; + m_settings.result_fn = result_callback; // result_callback; + m_settings.headers_done_fn = headers_callback; // headers_callback; } std::string HttpClient::retrieveWasteDatesAsCsv() { @@ -62,7 +69,7 @@ std::string HttpClient::retrieveWasteDatesAsCsv() { sleep_ms(1000); } - result.append(myBuffer); + result.append(myBodyBuffer); return result; } \ No newline at end of file diff --git a/src/http_client.h b/src/http_client.h index cc8d2d0..2113c42 100644 --- a/src/http_client.h +++ b/src/http_client.h @@ -6,15 +6,16 @@ #include "pico/cyw43_arch.h" //#include "pico/stdlib.h" -static char myBuffer[2048]; +static char myHeaderBuffer[2048]; +static char myBodyBuffer[2048]; -extern "C" void result_callback(void *arg, httpc_result_t httpc_result, u32_t rx_content_len, +void result_callback(void *arg, httpc_result_t httpc_result, u32_t rx_content_len, u32_t srv_res, err_t err); -extern "C" err_t headers_callback(httpc_state_t *connection, void *arg, struct pbuf *hdr, +err_t headers_callback(httpc_state_t *connection, void *arg, struct pbuf *hdr, u16_t hdr_len, u32_t content_len); -extern "C" err_t body_callback(void *arg, struct altcp_pcb *conn, struct pbuf *p, err_t err); +err_t body_callback(void *arg, struct altcp_pcb *conn, struct pbuf *p, err_t err); class HttpClient { public: