MCPcopy Create free account
hub / github.com/ShaanCoding/makeread.me / getHeaders

Function getHeaders

frontend/openAPI/generated/core/request.ts:139–180  ·  view source on GitHub ↗
(config: OpenAPIConfig, options: ApiRequestOptions)

Source from the content-addressed store, hash-verified

137};
138
139export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise<Headers> => {
140 const [token, username, password, additionalHeaders] = await Promise.all([
141 resolve(options, config.TOKEN),
142 resolve(options, config.USERNAME),
143 resolve(options, config.PASSWORD),
144 resolve(options, config.HEADERS),
145 ]);
146
147 const headers = Object.entries({
148 Accept: 'application/json',
149 ...additionalHeaders,
150 ...options.headers,
151 })
152 .filter(([_, value]) => isDefined(value))
153 .reduce((headers, [key, value]) => ({
154 ...headers,
155 [key]: String(value),
156 }), {} as Record<string, string>);
157
158 if (isStringWithValue(token)) {
159 headers['Authorization'] = `Bearer ${token}`;
160 }
161
162 if (isStringWithValue(username) && isStringWithValue(password)) {
163 const credentials = base64(`${username}:${password}`);
164 headers['Authorization'] = `Basic ${credentials}`;
165 }
166
167 if (options.body !== undefined) {
168 if (options.mediaType) {
169 headers['Content-Type'] = options.mediaType;
170 } else if (isBlob(options.body)) {
171 headers['Content-Type'] = options.body.type || 'application/octet-stream';
172 } else if (isString(options.body)) {
173 headers['Content-Type'] = 'text/plain';
174 } else if (!isFormData(options.body)) {
175 headers['Content-Type'] = 'application/json';
176 }
177 }
178
179 return new Headers(headers);
180};
181
182export const getRequestBody = (options: ApiRequestOptions): any => {
183 if (options.body !== undefined) {

Callers 1

requestFunction · 0.85

Calls 7

resolveFunction · 0.85
isDefinedFunction · 0.85
isStringWithValueFunction · 0.85
base64Function · 0.85
isBlobFunction · 0.85
isStringFunction · 0.85
isFormDataFunction · 0.85

Tested by

no test coverage detected