Skip to content

Commit

Permalink
fix(network): stringify response headers for intercepted requests (#4436
Browse files Browse the repository at this point in the history
)

Stringifying the headers was the behaviour before v1.15

References #4379
  • Loading branch information
jake314159 authored and aslushnikov committed May 20, 2019
1 parent 3f19bd5 commit 90a1032
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3253,7 +3253,7 @@ Exception is immediately thrown if the request interception is not enabled.
- `url` <[string]> If set, the request url will be changed. This is not a redirect. The request will be silently forwarded to the new url. For example, the address bar will show the original url.
- `method` <[string]> If set changes the request method (e.g. `GET` or `POST`)
- `postData` <[string]> If set changes the post data of request
- `headers` <[Object]> If set changes the request HTTP headers
- `headers` <[Object]> If set changes the request HTTP headers. Header values will be converted to a string.
- returns: <[Promise]>

Continues request with optional request overrides. To use this, request interception should be enabled with `page.setRequestInterception`.
Expand Down Expand Up @@ -3339,7 +3339,7 @@ ResourceType will be one of the following: `document`, `stylesheet`, `image`, `m
#### request.respond(response)
- `response` <[Object]> Response that will fulfill this request
- `status` <[number]> Response status code, defaults to `200`.
- `headers` <[Object]> Optional response headers
- `headers` <[Object]> Optional response headers. Header values will be converted to a string.
- `contentType` <[string]> If set, equals to setting `Content-Type` response header
- `body` <[string]|[Buffer]> Optional response body
- returns: <[Promise]>
Expand Down
2 changes: 1 addition & 1 deletion lib/NetworkManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ class SecurityDetails {
function headersArray(headers) {
const result = [];
for (const name in headers)
result.push({name, value: headers[name]});
result.push({name, value: headers[name] + ''});
return result;
}

Expand Down
17 changes: 17 additions & 0 deletions test/requestinterception.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,23 @@ module.exports.addTests = function({testRunner, expect, CHROME}) {
const img = await page.$('img');
expect(await img.screenshot()).toBeGolden('mock-binary-response.png');
});
it('should stringify intercepted request response headers', async({page, server}) => {
await page.setRequestInterception(true);
page.on('request', request => {
request.respond({
status: 200,
headers: {
'foo': true
},
body: 'Yo, page!'
});
});
const response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(200);
const headers = response.headers();
expect(headers.foo).toBe('true');
expect(await page.evaluate(() => document.body.textContent)).toBe('Yo, page!');
});
});

};
Expand Down

0 comments on commit 90a1032

Please sign in to comment.