From 09ff9b650c3567c91eed62f4dd571729df2dedd4 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Fri, 13 Jul 2018 12:52:26 -0600 Subject: [PATCH] http.lua: allow override of hard-coded 5 max redirects --- doc/http.html | 8 +++++--- src/http.lua | 5 ++++- 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.request{
  [step = LTN12 pump step,]
  [proxy = string,]
  [redirect = boolean,]
-  [create = function]
+  [create = function,]
+  [maxredirects = number]
}

@@ -185,6 +186,7 @@ Defaults to the LTN12 pump.step function. function from automatically following 301 or 302 server redirect messages;
  • create: An optional function to be used instead of socket.tcp when the communications socket is created. +
  • maxredirects: An optional number specifying the maximum number of redirects to follow. Defaults to 5 if not specified. A boolean false value means no maximum (unlimited).

    @@ -324,8 +326,8 @@ r, c = http.request {

    -Last modified by Diego Nehab on
    -Thu Apr 20 00:25:26 EDT 2006 +Last modified by Eric Westbrook on
    +Sat Feb 23 19:09:42 UTC 2019

    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) return (reqt.redirect ~= false) and (code == 301 or code == 302 or code == 303 or code == 307) and (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 local function shouldreceivebody(reqt, code) @@ -299,6 +301,7 @@ local trequest, tredirect sink = reqt.sink, headers = reqt.headers, proxy = reqt.proxy, + maxredirects = reqt.maxredirects, nredirects = (reqt.nredirects or 0) + 1, create = reqt.create }