Repository navigation
Expand file tree
/
Copy pathhttpRequest.ts
More file actions
55 lines (48 loc) · 1.53 KB
/
Copy pathhttpRequest.ts
File metadata and controls
55 lines (48 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { Stream } from 'stream';
import { getContentType } from '../utils/misc';
import { RequestHeaders } from './base';
import got = require('got');
export class HttpRequest {
public isCancelled: boolean;
private _underlyingRequest: got.GotPromise<Buffer>;
public constructor(
public method: string,
public url: string,
public headers: RequestHeaders,
public body?: string | Stream,
public rawBody?: string,
public name?: string) {
this.method = method.toLocaleUpperCase();
this.isCancelled = false;
}
public get contentType(): string | undefined {
return getContentType(this.headers);
}
public setUnderlyingRequest(request: got.GotPromise<Buffer>): void {
this._underlyingRequest = request;
}
public cancel(): void {
if (!this.isCancelled) {
this._underlyingRequest?.cancel();
this.isCancelled = true;
}
}
}
export class HistoricalHttpRequest {
public constructor(
public method: string,
public url: string,
public headers: RequestHeaders,
public body: string | undefined,
public startTime: number) {
}
public static convertFromHttpRequest(httpRequest: HttpRequest, startTime: number = Date.now()): HistoricalHttpRequest {
return new HistoricalHttpRequest(
httpRequest.method,
httpRequest.url,
httpRequest.headers,
httpRequest.rawBody,
startTime
);
}
}