From 75d9b07158510f4d1315edefe860bcdf7b0fd2f7 Mon Sep 17 00:00:00 2001 From: HuaYang Huang Date: Wed, 29 Apr 2015 20:18:13 +0800 Subject: [PATCH] fix: httpc.get MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit :-( 此错误会导致httpc.get无法找到正确的虚拟主机 --- lualib/http/httpc.lua | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lualib/http/httpc.lua b/lualib/http/httpc.lua index a8b7d6f8..ae771dc8 100644 --- a/lualib/http/httpc.lua +++ b/lualib/http/httpc.lua @@ -11,23 +11,21 @@ local function request(fd, method, host, url, recvheader, header, content) local write = socket.writefunc(fd) local header_content = "" if header then + if not header.host then + header.host = host + end for k,v in pairs(header) do header_content = string.format("%s%s:%s\r\n", header_content, k, v) end - if header.host then - host = "" - else - host = string.format("host:%s\r\n", host) - end else - host = string.format("host:%s\r\n",host) + header_content = string.format("host:%s\r\n",host) end if content then - local data = string.format("%s %s HTTP/1.1\r\n%scontent-length:%d\r\n%s\r\n%s", method, url, host, #content, header_content, content) + local data = string.format("%s %s HTTP/1.1\r\n%scontent-length:%d\r\n\r\n%s", method, url, header_content, #content, content) write(data) else - local request_header = string.format("%s %s HTTP/1.1\r\nhost:%s\r\ncontent-length:0\r\n%s\r\n", method, url, host, header_content) + local request_header = string.format("%s %s HTTP/1.1\r\n%scontent-length:0\r\n\r\n", method, url, header_content) write(request_header) end