WIP: bug hunting: get complete body!

This commit is contained in:
Martin Brodbeck 2023-01-03 17:04:37 +01:00
parent d09eb43ddf
commit 132b8d49fe
2 changed files with 21 additions and 13 deletions

View file

@ -1,6 +1,8 @@
#include "http_client.h"
/*
#include <iostream>
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;
}

View file

@ -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: