net: http: dont timeout on HTTP requests w/o body
A TCP FIN message is passed on to user apps as a tcp_received_callback with a NULL pkt parameter. This means the connection is closing and the app should do whatever cleanup it needs as there will be no further callbacks for the current TCP connection. Currently, if a HTTP client request doesn't receive a "body" which the HTTP parser can use to trigger on_message_complete, then the request will end up timing out and most apps will think an error has occurred. Instead, let's handle the TCP FIN message and return the waiting semaphore, leaving the app to deal with whatever has been set in the current HTTP context response data (IE: http_status). This fixes using HTTP client to send POST data to servers which only respond with HTTP_OK status and no body. Signed-off-by: Michael Scott <michael.scott@linaro.org>
This commit is contained in:
parent
0592c0ce59
commit
8ebaf29927
1 changed files with 14 additions and 0 deletions
|
@ -489,6 +489,20 @@ static void recv_cb(struct net_context *net_ctx, struct net_pkt *pkt,
|
|||
}
|
||||
|
||||
if (!pkt || net_pkt_appdatalen(pkt) == 0) {
|
||||
/*
|
||||
* This block most likely handles a TCP_FIN message.
|
||||
* (this means the connection is now closed)
|
||||
* If we get here, and req.wait.count is still 0 this means
|
||||
* http client is still waiting to parse a response body.
|
||||
* This will will never happen now. Instead of generating
|
||||
* an ETIMEDOUT error in the future, let's unlock the
|
||||
* req.wait semaphore and let the app deal with whatever
|
||||
* data was parsed in the header (IE: http status, etc).
|
||||
*/
|
||||
if (ctx->req.wait.count == 0) {
|
||||
k_sem_give(&ctx->req.wait);
|
||||
}
|
||||
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue