MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / httpRequestToRequestData

Function httpRequestToRequestData

packages/core/src/utils/request.ts:198–243  ·  view source on GitHub ↗
(request: {
  method?: string;
  url?: string;
  headers?: {
    [key: string]: string | string[] | undefined;
  };
  protocol?: string;
  socket?: {
    encrypted?: boolean;
    remoteAddress?: string;
  };
})

Source from the content-addressed store, hash-verified

196 * we want to be more specific and generally require a http.IncomingMessage-like object.
197 */
198export function httpRequestToRequestData(request: {
199 method?: string;
200 url?: string;
201 headers?: {
202 [key: string]: string | string[] | undefined;
203 };
204 protocol?: string;
205 socket?: {
206 encrypted?: boolean;
207 remoteAddress?: string;
208 };
209}): RequestEventData {
210 const headers = request.headers || {};
211
212 // Check for x-forwarded-host first, then fall back to host header
213 const forwardedHost = typeof headers['x-forwarded-host'] === 'string' ? headers['x-forwarded-host'] : undefined;
214 const host = forwardedHost || (typeof headers.host === 'string' ? headers.host : undefined);
215
216 // Check for x-forwarded-proto first, then fall back to existing protocol detection
217 const forwardedProto = typeof headers['x-forwarded-proto'] === 'string' ? headers['x-forwarded-proto'] : undefined;
218 const protocol = forwardedProto || request.protocol || (request.socket?.encrypted ? 'https' : 'http');
219
220 const url = request.url || '';
221
222 const absoluteUrl = getAbsoluteUrl({
223 url,
224 host,
225 protocol,
226 });
227
228 // This is non-standard, but may be sometimes set
229 // It may be overwritten later by our own body handling
230 const data = (request as PolymorphicRequest).body || undefined;
231
232 // This is non-standard, but may be set on e.g. Next.js or Express requests
233 const cookies = (request as PolymorphicRequest).cookies;
234
235 return {
236 url: absoluteUrl,
237 method: request.method,
238 query_string: extractQueryParamsFromUrl(url),
239 headers: headersToDict(headers),
240 cookies,
241 data,
242 };
243}
244
245function getAbsoluteUrl({
246 url,

Callers 8

_wrapHttpFunctionFunction · 0.90
request.test.tsFile · 0.90
applyFunction · 0.90
setSDKProcessingMetadataFunction · 0.90
wrapApiHandlerWithSentryFunction · 0.90
honoRequestHandlerFunction · 0.90

Calls 3

headersToDictFunction · 0.85
getAbsoluteUrlFunction · 0.70

Tested by

no test coverage detected