From 8ebaf29927c29df50488fdd9ef5ea6c8b47c9323 Mon Sep 17 00:00:00 2001 From: Michael Scott Date: Mon, 14 Aug 2017 20:54:36 -0700 Subject: [PATCH] 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 --- subsys/net/lib/http/http_client.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/subsys/net/lib/http/http_client.c b/subsys/net/lib/http/http_client.c index 25f39e3bdf3..0c608a31bd7 100644 --- a/subsys/net/lib/http/http_client.c +++ b/subsys/net/lib/http/http_client.c @@ -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; }