Module: PudimServer.http
HTTP request parsing and response generation.
http:ParseRequest(raw)
Transforms the raw HTTP string into a table with method, path, version, headers, body, query, and params.
Inputs: raw (string containing the full HTTP request).
Output: parsed Request table.
local http = require("PudimServer.http")
local req = http:ParseRequest(rawRequest)
http:response(status, body, headers?)
Builds the final HTTP response; when body is a table, it is automatically converted to JSON.
Inputs: status (number), body (string|table), headers? (optional table).
Output: HTTP string ready to send through the socket.
return http:response(200, { ok = true })
Supported Status Codes
The response method automatically maps these status codes to their reason phrase. Any unlisted code will produce an empty reason.
| Code | Reason Phrase |
|---|---|
| 100 | Continue |
| 101 | Switching Protocols |
| 102 | Processing |
| 200 | OK |
| 201 | Created |
| 202 | Accepted |
| 204 | No Content |
| 301 | Moved Permanently |
| 302 | Found |
| 304 | Not Modified |
| 400 | Bad Request |
| 401 | Unauthorized |
| 403 | Forbidden |
| 404 | Not Found |
| 405 | Method Not Allowed |
| 409 | Conflict |
| 415 | Unsupported Media Type |
| 422 | Unprocessable Entity |
| 429 | Too Many Requests |
| 500 | Internal Server Error |
| 501 | Not Implemented |
| 502 | Bad Gateway |
| 503 | Service Unavailable |
| 504 | Gateway Timeout |