mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-25 12:08:21 +01:00
http.lua: allow override of hard-coded 5 max redirects
This commit is contained in:
parent
144fa01c2f
commit
09ff9b650c
@ -135,7 +135,8 @@ http.<b>request{</b><br>
|
|||||||
[step = <i>LTN12 pump step</i>,]<br>
|
[step = <i>LTN12 pump step</i>,]<br>
|
||||||
[proxy = <i>string</i>,]<br>
|
[proxy = <i>string</i>,]<br>
|
||||||
[redirect = <i>boolean</i>,]<br>
|
[redirect = <i>boolean</i>,]<br>
|
||||||
[create = <i>function</i>]<br>
|
[create = <i>function</i>,]<br>
|
||||||
|
[maxredirects = <i>number</i>]<br>
|
||||||
<b>}</b>
|
<b>}</b>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@ -185,6 +186,7 @@ Defaults to the LTN12 <tt>pump.step</tt> function.
|
|||||||
function from automatically following 301 or 302 server redirect messages;
|
function from automatically following 301 or 302 server redirect messages;
|
||||||
<li><tt>create</tt>: An optional function to be used instead of
|
<li><tt>create</tt>: An optional function to be used instead of
|
||||||
<a href=tcp.html#socket.tcp><tt>socket.tcp</tt></a> when the communications socket is created.
|
<a href=tcp.html#socket.tcp><tt>socket.tcp</tt></a> when the communications socket is created.
|
||||||
|
<li><tt>maxredirects</tt>: An optional number specifying the maximum number of redirects to follow. Defaults to <tt>5</tt> if not specified. A boolean <tt>false</tt> value means no maximum (unlimited).
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<p class=return>
|
<p class=return>
|
||||||
@ -324,8 +326,8 @@ r, c = http.request {
|
|||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<small>
|
<small>
|
||||||
Last modified by Diego Nehab on <br>
|
Last modified by Eric Westbrook on <br>
|
||||||
Thu Apr 20 00:25:26 EDT 2006
|
Sat Feb 23 19:09:42 UTC 2019
|
||||||
</small>
|
</small>
|
||||||
</p>
|
</p>
|
||||||
</center>
|
</center>
|
||||||
|
@ -277,7 +277,9 @@ local function shouldredirect(reqt, code, headers)
|
|||||||
return (reqt.redirect ~= false) and
|
return (reqt.redirect ~= false) and
|
||||||
(code == 301 or code == 302 or code == 303 or code == 307) and
|
(code == 301 or code == 302 or code == 303 or code == 307) and
|
||||||
(not reqt.method or reqt.method == "GET" or reqt.method == "HEAD")
|
(not reqt.method or reqt.method == "GET" or reqt.method == "HEAD")
|
||||||
and (not reqt.nredirects or reqt.nredirects < 5)
|
and ((false == reqt.maxredirects)
|
||||||
|
or ((reqt.nredirects or 0)
|
||||||
|
< (reqt.maxredirects or 5)))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function shouldreceivebody(reqt, code)
|
local function shouldreceivebody(reqt, code)
|
||||||
@ -299,6 +301,7 @@ local trequest, tredirect
|
|||||||
sink = reqt.sink,
|
sink = reqt.sink,
|
||||||
headers = reqt.headers,
|
headers = reqt.headers,
|
||||||
proxy = reqt.proxy,
|
proxy = reqt.proxy,
|
||||||
|
maxredirects = reqt.maxredirects,
|
||||||
nredirects = (reqt.nredirects or 0) + 1,
|
nredirects = (reqt.nredirects or 0) + 1,
|
||||||
create = reqt.create
|
create = reqt.create
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user