import nitcorn
+# Nitcorn Action used to answer requests.
class HTCPCPAction
super Action
+
+ # Brewing status.
var brewing = false
- var is_teapot = false
+
+ # Teapot status.
+ var is_teapot = false
redef fun answer(http_request, turi) do
var message: String
var method = http_request.method
- var headers = http_request.header
var response: HttpResponse
if is_teapot == true then
end
end
-
+# Nitcorn server.
class HTCPCServer
+
+ # Port to listen to.
var port: Int
+ # Start listening.
fun run do
var vh = new VirtualHost("localhost:{port}")
vh.routes.add new Route("/", new HTCPCPAction)
# A request received over HTTP, is build by `HttpRequestParser`
class HttpRequest
- private init do end
+ private init is old_style_init do end
# HTTP protocol version
var http_version: String
# Words of the first line
private var first_line = new Array[String]
+ # Parse the `first_line`, `header_fields` and `body` of `full_request`.
fun parse_http_request(full_request: String): nullable HttpRequest
do
clear_data
# All know code and their message
var codes = new HashMap[Int, String]
- protected init do insert_status_codes
+ # Init the status `codes` list.
+ protected init is old_style_init do insert_status_codes
# Get the message associated to the status `code`, return `null` in unknown
fun [](code: Int): nullable String
# Map of known MIME types
class MediaTypes
+
+ # MIME types by extensions.
protected var types = new HashMap[String, String]
# Get the type/subtype associated to a file extension `ext`
end
end
+# MIME types list.
fun media_types: MediaTypes do return once new MediaTypes