diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2009-05-27 09:31:38 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2009-05-27 09:31:38 +0000 |
| commit | bce60be30fe8e9c1b0eb33128c23c93d7bca5303 (patch) | |
| tree | 3927343c777fcb7764a0f2f89754a0ceab141c21 /src/http.lua | |
| parent | d1a72435d5bd3528f3c334cd4d1da16dcead47bf (diff) | |
| download | luasocket-bce60be30fe8e9c1b0eb33128c23c93d7bca5303.tar.gz luasocket-bce60be30fe8e9c1b0eb33128c23c93d7bca5303.tar.bz2 luasocket-bce60be30fe8e9c1b0eb33128c23c93d7bca5303.zip | |
Decent makefiles!
Diffstat (limited to 'src/http.lua')
| -rw-r--r-- | src/http.lua | 10 |
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") | |||
| 13 | local ltn12 = require("ltn12") | 13 | local ltn12 = require("ltn12") |
| 14 | local mime = require("mime") | 14 | local mime = require("mime") |
| 15 | local string = require("string") | 15 | local string = require("string") |
| 16 | local headers = require("socket.headers") | ||
| 16 | local base = _G | 17 | local base = _G |
| 17 | local table = require("table") | 18 | local table = require("table") |
| 18 | module("socket.http") | 19 | module("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)) |
| 124 | end | 125 | end |
| 125 | 126 | ||
| 126 | function metat.__index:sendheaders(headers) | 127 | function 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) |
| 260 | end | 262 | end |
