From bd656efd644da12f540aff2e4d871ebebd0edb8a Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 16 Feb 2018 12:29:40 +0100 Subject: [PATCH] http client: add https support, fix parsing header with chained pbufs --- src/apps/http/http_client.c | 12 +++++++++++- src/include/lwip/apps/http_client.h | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/apps/http/http_client.c b/src/apps/http/http_client.c index 50266103..b62dad4b 100644 --- a/src/apps/http/http_client.c +++ b/src/apps/http/http_client.c @@ -288,7 +288,7 @@ httpc_tcp_recv(void *arg, struct altcp_pcb *pcb, struct pbuf *p, err_t r) } if (req->parse_state == HTTPC_PARSE_WAIT_HEADERS) { u16_t total_header_len; - err_t err = http_wait_headers(p, &req->hdr_content_len, &total_header_len); + err_t err = http_wait_headers(req->rx_hdrs, &req->hdr_content_len, &total_header_len); if (err == ERR_OK) { /* hide header bytes in pbuf */ struct pbuf *q; @@ -536,6 +536,16 @@ httpc_init_connection_common(httpc_state_t **connection, const httpc_connection_ httpc_free_state(req); return ERR_MEM; } +#if LWIP_ALTCP_TLS + if (settings->tls_config) { + struct altcp_pcb *pcbs = altcp_tls_new(settings->tls_config, req->pcb); + if (pcbs == NULL) { + httpc_free_state(req); + return ERR_MEM; + } + req->pcb = pcbs; + } +#endif req->remote_port = settings->use_proxy ? settings->proxy_port : server_port; altcp_arg(req->pcb, req); altcp_recv(req->pcb, httpc_tcp_recv); diff --git a/src/include/lwip/apps/http_client.h b/src/include/lwip/apps/http_client.h index a667df95..26385124 100644 --- a/src/include/lwip/apps/http_client.h +++ b/src/include/lwip/apps/http_client.h @@ -109,6 +109,10 @@ typedef struct _httpc_connection { u8_t use_proxy; /* @todo: add username:pass? */ +#if LWIP_ALTCP_TLS + struct altcp_tls_config *tls_config; +#endif + /* this callback is called when the transfer is finished (or aborted) */ httpc_result_fn result_fn; /* this callback is called after receiving the http headers