Skip to content

Commit 8f42a68

Browse files
committed
Always finish headers if a request body is provided to startRequest
1 parent f56eecb commit 8f42a68

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

HttpClient.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,19 @@ int HttpClient::startRequest(const char* aURLPath, const char* aHttpMethod,
118118
sendHeader(HTTP_HEADER_CONTENT_LENGTH, aContentLength);
119119
}
120120

121-
if ((initialState == eIdle))
121+
bool hasBody = (aBody && aContentLength > 0);
122+
123+
if (initialState == eIdle || hasBody)
122124
{
123125
// This was a simple version of the API, so terminate the headers now
124126
finishHeaders();
127+
}
128+
// else we'll call it in endRequest or in the first call to print, etc.
125129

126-
if (aBody && aContentLength > 0)
127-
{
130+
if (hasBody)
131+
{
128132
write(aBody, aContentLength);
129-
}
130133
}
131-
// else we'll call it in endRequest or in the first call to print, etc.
132134
}
133135

134136
return ret;

HttpClient.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class HttpClient : public Client
7575
int post(const char* aURLPath);
7676
int post(const String& aURLPath);
7777

78-
/** Connect to the server and start to send a POST request
78+
/** Connect to the server and send a POST request
7979
with body and content type
8080
@param aURLPath Url to request
8181
@param aContentType Content type of request body
@@ -93,7 +93,7 @@ class HttpClient : public Client
9393
int put(const char* aURLPath);
9494
int put(const String& aURLPath);
9595

96-
/** Connect to the server and start to send a PUT request
96+
/** Connect to the server and send a PUT request
9797
with body and content type
9898
@param aURLPath Url to request
9999
@param aContentType Content type of request body
@@ -111,7 +111,7 @@ class HttpClient : public Client
111111
int del(const char* aURLPath);
112112
int del(const String& aURLPath);
113113

114-
/** Connect to the server and start to send a DELETE request
114+
/** Connect to the server and send a DELETE request
115115
with body and content type
116116
@param aURLPath Url to request
117117
@param aContentType Content type of request body
@@ -123,6 +123,7 @@ class HttpClient : public Client
123123
int del(const char* aURLPath, const char* aContentType, int aContentLength, const byte aBody[]);
124124

125125
/** Connect to the server and start to send the request.
126+
If a body is provided, the entire request (including headers and body) will be sent
126127
@param aURLPath Url to request
127128
@param aHttpMethod Type of HTTP request to make, e.g. "GET", "POST", etc.
128129
@param aContentType Content type of request body (optional)

0 commit comments

Comments
 (0)