MCPcopy
hub / github.com/stenciljs/core / normalizeHttpRequest

Function normalizeHttpRequest

src/dev-server/request-handler.ts:127–160  ·  view source on GitHub ↗
(devServerConfig: d.DevServerConfig, incomingReq: IncomingMessage)

Source from the content-addressed store, hash-verified

125}
126
127function normalizeHttpRequest(devServerConfig: d.DevServerConfig, incomingReq: IncomingMessage) {
128 const req: d.HttpRequest = {
129 method: (incomingReq.method || 'GET').toUpperCase() as any,
130 headers: incomingReq.headers as any,
131 acceptHeader:
132 (incomingReq.headers && typeof incomingReq.headers.accept === 'string' && incomingReq.headers.accept) || '',
133 host: (incomingReq.headers && typeof incomingReq.headers.host === 'string' && incomingReq.headers.host) || null,
134 url: null,
135 searchParams: null,
136 };
137
138 const incomingUrl = (incomingReq.url || '').trim() || null;
139 if (incomingUrl) {
140 if (req.host) {
141 req.url = new URL(incomingReq.url, `http://${req.host}`);
142 } else {
143 req.url = new URL(incomingReq.url, `http://dev.stenciljs.com`);
144 }
145 req.searchParams = req.url.searchParams;
146 }
147
148 if (req.url) {
149 const parts = req.url.pathname.replace(/\\/g, '/').split('/');
150
151 req.pathname = parts.map((part) => decodeURIComponent(part)).join('/');
152 if (req.pathname.length > 0 && !isDevClient(req.pathname)) {
153 req.pathname = '/' + req.pathname.substring(devServerConfig.basePath.length);
154 }
155
156 req.filePath = normalizePath(path.normalize(path.join(devServerConfig.root, path.relative('/', req.pathname))));
157 }
158
159 return req;
160}
161
162export function isValidHistoryApi(devServerConfig: d.DevServerConfig, req: d.HttpRequest) {
163 if (!devServerConfig.historyApiFallback) {

Callers 1

defaultHandlerFunction · 0.85

Calls 6

isDevClientFunction · 0.90
normalizePathFunction · 0.85
joinMethod · 0.80
normalizeMethod · 0.80
relativeMethod · 0.80
replaceMethod · 0.65

Tested by

no test coverage detected