aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/http.html8
-rw-r--r--src/http.lua5
2 files changed, 9 insertions, 4 deletions
diff --git a/doc/http.html b/doc/http.html
index 3b7a8b1..78f785a 100644
--- a/doc/http.html
+++ b/doc/http.html
@@ -135,7 +135,8 @@ http.<b>request{</b><br>
135&nbsp;&nbsp;[step = <i>LTN12 pump step</i>,]<br> 135&nbsp;&nbsp;[step = <i>LTN12 pump step</i>,]<br>
136&nbsp;&nbsp;[proxy = <i>string</i>,]<br> 136&nbsp;&nbsp;[proxy = <i>string</i>,]<br>
137&nbsp;&nbsp;[redirect = <i>boolean</i>,]<br> 137&nbsp;&nbsp;[redirect = <i>boolean</i>,]<br>
138&nbsp;&nbsp;[create = <i>function</i>]<br> 138&nbsp;&nbsp;[create = <i>function</i>,]<br>
139&nbsp;&nbsp;[maxredirects = <i>number</i>]<br>
139<b>}</b> 140<b>}</b>
140</p> 141</p>
141 142
@@ -185,6 +186,7 @@ Defaults to the LTN12 <tt>pump.step</tt> function.
185function from automatically following 301 or 302 server redirect messages; 186function from automatically following 301 or 302 server redirect messages;
186<li><tt>create</tt>: An optional function to be used instead of 187<li><tt>create</tt>: An optional function to be used instead of
187<a href=tcp.html#socket.tcp><tt>socket.tcp</tt></a> when the communications socket is created. 188<a href=tcp.html#socket.tcp><tt>socket.tcp</tt></a> when the communications socket is created.
189<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).
188</ul> 190</ul>
189 191
190<p class=return> 192<p class=return>
@@ -324,8 +326,8 @@ r, c = http.request {
324</p> 326</p>
325<p> 327<p>
326<small> 328<small>
327Last modified by Diego Nehab on <br> 329Last modified by Eric Westbrook on <br>
328Thu Apr 20 00:25:26 EDT 2006 330Sat Feb 23 19:09:42 UTC 2019
329</small> 331</small>
330</p> 332</p>
331</center> 333</center>
diff --git a/src/http.lua b/src/http.lua
index a386165..8bda0d8 100644
--- a/src/http.lua
+++ b/src/http.lua
@@ -277,7 +277,9 @@ local function shouldredirect(reqt, code, headers)
277 return (reqt.redirect ~= false) and 277 return (reqt.redirect ~= false) and
278 (code == 301 or code == 302 or code == 303 or code == 307) and 278 (code == 301 or code == 302 or code == 303 or code == 307) and
279 (not reqt.method or reqt.method == "GET" or reqt.method == "HEAD") 279 (not reqt.method or reqt.method == "GET" or reqt.method == "HEAD")
280 and (not reqt.nredirects or reqt.nredirects < 5) 280 and ((false == reqt.maxredirects)
281 or ((reqt.nredirects or 0)
282 < (reqt.maxredirects or 5)))
281end 283end
282 284
283local function shouldreceivebody(reqt, code) 285local function shouldreceivebody(reqt, code)
@@ -299,6 +301,7 @@ local trequest, tredirect
299 sink = reqt.sink, 301 sink = reqt.sink,
300 headers = reqt.headers, 302 headers = reqt.headers,
301 proxy = reqt.proxy, 303 proxy = reqt.proxy,
304 maxredirects = reqt.maxredirects,
302 nredirects = (reqt.nredirects or 0) + 1, 305 nredirects = (reqt.nredirects or 0) + 1,
303 create = reqt.create 306 create = reqt.create
304 } 307 }