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

Support for custom HTTP Headers #53

Merged
merged 5 commits into from
Jan 20, 2023
Merged

Support for custom HTTP Headers #53

merged 5 commits into from
Jan 20, 2023

Conversation

2moe
Copy link
Contributor

@2moe 2moe commented Jan 15, 2023

Pull Request

Types of changes

  • New feature (Support for custom HTTP Headers)
  • Chore (Upgrade and simplify deps)

Description

close #52

About feature:

Added .headers() and .header() for DownloaderBuilder.
We can either call the .header() multiple times to add multiple headers, or we can add a bunch of headers with .headers().

   use reqwest::{
            header::{self, HeaderValue},
        };

    const FIREFOX_UA: &str =
        "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/109.0";

    let ua = HeaderValue::from_str(FIREFOX_UA).expect("Invalid UA");

    let client = DownloaderBuilder::new()
        .directory(PathBuf::from("assets"))
        .header(header::USER_AGENT, ua)
        .build();

About dependencies:

http::header -> reqwest::header
url::Url -> reqwest::Url

Reducing external dependencies makes maintenance easier, as well as reducing the probability of dependency conflicts.

Checklist

  • I have updated the documentation accordingly
  • [] I have updated the Changelog (if applicable)

Copy link
Owner

@rgreinho rgreinho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Thank you for your contribution 👍

Only one minor thing I would like you to change regarding the version number.

Also, for some reason the formatting of the PR seems off and causes cargo fmt to complain. Are you using Rust nightly?

Cargo.toml Outdated
@@ -1,6 +1,6 @@
[package]
name = "trauma"
version = "2.1.1"
version = "2.2.0"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't update the version number. We change it when we cut a new release.

Copy link
Contributor Author

@2moe 2moe Jan 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using rust stable. (rustc 1.66.1 (90743e729 2023-01-10))
The format is mainly related to rustfmt.

    "rust-analyzer.rustfmt.extraArgs": [
        "--config",
        "max_width=85,single_line_if_else_max_width=80,chain_width=32,format_code_in_doc_comments=false,imports_granularity=Crate"
    ],
    "rust-analyzer.checkOnSave.command": "clippy",

Could you provide the relevant configuration?

Ok, It has been reformatted according to the default configuration, rather than using the above configuration.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Owner

@rgreinho rgreinho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@kodiakhq kodiakhq bot merged commit e8fd949 into rgreinho:main Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom Http Headers
2 participants