aboutsummaryrefslogtreecommitdiff
path: root/src/http.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/http.lua')
-rw-r--r--src/http.lua10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/http.lua b/src/http.lua
index 3a386a6..4c27149 100644
--- a/src/http.lua
+++ b/src/http.lua
@@ -13,6 +13,7 @@ local url = require("socket.url")
13local ltn12 = require("ltn12") 13local ltn12 = require("ltn12")
14local mime = require("mime") 14local mime = require("mime")
15local string = require("string") 15local string = require("string")
16local headers = require("socket.headers")
16local base = _G 17local base = _G
17local table = require("table") 18local table = require("table")
18module("socket.http") 19module("socket.http")
@@ -123,10 +124,11 @@ function metat.__index:sendrequestline(method, uri)
123 return self.try(self.c:send(reqline)) 124 return self.try(self.c:send(reqline))
124end 125end
125 126
126function metat.__index:sendheaders(headers) 127function metat.__index:sendheaders(tosend)
128 local canonic = headers.canonic
127 local h = "\r\n" 129 local h = "\r\n"
128 for i, v in base.pairs(headers) do 130 for f, v in base.pairs(tosend) do
129 h = i .. ": " .. v .. "\r\n" .. h 131 h = (canonic[f] or f) .. ": " .. v .. "\r\n" .. h
130 end 132 end
131 self.try(self.c:send(h)) 133 self.try(self.c:send(h))
132 return 1 134 return 1
@@ -254,7 +256,7 @@ local function shouldredirect(reqt, code, headers)
254 return headers.location and 256 return headers.location and
255 string.gsub(headers.location, "%s", "") ~= "" and 257 string.gsub(headers.location, "%s", "") ~= "" and
256 (reqt.redirect ~= false) and 258 (reqt.redirect ~= false) and
257 (code == 301 or code == 302) and 259 (code == 301 or code == 302 or code == 303 or code == 307) and
258 (not reqt.method or reqt.method == "GET" or reqt.method == "HEAD") 260 (not reqt.method or reqt.method == "GET" or reqt.method == "HEAD")
259 and (not reqt.nredirects or reqt.nredirects < 5) 261 and (not reqt.nredirects or reqt.nredirects < 5)
260end 262end