-
Notifications
You must be signed in to change notification settings - Fork 422
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
Add Content-Type header to all POST requests without an empty body #863
Add Content-Type header to all POST requests without an empty body #863
Conversation
Uhm, instead of all of this duplicate code, shouldn't we change the This will not be merged before the next version, I don't think it is a big deal for the NewPipe app. But we can make a specific extractor version after this PR is merged if needed. |
I'm not sure if |
c6cf025
to
438fb69
Compare
Thank you for the catch! I removed the addition of this header, and kept only the |
Note that the CI will fail because I didn't updated |
438fb69
to
b61ee64
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just create a utility method in the downloader, something like this:
postWithContentType(url, headers, body, contentType, localization) {
final Map<String, List<String>> actualHeaders = new HashMap<>(headers);
actualHeaders.put("Content-Type", Collections.singletonList(contentType));
post(url, actualHeaders, body, localization);
}
and maybe even this as a shorthand for json requests
postWithContentTypeJson(url, headers, body, localization) {
postWithContentType(url, headers, body, "application/json", localization);
}
The current strategy contains too much duplicated code.
b61ee64
to
54970e5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, almost ready
extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java
Outdated
Show resolved
Hide resolved
...va/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMixPlaylistExtractor.java
Outdated
Show resolved
Hide resolved
54970e5
to
2ca254e
Compare
Requested changes have been applied. Note: I reverted update of |
c9b9356
to
134bc2f
Compare
@Stypox Could you please review again this pull request? Thank you in advance :) |
Post methods in Downloader return the result of a POST request and not the one of a GET request.
This header was not sent before and was added and guessed by OkHttp. This can create issues when using other HTTP clients than OkHttp, such as Cronet. Also make use of StandardCharsets.UTF_8 when getting bytes of bodies instead of the platform default's charset, to make sure to prevent some encoding issues on some JVMs.
This header was not sent partially before and was added and guessed by OkHttp. This can create issues when using other HTTP clients than OkHttp, such as Cronet. Some code in the modified classes has been improved and / or deduplicated, and usages of the UTF_8 constant of the Utils class has been replaced by StandardCharsets.UTF_8 where possible. Note that this header has been not added in except in YoutubeDashManifestCreatorsUtils, as an empty body is sent in the POST requests made by this class.
…n Downloader Co-authored-by: Stypox <[email protected]>
…ods in services and extractors
134bc2f
to
fec769c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AudricV I rebased and updated the YouTube mocks. The following tests fail, but I don't think they are related. You can merge this PR if you think it is still ok!
Not all the "learn more" button is uppercase anymore, that's only the case for the first letter.
fec769c
to
34d79bd
Compare
@Stypox Indeed, you are almost right:
|
Anything worth mentioning in the blog post? |
This PR adds the
Content-Type
header to all POST requests without an empty body made by the extractor. They are made only in YouTube and Bandcamp services, according to the usages of thepost
methods in theDownloader
class.Currently, in NewPipe and in tests, this header is partially guessed and added by the network library we use, OkHttp. But this is not the case of all network libraries (e.g. Cronet), where 400 responses would be encountered on YouTube because the HTTP specifications for POST requests are not required.
I also improved related code in the changed files, and fixed some issues on the fly.