[fix] api - Send Access-Control-Expose-Headers for pagination and ETag headers#1786
Merged
liiight merged 3 commits intoFlexget:developfrom Apr 11, 2017
Merged
[fix] api - Send Access-Control-Expose-Headers for pagination and ETag headers#1786liiight merged 3 commits intoFlexget:developfrom
liiight merged 3 commits intoFlexget:developfrom
Conversation
Web browsers require the “Access-Control-Expose-Headers” header to be sent in order to allow JavaScript (XMLHttpRequest) access to “unsafe” headers, such as the custom ones that Flexget implements. Flask-CORS provides an option for the Access-Control-Expose-Headers header to be sent, and this change implements that option.
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.
Motivation for changes:
Outside of the six "simple response headers", most headers returned by a cross-origin
XMLHttpRequestare not available to JavaScript in browsers. In order to programmatically use in JavaScript the pagination and ETag headers returned by the Flexget API, theAccess-Control-Expose-Headersheader must be sent to the browser.Detailed changes:
Implements the Flask-CORS
expose_headersoption with the four additional headers Flexget sends (Link, Total-Count, Count, ETag). This causes theAccess-Control-Expose-Headersheader to be sent. This option should be updated if Flexget sends additional headers in the future. Note the the presence of the header name here does not mean that it will be sent with every request, simply that it's possible it will be and if it is present, it should be considered safe to use.Log and/or tests output (preferably both):
Example JavaScript function:
Chrome console output
Before changes
After changes