Implement redirect handler option.#622
Merged
csmarchbanks merged 7 commits intoprometheus:masterprometheus/client_python:masterfrom Feb 11, 2021
espears1:espears1/issue-131-redirect-handlerespears1/client_python:espears1/issue-131-redirect-handlerCopy head branch name to clipboard
Merged
Implement redirect handler option.#622csmarchbanks merged 7 commits intoprometheus:masterprometheus/client_python:masterfrom espears1:espears1/issue-131-redirect-handlerespears1/client_python:espears1/issue-131-redirect-handlerCopy head branch name to clipboard
csmarchbanks merged 7 commits intoprometheus:masterprometheus/client_python:masterfrom
espears1:espears1/issue-131-redirect-handlerespears1/client_python:espears1/issue-131-redirect-handlerCopy head branch name to clipboard
Conversation
Signed-off-by: Ely Spears <espears@squarespace.com>
1b75532 to
4613dfa
Compare
Signed-off-by: Ely Spears <espears@squarespace.com>
c31af42 to
67e99ff
Compare
Signed-off-by: Ely Spears <espears@squarespace.com>
csmarchbanks
reviewed
Feb 9, 2021
Member
csmarchbanks
left a comment
There was a problem hiding this comment.
Thanks! Generally this is looking good, just a couple of questions to begin with.
Signed-off-by: Ely Spears <espears@squarespace.com>
Signed-off-by: Ely Spears <espears@squarespace.com>
Signed-off-by: Ely Spears <espears@squarespace.com>
Signed-off-by: Ely Spears <espears@squarespace.com>
csmarchbanks
approved these changes
Feb 11, 2021
Member
csmarchbanks
left a comment
There was a problem hiding this comment.
Thanks, this looks good to me!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes #131 and a significant amount of content is discussed in that issue.
This PR adds a new redirect handler utility class that deliberately forwards an unmodified request to the
Locationheader provided by a redirect, while preserving the method, headers and data of the original request. As discussed in comments of the PR, HTTP RFC 2616 requires explicit user approval for redirects in certain situations that may alter the meaning or effect of the request. Given this, the defaultHTTPRedirectHandlerinurllibdoes not honor redirects forPUTand does not preserve all headers and data.In the case of Prometheus, many users will have some type of in-house "private" deployment of a Prometheus pushgateway server, and e.g. in a deployment infrastructure like Kubernetes where the ultimate IP-based host address could change often, there may be a need for a purely cosmetic redirect that fronts this host address with an easier static URL. In that case, the user would like to "opt in" to trusted pass-through redirects for all method types (including PUT).
This PR provides
passthrough_redirect_handlerto support this specific redirect option. Use of this special redirect handler would constitute the user's explicit approval for RFC2616.Additionally, this PR adds a new "redirect" HTTPD server to the unit tests for the pushgateway, in order to simulate a real redirect during testing and confirm it is handled as expected. I've locally validated all testing and flake8 instructions - and will work to resolve any requested changes or build issues.