From 4a3504612cda28f25ab777db94bfeab55e081e16 Mon Sep 17 00:00:00 2001 From: xyida <522918670@qq.com> Date: Thu, 26 Apr 2018 16:39:29 +0800 Subject: [PATCH] Fixed an issue that was mistaken for HTTP 0.9 when timeout --- src/http.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/http.lua b/src/http.lua index a386165..79a931c 100644 --- a/src/http.lua +++ b/src/http.lua @@ -147,10 +147,15 @@ function metat.__index:sendbody(headers, source, step) end function metat.__index:receivestatusline() - local status = self.try(self.c:receive(5)) + local status,ec = self.try(self.c:receive(5)) -- identify HTTP/0.9 responses, which do not contain a status line -- this is just a heuristic, but is what the RFC recommends - if status ~= "HTTP/" then return nil, status end + if status ~= "HTTP/" then + if ec == "timeout" then + return 408 + end + return nil, status + end -- otherwise proceed reading a status line status = self.try(self.c:receive("*l", status)) local code = socket.skip(2, string.find(status, "HTTP/%d*%.%d* (%d%d%d)")) @@ -325,6 +330,8 @@ end if not code then h:receive09body(status, nreqt.sink, nreqt.step) return 1, 200 + elseif code == 408 then + return 1, code end local headers -- ignore any 100-continue messages