MCPcopy Create free account
hub / github.com/arctic-cli/interface / beforeRequest

Function beforeRequest

packages/sdk/js/src/gen/client/client.gen.ts:32–64  ·  view source on GitHub ↗
(options: RequestOptions)

Source from the content-addressed store, hash-verified

30 const interceptors = createInterceptors<Request, Response, unknown, ResolvedRequestOptions>()
31
32 const beforeRequest = async (options: RequestOptions) => {
33 const opts = {
34 ..._config,
35 ...options,
36 fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
37 headers: mergeHeaders(_config.headers, options.headers),
38 serializedBody: undefined,
39 }
40
41 if (opts.security) {
42 await setAuthParams({
43 ...opts,
44 security: opts.security,
45 })
46 }
47
48 if (opts.requestValidator) {
49 await opts.requestValidator(opts)
50 }
51
52 if (opts.body && opts.bodySerializer) {
53 opts.serializedBody = opts.bodySerializer(opts.body)
54 }
55
56 // remove Content-Type header if body is empty to avoid sending invalid requests
57 if (opts.serializedBody === undefined || opts.serializedBody === "") {
58 opts.headers.delete("Content-Type")
59 }
60
61 const url = buildUrl(opts)
62
63 return { opts, url }
64 }
65
66 const request: Client["request"] = async (options) => {
67 // @ts-expect-error

Callers 2

requestFunction · 0.70
makeMethodFunction · 0.70

Calls 4

mergeHeadersFunction · 0.90
setAuthParamsFunction · 0.90
buildUrlFunction · 0.90
deleteMethod · 0.45

Tested by

no test coverage detected