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

Bugfix/header modifier doesn't work for user agent property #516

Merged

Conversation

Cich0sza
Copy link
Contributor

Description

The problem with changing some headers like User-agent, Accept was solved by changing proxy server configuration.

Motivation and Context

#515

Screenshots (if appropriate)

Upgrade notes (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • I have reviewed (and updated if needed) the documentation regarding this change

I hereby agree to the terms of the AET Contributor License Agreement.

URIBuilder uriBuilder = new URIBuilder().setScheme(HTTP).setHost(server.getAPIHost())
.setPort(server.getAPIPort());
// Request BMP to add header
HttpPost request = new HttpPost(uriBuilder.setPath(
Copy link
Contributor

Choose a reason for hiding this comment

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

According to https://github.com/lightbody/browsermob-proxy#rest-api docs:
POST /proxy/[port]/headers

Set and override HTTP Request headers

Do those changes mean, that this is not true? There is even an example of setting the User-Agent header.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this doesn't work anymore. You can't use this to change some headers like User-agent. Using this you can only add new header or override header that you add before.

@@ -14,6 +14,7 @@ In order to use this modifier it must be declared before the open module in the
| --------- | ----- | ----------- | --------- |
| `key` | x | Key for the header | yes |
| `value` | y | Value for the header | yes |
| `override` | `true`/`false` | Replace existing header instead of adding new one | no (default false) |
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the case of using the Header Modifier without override=true?
Is that the case, that the user wants to have more than one header's value?
If that's the case, override=true should be the default option and eventually let the user add more header values using override=false.
Could you please also make it more clear, in the docs, that override=false means, that if the header already occurs in the request, it will not be modified (like with User-Agent example, where Chrome instance sets it).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Override false is use when you want add new header, true option is used to change headers that are add by Chrome instance. This is why false is default strategy.

I'll make documentation more clear about that.

@malaskowski
Copy link
Contributor

What also concerns me is that https://github.com/lightbody/browsermob-proxy is no longer maintained:
image
There are over 160 issues open at the moment. If the docs for headers is not up-to-date maybe we should consider changing BMP for some different proxy?
However, this is a topic for another discussion and PR.

@@ -58,7 +58,7 @@ public void testCollect() throws Exception {
headerModifier.setParameters(ImmutableMap.of("key", "header", "value", "value1"));
headerModifier.collect();

verify(proxyServer).addHeader("header", "value1");
verify(proxyServer).addHeader("header", "value1", false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any way to test the override approach?
Maybe if not the unit test, some integration test (e.g. page displaying User-Agent header value?)

@tkaik tkaik merged commit 03cd733 into master Aug 12, 2019
@tkaik tkaik deleted the bugfix/header-modifier-doesn't-work-for-User-Agent-property branch August 12, 2019 07:15
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.

3 participants