MCPcopy Create free account
hub / github.com/ShipSecAI/studio / buildHarRequest

Function buildHarRequest

packages/component-sdk/src/http/har-builder.ts:126–168  ·  view source on GitHub ↗
(
  input: HttpRequestInput,
  init: RequestInit | undefined,
  options: HttpInstrumentationOptions = {},
)

Source from the content-addressed store, hash-verified

124}
125
126export 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
170export async function buildHarResponse(
171 response: HttpResponseLike,

Callers 2

instrumentedFetchFunction · 0.90
createHttpClientFunction · 0.90

Calls 8

getBodyTextFunction · 0.85
truncateBodyFunction · 0.85
maskHeadersFunction · 0.85
headersToHarFunction · 0.85
parseQueryStringFunction · 0.85
maskQueryParamsFunction · 0.85
maskUrlQueryParamsFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected