UNPKG

f2e-server3

Version:

f2e-server 3.0

47 lines (46 loc) 1.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NativeRequest = void 0; class NativeRequest { request; location; searchParams; constructor(req) { this.request = req; this.location = new URL(req.url || '/', 'http://localhost'); this.searchParams = new URLSearchParams(this.location.search?.replace(/^[?]+/, '')); } getHeader(lowerCaseKey) { return this.request.headers[lowerCaseKey.toString()]?.toString() || ''; } getParameter(index) { return [...this.searchParams][index]?.join('='); } getUrl() { return this.location.pathname || '/'; } getMethod() { return this.getCaseSensitiveMethod().toLowerCase(); } getCaseSensitiveMethod() { return this.request.method || 'GET'; } getQuery(key) { if (key) { return this.searchParams.get(key.toString()) || undefined; } else { return this.location.search?.replace(/^[?]+/, '') || undefined; } } forEach(cb) { const headers = this.request.rawHeaders; for (let i = 0; i < headers.length; i += 2) { cb?.(headers[i], headers[i + 1]); } } setYield(_yield) { throw new Error('Method not implemented.'); } } exports.NativeRequest = NativeRequest;