MCPcopy
hub / github.com/vitejs/vite / sendRawRequest

Function sendRawRequest

playground/fs-serve/__tests__/fs-serve.spec.ts:8–38  ·  view source on GitHub ↗
(baseUrl: string, requestTarget: string)

Source from the content-addressed store, hash-verified

6
7describe.runIf(isServe)('invalid request', () => {
8 const sendRawRequest = async (baseUrl: string, requestTarget: string) => {
9 return new Promise<string>((resolve, reject) => {
10 const parsedUrl = new URL(baseUrl)
11
12 const buf: Buffer[] = []
13 const client = net.createConnection(
14 { port: +parsedUrl.port, host: parsedUrl.hostname },
15 () => {
16 client.write(
17 [
18 `GET ${encodeURI(requestTarget)} HTTP/1.1`,
19 `Host: ${parsedUrl.host}`,
20 'Connection: Close',
21 '\r\n',
22 ].join('\r\n'),
23 )
24 },
25 )
26 client.on('data', (data) => {
27 buf.push(data)
28 })
29 client.on('end', (hadError) => {
30 if (!hadError) {
31 resolve(Buffer.concat(buf).toString())
32 }
33 })
34 client.on('error', (err) => {
35 reject(err)
36 })
37 })
38 }
39
40 const root = path
41 .resolve(import.meta.dirname.replace('playground', 'playground-temp'), '..')

Callers 1

fs-serve.spec.tsFile · 0.85

Calls 2

onMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected