Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not follow HTTP redirects #170

Open
1 task done
relvacode opened this issue Aug 8, 2022 · 5 comments
Open
1 task done

Do not follow HTTP redirects #170

relvacode opened this issue Aug 8, 2022 · 5 comments

Comments

@relvacode
Copy link

Terraform CLI and Provider Versions

terraform version
Terraform v1.2.6
on darwin_amd64

Use Cases or Problem Statement

The current version of this provider does not expose an option to not implictly follow HTTP redirects.

It also does not document the behaviour of HTTP redirection, as highlighted in #60.

In my use-case, I would like to use this module to call an HTTP server with some specific headers, such as Authorization. This server will then respond with a S3 URL which I would like to pass to another module that I do not want to propagate the origin server-specific request headers to.

Proposal

I propose that the provider adds the option no_follow_redirects to explicitly disable HTTP redirection and instead return the response of the first HTTP request made.
no_follow_redirects instead of follow_redirects to make it obvious the default behaviour is to follow redirects, and setting the option to true disables this behaviour.

I also propose that it adds an output named location that describes the absolute URL of the request that made the final response returned by the provider.
In the case that the server responds with a Location header, the location attribute is the absolute URL of the Location header value relative to the request that made the final HTTP request.

Example 1

url is http://example.org which returns HTTP 200 OK

status_code is 200
location is http://example.org

Example 2

url is http://example.org which returns HTTP 302 Found and Location of /redirected
no_follow_redirects is false

<-- provider makes another request -->

status_code is 200
location is http://example.org/redirected

Example 3

url is http://example.org which returns HTTP 302 Found and Location of /redirected
no_follow_redirects is true

status_code is 302
location is http://example.org/redirected

How much impact is this issue causing?

Medium

Additional Information

I have written an implementation of this proposal at https://github.com/relvacode/terraform-provider-http/tree/feature/explicit-follow-redirects

Code of Conduct

  • I agree to follow this project's Code of Conduct
@dentarg
Copy link

dentarg commented Nov 11, 2022

I also want this, 100% a very useful feature to have!

@timbrammer910
Copy link

+1 Would also love to see this merged!!

@kalsto
Copy link

kalsto commented Sep 12, 2023

+1 to this as well - would be very useful in my use case!

@kalsto
Copy link

kalsto commented Sep 17, 2023

I've investigated the proposal implementation provided by relvacode and tested it out. I have found that all that's really missing is a "Location" in the struct. By setting the http { METHOD = "HEAD" } and having a Location output defined, I'm receiving the "Location" response which includes the Token from the header (which is typically found in the 302 redirect).

Would it be acceptable for me to submit a PR towards these changes ?

@robsteel-kpmg
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants