Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/httpParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
25 changes: 12 additions & 13 deletions server/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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');

Expand Down Expand Up @@ -68,7 +66,7 @@ class Response {
}

/**
*
*
* @param {number} code - The HTTP status code.
* @returns - The Response instance.
*/
Expand All @@ -81,7 +79,7 @@ class Response {
}

/**
*
*
* @param {string} key - The header key.
* @param {string} value - The header value.
* @returns - The Response instance.
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
*/
Expand All @@ -156,7 +154,7 @@ class Response {
}

/**
*
*
* @param {*} data - The data to send.
*/
json (data) {
Expand All @@ -172,7 +170,7 @@ class Response {
}

/**
*
*
* @param {*} file - The file to send.
*/
sendFile (file) {
Expand Down Expand Up @@ -208,7 +206,7 @@ class Response {
}

/**
*
*
* @param {*} file - The file to send.
* @param {*} filename - The filename to send.
*/
Expand Down Expand Up @@ -244,7 +242,8 @@ class Response {
})
return null
}
end () {

end () {
this.socket.end()
}
}
Expand Down
Loading