Clean up some HTTP client stuff.

This commit is contained in:
Jordan Bancino 2023-04-01 02:13:41 +00:00
parent 7b3d537175
commit e592840c99
2 changed files with 16 additions and 3 deletions

View file

@ -150,7 +150,7 @@ HttpRequest(HttpRequestMethod method, int flags, unsigned short port, char *host
return NULL; return NULL;
} }
StreamPrintf(context->stream, "%s %s HTTP/1.1\r\n", StreamPrintf(context->stream, "%s %s HTTP/1.0\r\n",
HttpRequestMethodToString(method), path); HttpRequestMethodToString(method), path);
HttpRequestHeader(context, "Connection", "close"); HttpRequestHeader(context, "Connection", "close");

View file

@ -155,7 +155,6 @@ main(int argc, char **argv)
Free(val); Free(val);
} }
HttpRequestSendHeaders(cx);
HashMapFree(requestHeaders); HashMapFree(requestHeaders);
if (data) if (data)
@ -181,15 +180,29 @@ main(int argc, char **argv)
return 1; return 1;
} }
HttpRequestSendHeaders(cx);
StreamCopy(in, HttpClientStream(cx)); StreamCopy(in, HttpClientStream(cx));
StreamClose(in); StreamClose(in);
} }
else else
{ {
char *lenStr;
int len = strlen(data);
int nBytes = snprintf(NULL, 0, "%d", len);
lenStr = Malloc(nBytes + 1);
snprintf(lenStr, nBytes + 1, "%d", len);
HttpRequestHeader(cx, "Content-Length", lenStr);
Free(lenStr);
HttpRequestSendHeaders(cx);
StreamPuts(HttpClientStream(cx), data); StreamPuts(HttpClientStream(cx), data);
} }
} }
else
{
HttpRequestSendHeaders(cx);
}
res = HttpRequestSend(cx); res = HttpRequestSend(cx);