Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/src/api/class-response.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ Returns all values of the headers matching the name, for example `set-cookie`. T

Name of the header.

## async method: Response.httpVersion
* since: v1.59
- returns: <[string]>

Returns the http version used by the response.

## async method: Response.json
* since: v1.8
* langs: js, python
Expand Down
5 changes: 5 additions & 0 deletions packages/playwright-client/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21155,6 +21155,11 @@ export interface Response {
*/
headerValues(name: string): Promise<Array<string>>;

/**
* Returns the http version used by the response.
*/
httpVersion(): Promise<string>;

/**
* Returns the JSON representation of response body.
*
Expand Down
6 changes: 6 additions & 0 deletions packages/playwright-core/src/client/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,12 @@ export class Response extends ChannelOwner<channels.ResponseChannel> implements
async securityDetails(): Promise<SecurityDetails|null> {
return (await this._channel.securityDetails()).value || null;
}

async httpVersion(): Promise<string> {
return this._wrapApiCall(async () => {
return (await this._channel.httpVersion()).value;
}, { internal: true });
}
}

export class WebSocket extends ChannelOwner<channels.WebSocketChannel> implements api.WebSocket {
Expand Down
4 changes: 4 additions & 0 deletions packages/playwright-core/src/protocol/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2416,6 +2416,10 @@ scheme.ResponseRawResponseHeadersParams = tOptional(tObject({}));
scheme.ResponseRawResponseHeadersResult = tObject({
headers: tArray(tType('NameValue')),
});
scheme.ResponseHttpVersionParams = tOptional(tObject({}));
scheme.ResponseHttpVersionResult = tObject({
value: tString,
});
scheme.ResponseSizesParams = tOptional(tObject({}));
scheme.ResponseSizesResult = tObject({
sizes: tType('RequestSizes'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export class ResponseDispatcher extends Dispatcher<Response, channels.ResponseCh
return { headers: await progress.race(this._object.rawResponseHeaders()) };
}

async httpVersion(params: channels.ResponseHttpVersionParams, progress: Progress): Promise<channels.ResponseHttpVersionResult> {
return { value: await progress.race(this._object.httpVersion()) };
}

async sizes(params: channels.ResponseSizesParams, progress: Progress): Promise<channels.ResponseSizesResult> {
return { sizes: await progress.race(this._object.sizes()) };
}
Expand Down
6 changes: 3 additions & 3 deletions packages/playwright-core/src/server/har/harTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export class HarTracer {
}));
}

const httpVersion = response.httpVersion();
const httpVersion = await response.httpVersion();
harEntry.request.httpVersion = httpVersion;
harEntry.response.httpVersion = httpVersion;

Expand Down Expand Up @@ -441,7 +441,7 @@ export class HarTracer {
}
}

private _onResponse(response: network.Response) {
private async _onResponse(response: network.Response) {
const harEntry = this._entryForRequest(response.request());
if (!harEntry)
return;
Expand All @@ -452,7 +452,7 @@ export class HarTracer {
harEntry.response = {
status: response.status(),
statusText: response.statusText(),
httpVersion: response.httpVersion(),
httpVersion: await response.httpVersion(),
// These are bad values that will be overwritten below.
cookies: [],
headers: [],
Expand Down
20 changes: 12 additions & 8 deletions packages/playwright-core/src/server/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ export class Response extends SdkObject {
private _serverAddrPromise = new ManualPromise<RemoteAddr | undefined>();
private _securityDetailsPromise = new ManualPromise<SecurityDetails | undefined>();
private _rawResponseHeadersPromise = new ManualPromise<HeadersArray>();
private _httpVersion: string | undefined;
private _httpVersionPromise = new ManualPromise<string | undefined>();
private _fromServiceWorker: boolean;
private _encodedBodySizePromise = new ManualPromise<number | null>();
private _transferSizePromise = new ManualPromise<number | null>();
Expand All @@ -526,7 +526,8 @@ export class Response extends SdkObject {
this._headersMap.set(name.toLowerCase(), value);
this._getResponseBodyCallback = getResponseBodyCallback;
this._request._setResponse(this);
this._httpVersion = httpVersion;
if (httpVersion)
this._httpVersionPromise.resolve(httpVersion);
this._fromServiceWorker = fromServiceWorker;
}

Expand All @@ -547,7 +548,7 @@ export class Response extends SdkObject {
}

_setHttpVersion(httpVersion: string) {
this._httpVersion = httpVersion;
this._httpVersionPromise.resolve(httpVersion);
}

url(): string {
Expand Down Expand Up @@ -631,14 +632,17 @@ export class Response extends SdkObject {
return this._request.frame();
}

httpVersion(): string {
if (!this._httpVersion)
async httpVersion(): Promise<string> {
const httpVersion = await this._httpVersionPromise || null;
if (!httpVersion)
return 'HTTP/1.1';
if (this._httpVersion === 'http/1.1')
if (httpVersion === 'http/1.1')
return 'HTTP/1.1';
if (this._httpVersion === 'h2')
if (httpVersion === 'h2')
return 'HTTP/2.0';
return this._httpVersion;
if (httpVersion === 'h3')
return 'HTTP/3.0';
return httpVersion;
}

fromServiceWorker(): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ export const methodMetainfo = new Map<string, { internal?: boolean, title?: stri
['Response.securityDetails', { internal: true, }],
['Response.serverAddr', { internal: true, }],
['Response.rawResponseHeaders', { internal: true, }],
['Response.httpVersion', { internal: true, }],
['Response.sizes', { internal: true, }],
['BindingCall.reject', { internal: true, }],
['BindingCall.resolve', { internal: true, }],
Expand Down
5 changes: 5 additions & 0 deletions packages/playwright-core/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21155,6 +21155,11 @@ export interface Response {
*/
headerValues(name: string): Promise<Array<string>>;

/**
* Returns the http version used by the response.
*/
httpVersion(): Promise<string>;

/**
* Returns the JSON representation of response body.
*
Expand Down
6 changes: 6 additions & 0 deletions packages/protocol/src/channels.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4136,6 +4136,7 @@ export interface ResponseChannel extends ResponseEventTarget, Channel {
securityDetails(params?: ResponseSecurityDetailsParams, progress?: Progress): Promise<ResponseSecurityDetailsResult>;
serverAddr(params?: ResponseServerAddrParams, progress?: Progress): Promise<ResponseServerAddrResult>;
rawResponseHeaders(params?: ResponseRawResponseHeadersParams, progress?: Progress): Promise<ResponseRawResponseHeadersResult>;
httpVersion(params?: ResponseHttpVersionParams, progress?: Progress): Promise<ResponseHttpVersionResult>;
sizes(params?: ResponseSizesParams, progress?: Progress): Promise<ResponseSizesResult>;
}
export type ResponseBodyParams = {};
Expand All @@ -4158,6 +4159,11 @@ export type ResponseRawResponseHeadersOptions = {};
export type ResponseRawResponseHeadersResult = {
headers: NameValue[],
};
export type ResponseHttpVersionParams = {};
export type ResponseHttpVersionOptions = {};
export type ResponseHttpVersionResult = {
value: string,
};
export type ResponseSizesParams = {};
export type ResponseSizesOptions = {};
export type ResponseSizesResult = {
Expand Down
5 changes: 5 additions & 0 deletions packages/protocol/src/protocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3656,6 +3656,11 @@ Response:
type: array
items: NameValue

httpVersion:
internal: true
returns:
value: string

sizes:
internal: true
returns:
Expand Down