From 7e144ae4881f024c0ca831a1038846d92b076230 Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Wed, 8 Mar 2023 02:53:47 +0000 Subject: [PATCH] Clean up a few bugs in HttpClient and Uri --- TODO.txt | 1 + src/HttpClient.c | 17 ++++++++++++----- src/Uri.c | 2 +- src/include/HttpClient.h | 3 +++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/TODO.txt b/TODO.txt index 26239d5..b009364 100644 --- a/TODO.txt +++ b/TODO.txt @@ -18,6 +18,7 @@ Milestone: v0.3.0 [~] HTTP Client API [ ] Document HttpParseHeaders() [ ] HttpClient man page + [ ] Uia man page [ ] Test on other platforms [ ] Option to pretty-print Json diff --git a/src/HttpClient.c b/src/HttpClient.c index 8d239b1..8967d6c 100644 --- a/src/HttpClient.c +++ b/src/HttpClient.c @@ -75,8 +75,6 @@ HttpRequest(HttpRequestMethod method, int flags, unsigned short port, char *host sprintf(serv, "%hu", port); } - printf("serv = %s\n", serv); - /* TODO: Not supported yet */ if (flags & HTTP_TLS) { @@ -157,6 +155,18 @@ HttpRequestHeader(HttpClientContext * context, char *key, char *val) fprintf(context->stream, "%s: %s\r\n", key, val); } +void +HttpRequestSendHeaders(HttpClientContext * context) +{ + if (!context) + { + return; + } + + fprintf(context->stream, "\r\n"); + fflush(context->stream); +} + HttpStatus HttpRequestSend(HttpClientContext * context) { @@ -172,9 +182,6 @@ HttpRequestSend(HttpClientContext * context) return 0; } - fprintf(context->stream, "\r\n"); - fflush(context->stream); - lineLen = UtilGetLine(&line, &lineSize, context->stream); /* Line must contain at least "HTTP/x.x xxx" */ diff --git a/src/Uri.c b/src/Uri.c index e18f990..ca1ad96 100644 --- a/src/Uri.c +++ b/src/Uri.c @@ -49,7 +49,7 @@ UriParse(const char *str) res = sscanf(str, "%7[^:]://%127[^:]:%hu%255[^\n]", uri->proto, uri->host, &uri->port, uri->path) == 4 || sscanf(str, "%7[^:]://%127[^/]%255[^\n]", uri->proto, uri->host, uri->path) == 3 - || sscanf(str, "%7[^:]://%127[^:]%hu[^\n]", uri->proto, uri->host, &uri->port) == 3 + || sscanf(str, "%7[^:]://%127[^:]:%hu[^\n]", uri->proto, uri->host, &uri->port) == 3 || sscanf(str, "%7[^:]://%127[^\n]", uri->proto, uri->host) == 2; if (!res) diff --git a/src/include/HttpClient.h b/src/include/HttpClient.h index 03b6ad2..f655ad9 100644 --- a/src/include/HttpClient.h +++ b/src/include/HttpClient.h @@ -40,6 +40,9 @@ extern HttpClientContext * extern void HttpRequestHeader(HttpClientContext *, char *, char *); +extern void +HttpRequestSendHeaders(HttpClientContext *); + extern HttpStatus HttpRequestSend(HttpClientContext *);