(
input: HttpRequestInput,
init: RequestInit | undefined,
options: HttpInstrumentationOptions = {},
)
| 124 | } |
| 125 | |
| 126 | export function buildHarRequest( |
| 127 | input: HttpRequestInput, |
| 128 | init: RequestInit | undefined, |
| 129 | options: HttpInstrumentationOptions = {}, |
| 130 | ): HarRequest { |
| 131 | let request: Request; |
| 132 | if (input instanceof Request) { |
| 133 | request = input; |
| 134 | } else { |
| 135 | const requestInput = input instanceof URL ? input.toString() : String(input); |
| 136 | request = new Request(requestInput, init); |
| 137 | } |
| 138 | const sensitiveHeaders = options.sensitiveHeaders ?? DEFAULT_SENSITIVE_HEADERS; |
| 139 | const sensitiveQueryParams = options.sensitiveQueryParams ?? DEFAULT_SENSITIVE_QUERY_PARAMS; |
| 140 | const maxBodySize = options.maxRequestBodySize ?? DEFAULT_MAX_REQUEST_BODY_SIZE; |
| 141 | const rawBody = getBodyText(init?.body); |
| 142 | const bodyText = rawBody ? truncateBody(rawBody, maxBodySize).text : undefined; |
| 143 | const contentType = request.headers.get('content-type') ?? ''; |
| 144 | |
| 145 | const headers = maskHeaders(headersToHar(request.headers), sensitiveHeaders); |
| 146 | const rawQueryString = parseQueryString(request.url); |
| 147 | const queryString = maskQueryParams(rawQueryString, sensitiveQueryParams); |
| 148 | const maskedUrl = maskUrlQueryParams(request.url, sensitiveQueryParams); |
| 149 | |
| 150 | const postData = bodyText |
| 151 | ? { |
| 152 | mimeType: contentType || 'text/plain', |
| 153 | text: bodyText, |
| 154 | } |
| 155 | : undefined; |
| 156 | |
| 157 | return { |
| 158 | method: request.method, |
| 159 | url: maskedUrl, |
| 160 | httpVersion: DEFAULT_HTTP_VERSION, |
| 161 | headers, |
| 162 | queryString, |
| 163 | cookies: [], |
| 164 | headersSize: -1, |
| 165 | bodySize: rawBody ? rawBody.length : 0, |
| 166 | ...(postData ? { postData } : {}), |
| 167 | }; |
| 168 | } |
| 169 | |
| 170 | export async function buildHarResponse( |
| 171 | response: HttpResponseLike, |
no test coverage detected