#
# Copyright 2013 Jean-Philippe Caissy <jpcaissy@piji.ca>
# Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
+# Copyright 2014 Alexandre Terrasa <alexandre@moz-code.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
module reactor
import more_collections
-import libevent
+import http_request_parser
-import server_config
+import vararg_routes
import http_request
import http_response
# The associated `HttpFactory`
var factory: HttpFactory
- init(buf_ev: NativeBufferEvent, factory: HttpFactory) do self.factory = factory
+ # Init the server using `HttpFactory`.
+ init(buf_ev: NativeBufferEvent, factory: HttpFactory) is old_style_init do
+ self.factory = factory
+ end
private var parser = new HttpRequestParser is lazy
redef fun read_callback(str)
do
- # TODO support bigger inputs (such as big forms and file upload)
-
var request_object = parser.parse_http_request(str.to_s)
-
if request_object != null then delegate_answer request_object
end
end label
end
+ # Use default virtual host if none already responded
+ if virtual_host == null then virtual_host = factory.config.default_virtual_host
+
# Get a response from the virtual host
var response
if virtual_host != null then
var route = virtual_host.routes[request.uri]
if route != null then
+ # include uri parameters in request
+ request.uri_params = route.parse_params(request.uri)
+
var handler = route.handler
var root = route.path
var turi
# `request` is fully formed request object and has a reference to the session
# if one preexists.
#
- # `truncated_uri` is the ending of the fulle request URI, truncated from the route
+ # `truncated_uri` is the ending of the full request URI, truncated from the route
# leading to this `Action`.
fun answer(request: HttpRequest, truncated_uri: String): HttpResponse is abstract
end