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

Fix rewrite of User-Agent header #9707

Merged
merged 11 commits into from
Jan 20, 2025
Merged

Fix rewrite of User-Agent header #9707

merged 11 commits into from
Jan 20, 2025

Conversation

vbrvk
Copy link
Contributor

@vbrvk vbrvk commented Jan 17, 2025

Motivation

For now passed User-Agent header is rewritten to foundry/version, but it should not

Solution

Fix header existence check condition (HeaderName is lowercased and do not contains :)

@grandizzy
Copy link
Collaborator

@vbrvk thank you! would it be possible to have a unit test to prevent regressions, in this way could also better understand the issue and solution too

@vbrvk
Copy link
Contributor Author

vbrvk commented Jan 17, 2025

@grandizzy actually I was thinking about tests but it is not possible to retrieve headers of request without firing it, so local server start required. I thought it is overkill for such little thing.

You OK with such approach or you suggesting more simple test?

    #[tokio::test]
    async fn test_headers() {
        let transport = RuntimeTransportBuilder::new(Url::parse("127.0.0.1").unwrap())
            .with_headers(vec!["User-Agent: test-agent".to_string()])
            .build();

        let inner = transport.connect_http().await.unwrap();

        match inner {
            InnerTransport::Http(http) => {
                let client = http.client();

                let req = client.get("/").build().unwrap();
                
                let actual_headers = req.headers();
                
                // aseert here
            }
            _ => unreachable!(),
        }
    }

@grandizzy
Copy link
Collaborator

@grandizzy actually I was thinking about tests but it is not possible to retrieve headers of request without firing it, so local server start required. I thought it is overkill for such little thing.

You OK with such approach or you suggesting more simple test?

    #[tokio::test]
    async fn test_headers() {
        let transport = RuntimeTransportBuilder::new(Url::parse("127.0.0.1").unwrap())
            .with_headers(vec!["User-Agent: test-agent".to_string()])
            .build();

        let inner = transport.connect_http().await.unwrap();

        match inner {
            InnerTransport::Http(http) => {
                let client = http.client();

                let req = client.get("/").build().unwrap();
                
                let actual_headers = req.headers();
                
                // aseert here
            }
            _ => unreachable!(),
        }
    }

that would be better than nothing, though if we need to start an anvil instance and then call cast or forge against we have several examples as here

forgetest_async!(decode_traces_with_project_artifacts, |prj, cmd| {

@vbrvk
Copy link
Contributor Author

vbrvk commented Jan 17, 2025

@grandizzy added test

So if fix not present, then test fails with

called `Result::unwrap()` on an `Err` value: reqwest::Error { kind: Request, url: "http://127.0.0.1:1337/", source: hyper_util::client::legacy::Error(SendRequest, hyper::Error(IncompleteMessage)) }
thread 'provider::runtime_transport::tests::test_user_agent_header' panicked at crates/common/src/provider/runtime_transport.rs:350:13:
assertion `left == right` failed
  left: "foundry/0.3.0"
 right: "test-agent"

Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@yash-atreya yash-atreya merged commit 90a5fdf into foundry-rs:master Jan 20, 2025
22 checks passed
@vbrvk vbrvk deleted the patch-1 branch January 20, 2025 09:54
@grandizzy grandizzy added T-bug Type: bug C-forge Command: forge labels Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge T-bug Type: bug
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

4 participants