MCPcopy Index your code
hub / github.com/simstudioai/sim / fetchCsrf

Function fetchCsrf

apps/sim/app/api/tools/sap_s4hana/proxy/route.ts:131–161  ·  view source on GitHub ↗
(
  req: ProxyRequest,
  accessToken: string | null,
  requestId: string
)

Source from the content-addressed store, hash-verified

129}
130
131async function fetchCsrf(
132 req: ProxyRequest,
133 accessToken: string | null,
134 requestId: string
135): Promise<CsrfBundle | null> {
136 const url = buildOdataUrl(req, '/$metadata')
137 const response = await secureFetchWithValidation(
138 url,
139 {
140 method: 'GET',
141 headers: {
142 Authorization: buildAuthHeader(req, accessToken),
143 Accept: 'application/xml',
144 'X-CSRF-Token': 'Fetch',
145 },
146 timeout: OUTBOUND_FETCH_TIMEOUT_MS,
147 },
148 'baseUrl'
149 )
150
151 if (!response.ok) {
152 const text = await response.text().catch(() => '')
153 logger.warn(`[${requestId}] CSRF fetch failed (${response.status}): ${text}`)
154 return null
155 }
156
157 const token = response.headers.get('x-csrf-token')
158 const cookie = joinSetCookies(response)
159 if (!token) return null
160 return { token, cookie }
161}
162
163function resolveHost(req: ProxyRequest): string {
164 if (req.deploymentType === 'cloud_public') {

Callers 1

route.tsFile · 0.85

Calls 7

buildOdataUrlFunction · 0.85
joinSetCookiesFunction · 0.85
textMethod · 0.80
buildAuthHeaderFunction · 0.70
warnMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected