|
@@ -3,55 +3,35 @@ using Invercargill;
|
|
|
|
|
|
|
|
namespace Astralis {
|
|
namespace Astralis {
|
|
|
|
|
|
|
|
- public class Request : Object {
|
|
|
|
|
- public string url { get; private set; }
|
|
|
|
|
|
|
+ public class HttpRequest : Object {
|
|
|
|
|
+ public string raw_path { get; private set; }
|
|
|
public string method { get; private set; }
|
|
public string method { get; private set; }
|
|
|
public string version { get; private set; }
|
|
public string version { get; private set; }
|
|
|
|
|
+
|
|
|
|
|
+ public Enumerable<string> path_components { get; private set; }
|
|
|
|
|
+
|
|
|
|
|
+ public Enumerable<HttpHeader> headers { get; private set; }
|
|
|
|
|
|
|
|
- public Request(string url, string method, string version) {
|
|
|
|
|
- this.url = url;
|
|
|
|
|
|
|
+ public HttpRequest(string url, string method, string version) {
|
|
|
|
|
+ this.raw_path = url;
|
|
|
this.method = method;
|
|
this.method = method;
|
|
|
this.version = version;
|
|
this.version = version;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ var path_parts = this.raw_path.split("?");
|
|
|
|
|
+ this.path_components = Wrap.array<string>(path_parts[0].split("/"))
|
|
|
|
|
+ .select<string>(p => Uri.unescape_string (p) ?? "")
|
|
|
|
|
+ .where (p => p != "")
|
|
|
|
|
+ .to_immutable_buffer();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public class HttpContext : Object {
|
|
public class HttpContext : Object {
|
|
|
- public Request request { get; private set; }
|
|
|
|
|
- private Connection connection;
|
|
|
|
|
|
|
+ public HttpRequest request { get; private set; }
|
|
|
|
|
|
|
|
- internal HttpContext(Connection connection, Request request) {
|
|
|
|
|
|
|
+ internal HttpContext(HttpRequest request) {
|
|
|
this.request = request;
|
|
this.request = request;
|
|
|
- this.connection = connection;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void respond(StatusCode status, Enumerable<HttpHeader> headers, uint8[] buffer) {
|
|
|
|
|
- var mhd_response = new Response.from_buffer(
|
|
|
|
|
- buffer.length,
|
|
|
|
|
- buffer,
|
|
|
|
|
- ResponseMemoryMode.RESPMEM_MUST_COPY
|
|
|
|
|
- );
|
|
|
|
|
- add_response_headers(mhd_response, headers);
|
|
|
|
|
- queue_response(status, mhd_response);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void respond_string(StatusCode status, string response, string content_type = "text/plain") {
|
|
|
|
|
- var headers = Iterate.these<HttpHeader>(new HttpHeader("Content-Type", content_type));
|
|
|
|
|
- respond(status, headers, response.data);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- internal static void add_response_headers(Response response, Enumerable<HttpHeader> headers) {
|
|
|
|
|
- foreach (var header in headers) {
|
|
|
|
|
- response.add_header(header.header, header.value);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- internal void queue_response(StatusCode status, Response response) {
|
|
|
|
|
- var res = MHD.queue_response(connection, status, response);
|
|
|
|
|
- if(res != MHD.Result.YES) {
|
|
|
|
|
- printerr("Astralis Internal Error: Unable to queue response\n");
|
|
|
|
|
- }
|
|
|
|
|
- MHD.resume_connection(connection);
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|