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

Modified request headers don't appear in response.request().headers() #4165

Open
tolmasky opened this issue Mar 14, 2019 · 2 comments
Open
Labels

Comments

@tolmasky
Copy link

I'm doing something relatively simple in the request interception:

const headers = request.headers();
const modifiedHeaders = { ...headers, "x-new-header": "true" };

request.continue({ headers: modifiedHeaders });

However, later, when I receive the callback for the response, this header is missing from the associated request:

response.request().headers()["x-new-header"] !== "true";

I am trying to mark the request as modified so that later in the response I know this was one of my intercepted requests.

@aslushnikov
Copy link
Contributor

However, later, when I receive the callback for the response, this header is missing from the associated request

@tolmasky We don't update headers in a requests. It looks like the workaround below would suite you well, so I'd keep it this way.

I am trying to mark the request as modified so that later in the response I know this was one of my intercepted requests.

Since request and response.request are exactly the same objects, you can just mark requests with a symbol:

const wasModified = Symbol('requestWasModified');

// ...

request.continue({headers: modifiedHeaders});
request[wasModified] = true;

// ....

response.request()[wasModified] === true;

Will it work for you?

@tolmasky
Copy link
Author

tolmasky commented Mar 15, 2019

Hi @aslushnikov , the workaround worked and I am currently using it in my code. Thank you very much for the suggestion.

That being said, I do believe that the correct behavior here is that the request object should be updated, as the request reported by response.request() is stale, and might be significantly diverged from the request that actually ended up being sent. If you have two libraries that don't know about each other (as opposed to my example where I control both ends), this could lead to more complex and difficult to debug incorrect behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants