plugin.api.http_session: remove parse_* methods#4803
Merged
gravyboat merged 1 commit intoSep 5, 2022
Merged
Conversation
The `parse_{cookies,headers,query_params}` methods were added when the
subclass of `requests.Session` was implemented in order to support
setting cookies, headers and query parameters via `k1=v1;k2=v2` strings
(in addition to key-value dicts) via the session API and via the CLI:
- 936e66d
- c6e54fd
Since these methods implement logic purely for the `Streamlink` session
interface and are not meant to be called by any plugin or stream
implementations which use the session's `HTTPSession` instance, they
should be removed. Cookies, headers and query string parameters should
be set directly on their respective `HTTPSession` attributes:
- `cookies`: instance of `requests.cookies.RequestsCookieJar`
- `headers`: instance of `requests.structures.CaseInsensitiveDict`
- `params`: instance of `dict`
Also, at least in regards to HTTP headers, the `key=value` syntax
does not reflect the syntax of raw HTTP requests/responses or interfaces
of other tools like cURL, etc., so having these methods on the
`HTTPSession` class makes it unnecessarily confusing. The method names
themselves are also confusing, as they suggest that the input gets
parsed and that some result gets returned, which is wrong.
This commit therefore moves the `k1=v1;k2=v2` string logic from the
`http_session` module to the `session` module where it belongs and it
also simplifies the option setter.
412b1c3 to
3392416
Compare
Billy2011
added a commit
to Billy2011/streamlink-27
that referenced
this pull request
Sep 15, 2022
The `parse_{cookies,headers,query_params}` methods were added when the
subclass of `requests.Session` was implemented in order to support
setting cookies, headers and query parameters via `k1=v1;k2=v2` strings
(in addition to key-value dicts) via the session API and via the CLI:
- 936e66d
- c6e54fd
Since these methods implement logic purely for the `Streamlink` session
interface and are not meant to be called by any plugin or stream
implementations which use the session's `HTTPSession` instance, they
should be removed. Cookies, headers and query string parameters should
be set directly on their respective `HTTPSession` attributes:
- `cookies`: instance of `requests.cookies.RequestsCookieJar`
- `headers`: instance of `requests.structures.CaseInsensitiveDict`
- `params`: instance of `dict`
Also, at least in regards to HTTP headers, the `key=value` syntax
does not reflect the syntax of raw HTTP requests/responses or interfaces
of other tools like cURL, etc., so having these methods on the
`HTTPSession` class makes it unnecessarily confusing. The method names
themselves are also confusing, as they suggest that the input gets
parsed and that some result gets returned, which is wrong.
This commit therefore moves the `k1=v1;k2=v2` string logic from the
`http_session` module to the `session` module where it belongs and it
also simplifies the option setter.
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.
The
parse_{cookies,headers,query_params}methods were added when thesubclass of
requests.Sessionwas implemented in order to supportsetting cookies, headers and query parameters via
k1=v1;k2=v2strings(in addition to key-value dicts) via the session API and via the CLI:
Since these methods implement logic purely for the
Streamlinksessioninterface and are not meant to be called by any plugin or stream
implementations which use the session's
HTTPSessioninstance, theyshould be removed. Cookies, headers and query string parameters should
be set directly on their respective
HTTPSessionattributes:cookies: instance ofrequests.cookies.RequestsCookieJarheaders: instance ofrequests.structures.CaseInsensitiveDictparams: instance ofdictAlso, at least in regards to HTTP headers, the
key=valuesyntaxdoes not reflect the syntax of raw HTTP requests/responses or interfaces
of other tools like cURL, etc., so having these methods on the
HTTPSessionclass makes it unnecessarily confusing. The method namesthemselves are also confusing, as they suggest that the input gets
parsed and that some result gets returned, which is wrong.
This commit therefore moves the
k1=v1;k2=v2string logic from thehttp_sessionmodule to thesessionmodule where it belongs and italso simplifies the option setter.
This might be a breaking change, not 100% sure, but since this isn't really advertised as a public interface, I don't see the need to document this removal, even though it's been implemented on the
HTTPSessionfor almost 9 years.This will only affect 3rd party code which is calling these
HTTPSessionmethods. Thekey=valuesyntax is still kept and remains the same on the CLI andStreamlinksession API. See the added tests.Merging this will introduce a conflict with the PR which adds the
http_sessionstub file.