fix(postData): allow overriding binary post data (#3120)
This commit is contained in:
Родитель
bec34db686
Коммит
e7cca86757
|
@ -1,6 +1,6 @@
|
|||
# 🎭 Playwright
|
||||
|
||||
[![npm version](https://img.shields.io/npm/v/playwright.svg?style=flat)](https://www.npmjs.com/package/playwright) [![Join Slack](https://img.shields.io/badge/join-slack-infomational)](https://join.slack.com/t/playwright/shared_invite/enQtOTEyMTUxMzgxMjIwLThjMDUxZmIyNTRiMTJjNjIyMzdmZDA3MTQxZWUwZTFjZjQwNGYxZGM5MzRmNzZlMWI5ZWUyOTkzMjE5Njg1NDg) <!-- GEN:chromium-version-badge -->[![Chromium version](https://img.shields.io/badge/chromium-86.0.4209.0-blue.svg?logo=google-chrome)](https://www.chromium.org/Home)<!-- GEN:stop --> <!-- GEN:firefox-version-badge -->[![Firefox version](https://img.shields.io/badge/firefox-78.0b5-blue.svg?logo=mozilla-firefox)](https://www.mozilla.org/en-US/firefox/new/)<!-- GEN:stop --> [![WebKit version](https://img.shields.io/badge/webkit-14.0-blue.svg?logo=safari)](https://webkit.org/)
|
||||
[![npm version](https://img.shields.io/npm/v/playwright.svg?style=flat)](https://www.npmjs.com/package/playwright) [![Join Slack](https://img.shields.io/badge/join-slack-infomational)](https://join.slack.com/t/playwright/shared_invite/enQtOTEyMTUxMzgxMjIwLThjMDUxZmIyNTRiMTJjNjIyMzdmZDA3MTQxZWUwZTFjZjQwNGYxZGM5MzRmNzZlMWI5ZWUyOTkzMjE5Njg1NDg) <!-- GEN:chromium-version-badge -->[![Chromium version](https://img.shields.io/badge/chromium-86.0.4211.0-blue.svg?logo=google-chrome)](https://www.chromium.org/Home)<!-- GEN:stop --> <!-- GEN:firefox-version-badge -->[![Firefox version](https://img.shields.io/badge/firefox-78.0b5-blue.svg?logo=mozilla-firefox)](https://www.mozilla.org/en-US/firefox/new/)<!-- GEN:stop --> [![WebKit version](https://img.shields.io/badge/webkit-14.0-blue.svg?logo=safari)](https://webkit.org/)
|
||||
|
||||
##### [Docs](docs/README.md) | [API reference](docs/api.md) | [Changelog](https://github.com/microsoft/playwright/releases)
|
||||
|
||||
|
@ -8,7 +8,7 @@ Playwright is a Node library to automate [Chromium](https://www.chromium.org/Hom
|
|||
|
||||
| | Linux | macOS | Windows |
|
||||
| :--- | :---: | :---: | :---: |
|
||||
| Chromium <!-- GEN:chromium-version -->86.0.4209.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| Chromium <!-- GEN:chromium-version -->86.0.4211.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| WebKit 14.0 | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| Firefox <!-- GEN:firefox-version -->78.0b5<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"browsers": [
|
||||
{
|
||||
"name": "chromium",
|
||||
"revision": "790602"
|
||||
"revision": "791201"
|
||||
},
|
||||
{
|
||||
"name": "firefox",
|
||||
|
|
|
@ -3729,7 +3729,7 @@ Aborts the route's request.
|
|||
#### route.continue([overrides])
|
||||
- `overrides` <[Object]> Optional request overrides, which can be one of the following:
|
||||
- `method` <[string]> If set changes the request method (e.g. GET or POST)
|
||||
- `postData` <[string]> If set changes the post data of request
|
||||
- `postData` <[string]|[Buffer]> If set changes the post data of request
|
||||
- `headers` <[Object]<[string], [string]>> If set changes the request HTTP headers. Header values will be converted to a string.
|
||||
- returns: <[Promise]>
|
||||
|
||||
|
|
|
@ -359,7 +359,7 @@ class InterceptableRequest implements network.RouteDelegate {
|
|||
requestId: this._interceptionId!,
|
||||
headers: overrides.headers,
|
||||
method: overrides.method,
|
||||
postData: overrides.postData
|
||||
postData: overrides.postData ? overrides.postData.toString('base64') : undefined
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -11856,7 +11856,7 @@ If absent, a standard phrase matching responseCode is used.
|
|||
/**
|
||||
* If set, overrides the post data in the request.
|
||||
*/
|
||||
postData?: string;
|
||||
postData?: binary;
|
||||
/**
|
||||
* If set, overrides the request headers.
|
||||
*/
|
||||
|
|
|
@ -168,7 +168,12 @@ export class Route extends ChannelOwner<RouteChannel, RouteInitializer> {
|
|||
}
|
||||
|
||||
async continue(overrides: types.ContinueOverrides = {}) {
|
||||
await this._channel.continue(normalizeContinueOverrides(overrides));
|
||||
const normalized = normalizeContinueOverrides(overrides);
|
||||
await this._channel.continue({
|
||||
method: normalized.method,
|
||||
headers: normalized.headers,
|
||||
postData: normalized.postData ? normalized.postData.toString('base64') : undefined
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1686,7 +1686,7 @@ Route:
|
|||
properties:
|
||||
name: string
|
||||
value: string
|
||||
postData: string?
|
||||
postData: binary?
|
||||
|
||||
fulfill:
|
||||
parameters:
|
||||
|
|
|
@ -107,7 +107,7 @@ export function normalizeContinueOverrides(overrides: types.ContinueOverrides):
|
|||
return {
|
||||
method: overrides.method,
|
||||
headers: overrides.headers ? headersObjectToArray(overrides.headers) : undefined,
|
||||
postData: overrides.postData,
|
||||
postData: helper.isString(overrides.postData) ? Buffer.from(overrides.postData, 'utf8') : overrides.postData,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -82,11 +82,11 @@ export class RouteDispatcher extends Dispatcher<Route, RouteInitializer> impleme
|
|||
});
|
||||
}
|
||||
|
||||
async continue(params: types.NormalizedContinueOverrides): Promise<void> {
|
||||
async continue(params: { method?: string, headers?: types.HeadersArray, postData?: string }): Promise<void> {
|
||||
await this._object.continue({
|
||||
method: params.method,
|
||||
headers: params.headers ? headersArrayToObject(params.headers) : undefined,
|
||||
postData: params.postData,
|
||||
postData: params.postData ? Buffer.from(params.postData, 'base64') : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -227,13 +227,13 @@ export type NormalizedFulfillResponse = {
|
|||
export type ContinueOverrides = {
|
||||
method?: string,
|
||||
headers?: Headers,
|
||||
postData?: string,
|
||||
postData?: string | Buffer,
|
||||
};
|
||||
|
||||
export type NormalizedContinueOverrides = {
|
||||
method?: string,
|
||||
headers?: HeadersArray,
|
||||
postData?: string,
|
||||
postData?: Buffer,
|
||||
};
|
||||
|
||||
export type NetworkCookie = {
|
||||
|
|
|
@ -532,7 +532,18 @@ describe('Request.continue', function() {
|
|||
server.waitForRequest('/sleep.zzz'),
|
||||
page.evaluate(() => fetch('/sleep.zzz', { method: 'POST', body: 'birdy' }))
|
||||
]);
|
||||
expect(await serverRequest.postBody).toBe('doggo');
|
||||
expect((await serverRequest.postBody).toString('utf8')).toBe('doggo');
|
||||
});
|
||||
it.fail(FFOX)('should amend utf8 post data', async({page, server}) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
await page.route('**/*', route => {
|
||||
route.continue({ postData: 'пушкин' });
|
||||
});
|
||||
const [serverRequest] = await Promise.all([
|
||||
server.waitForRequest('/sleep.zzz'),
|
||||
page.evaluate(() => fetch('/sleep.zzz', { method: 'POST', body: 'birdy' }))
|
||||
]);
|
||||
expect((await serverRequest.postBody).toString('utf8')).toBe('пушкин');
|
||||
});
|
||||
it.fail(FFOX)('should amend longer post data', async({page, server}) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
|
@ -543,7 +554,22 @@ describe('Request.continue', function() {
|
|||
server.waitForRequest('/sleep.zzz'),
|
||||
page.evaluate(() => fetch('/sleep.zzz', { method: 'POST', body: 'birdy' }))
|
||||
]);
|
||||
expect(await serverRequest.postBody).toBe('doggo-is-longer-than-birdy');
|
||||
expect((await serverRequest.postBody).toString('utf8')).toBe('doggo-is-longer-than-birdy');
|
||||
});
|
||||
it.fail(FFOX)('should amend binary post data', async({page, server}) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
const arr = Array.from(Array(256).keys());
|
||||
await page.route('**/*', route => {
|
||||
route.continue({ postData: Buffer.from(arr) });
|
||||
});
|
||||
const [serverRequest] = await Promise.all([
|
||||
server.waitForRequest('/sleep.zzz'),
|
||||
page.evaluate(() => fetch('/sleep.zzz', { method: 'POST', body: 'birdy' }))
|
||||
]);
|
||||
const buffer = await serverRequest.postBody;
|
||||
expect(buffer.length).toBe(arr.length);
|
||||
for (let i = 0; i < arr.length; ++i)
|
||||
expect(arr[i]).toBe(buffer[i]);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -194,8 +194,8 @@ class TestServer {
|
|||
throw error;
|
||||
});
|
||||
request.postBody = new Promise(resolve => {
|
||||
let body = '';
|
||||
request.on('data', chunk => body += chunk);
|
||||
let body = Buffer.from([]);
|
||||
request.on('data', chunk => body = Buffer.concat([body, chunk]));
|
||||
request.on('end', () => resolve(body));
|
||||
});
|
||||
const pathName = url.parse(request.url).path;
|
||||
|
|
Загрузка…
Ссылка в новой задаче