diff --git a/lib/httpParser.js b/lib/httpParser.js index 713ffbe..a60b9bd 100644 --- a/lib/httpParser.js +++ b/lib/httpParser.js @@ -11,7 +11,7 @@ async function httpParser (request) { if (headerBodySplit.length < 1) { throw new Error('Invalid HTTP request format') } - + const headersPart = headerBodySplit[0] // First part is the headers const bodyPart = headerBodySplit[1] || '' // Second part is the body, default to empty string if no body @@ -35,7 +35,7 @@ async function httpParser (request) { if (line) { const colonIndex = line.indexOf(':') if (colonIndex === -1) continue // Skip malformed headers - + const key = line.slice(0, colonIndex).trim().toLowerCase() const value = line.slice(colonIndex + 1).trim() req.headers[key] = value diff --git a/server/response.js b/server/response.js index a521e65..d94efaf 100644 --- a/server/response.js +++ b/server/response.js @@ -2,7 +2,6 @@ const fs = require('fs') const { lookupMimeType } = require('../lib/utils') const path = require('path') - const STATUS_CODES = Object.freeze({ 200: 'OK', 201: 'Created', @@ -25,16 +24,15 @@ const STATUS_CODES = Object.freeze({ 503: 'Service Unavailable' }) - /** * Response class for handling HTTP responses. - * + * * @class Response - * + * * @param {Socket} socket - The socket object for the response. * @param {boolean} enableCors - Enable Cross-Origin Resource Sharing (CORS). * @param {string} statusTextMap - Map of status codes to status texts. - * @example + * @example * ```javascript const Response = require('./response.js'); @@ -68,7 +66,7 @@ class Response { } /** - * + * * @param {number} code - The HTTP status code. * @returns - The Response instance. */ @@ -81,7 +79,7 @@ class Response { } /** - * + * * @param {string} key - The header key. * @param {string} value - The header value. * @returns - The Response instance. @@ -115,7 +113,7 @@ class Response { } /** - * + * * @param {string} data - The data to send. * @returns - If the data is an object or array, send as JSON */ @@ -144,7 +142,7 @@ class Response { } /** - * + * * @param {number} statusCode - The HTTP status code. * Updates the status code and sends the status code as a response. */ @@ -156,7 +154,7 @@ class Response { } /** - * + * * @param {*} data - The data to send. */ json (data) { @@ -172,7 +170,7 @@ class Response { } /** - * + * * @param {*} file - The file to send. */ sendFile (file) { @@ -208,7 +206,7 @@ class Response { } /** - * + * * @param {*} file - The file to send. * @param {*} filename - The filename to send. */ @@ -244,7 +242,8 @@ class Response { }) return null } - end () { + + end () { this.socket.end() } }