@@ -183,6 +183,15 @@ Public EnableAutoProxy As Boolean
183183''
184184Public Insecure As Boolean
185185
186+ ''
187+ ' Follow redirects (301, 302, 307) using Location header
188+ '
189+ ' @property FollowRedirects
190+ ' @type Boolean
191+ ' @default True
192+ ''
193+ Public FollowRedirects As Boolean
194+
186195''
187196' Proxy server to pass requests through (except for those that match `ProxyBypassList`).
188197'
@@ -449,26 +458,6 @@ Public Sub SetProxy(ProxyServer As String, _
449458 Me.ProxyBypassList = BypassList
450459End Sub
451460
452- ''
453- ' If the given Request is a redirect (301, 302, or 307),
454- ' then get value of the "Location" header
455- '
456- ' @param {WebRequest} Request
457- ' @return {String}
458- ''
459- Public Function GetRedirectLocation (Request As WebRequest ) As String
460- Dim RedirectRequest As WebRequest
461- Set RedirectRequest = Request.Clone
462- RedirectRequest.Method = WebMethod.HttpHead
463-
464- Dim Response As WebResponse
465- Set Response = Me.Execute(RedirectRequest)
466-
467- If Response.StatusCode = 301 Or Response.StatusCode = 302 Or Response.StatusCode = 307 Then
468- GetRedirectLocation = WebHelpers.FindInKeyValues(Response.Headers, "Location" )
469- End If
470- End Function
471-
472461''
473462' Get full url by joining given `WebRequest.FormattedResource` and `BaseUrl`.
474463'
@@ -535,24 +524,23 @@ Public Function PrepareHttpRequest(Request As WebRequest, Optional Async As Bool
535524 ' Invalid common name (CN), 0x1000
536525 ' Invalid date or certificate expired, 0x2000
537526 ' = 0x3300 = 13056
538- ' - Enable redirects
539527 ' - Enable https-to-http redirects
540528 web_Http.Option(web_WinHttpRequestOption.web_WinHttpRequestOption_EnableCertificateRevocationCheck) = False
541529 web_Http.Option(web_WinHttpRequestOption.web_WinHttpRequestOption_SslErrorIgnoreFlags) = 13056
542- web_Http.Option(web_WinHttpRequestOption.web_WinHttpRequestOption_EnableRedirects) = True
543530 web_Http.Option(web_WinHttpRequestOption.web_WinHttpRequestOption_EnableHttpsToHttpRedirects) = True
544531 Else
545532 ' By default:
546533 ' - Enable certificate revocation check (especially useful after HeartBleed)
547534 ' - Ignore no SLL erros
548- ' - Disable redirects (matches cURL behavior)
549535 ' - Disable https-to-http redirects
550536 web_Http.Option(web_WinHttpRequestOption.web_WinHttpRequestOption_EnableCertificateRevocationCheck) = True
551537 web_Http.Option(web_WinHttpRequestOption.web_WinHttpRequestOption_SslErrorIgnoreFlags) = 0
552- web_Http.Option(web_WinHttpRequestOption.web_WinHttpRequestOption_EnableRedirects) = False
553538 web_Http.Option(web_WinHttpRequestOption.web_WinHttpRequestOption_EnableHttpsToHttpRedirects) = False
554539 End If
555540
541+ ' Setup redirects
542+ web_Http.Option(web_WinHttpRequestOption.web_WinHttpRequestOption_EnableRedirects) = Me.FollowRedirects
543+
556544 ' Set headers on http request (after open)
557545 For Each web_KeyValue In Request.Headers
558546 web_Http.SetRequestHeader web_KeyValue("Key" ), web_KeyValue("Value" )
@@ -623,6 +611,11 @@ Public Function PrepareCurlRequest(Request As WebRequest) As String
623611 web_Curl = web_Curl & " --insecure"
624612 End If
625613
614+ ' Setup redirects
615+ If Me.FollowRedirects Then
616+ web_Curl = web_Curl & " --location"
617+ End If
618+
626619 ' Set headers and cookies
627620 For Each web_KeyValue In Request.Headers
628621 web_Curl = web_Curl & " -H '" & web_KeyValue("Key" ) & ": " & web_KeyValue("Value" ) & "'"
@@ -734,4 +727,5 @@ Private Sub Class_Initialize()
734727 Me.TimeoutMs = web_DefaultTimeoutMs
735728 Me.EnableAutoProxy = False
736729 Me.Insecure = False
730+ Me.FollowRedirects = True
737731End Sub
0 commit comments