MCPcopy
hub / github.com/axios/axios / handler

Function handler

tests/setup/server.js:209–245  ·  view source on GitHub ↗
(req)

Source from the content-addressed store, hash-verified

207
208export const startTestServer = async (port) => {
209 const handler = async (req) => {
210 const parsed = new URL(req.url, `http://localhost:${port}`);
211
212 const params = Object.fromEntries(parsed.searchParams);
213
214 const response = {
215 url: req.url,
216 pathname: parsed.pathname,
217 params,
218 method: req.method,
219 headers: req.headers,
220 };
221
222 const contentType = req.headers['content-type'] || '';
223
224 const { delay = 0 } = params;
225
226 if (+delay) {
227 await setTimeoutAsync(+delay);
228 }
229
230 switch (parsed.pathname.replace(/\/$/, '')) {
231 case '/echo/json':
232 default:
233 if (contentType.startsWith('multipart/')) {
234 const { fields, files } = await handleFormData(req);
235 response.form = fields;
236 response.files = files;
237 } else {
238 response.body = (await getStreamAsBuffer(req)).toString('hex');
239 }
240
241 return {
242 body: response,
243 };
244 }
245 };
246
247 return await startHTTPServer(
248 (req, res) => {

Callers 1

startTestServerFunction · 0.85

Calls 3

setTimeoutAsyncFunction · 0.85
handleFormDataFunction · 0.85
toStringMethod · 0.80

Tested by

no test coverage detected