1 /* 2 * Archttp - A highly performant web framework written in D. 3 * 4 * Copyright (C) 2021-2022 Kerisy.com 5 * 6 * Website: https://www.kerisy.com 7 * 8 * Licensed under the Apache-2.0 License. 9 * 10 */ 11 12 module archttp.HttpRequestParserHandler; 13 14 import archttp.HttpRequest; 15 import archttp.HttpMessageParser; 16 17 import std.stdio : writeln; 18 import std.conv : to; 19 20 import archttp.Url; 21 22 class HttpRequestParserHandler : HttpMessageHandler 23 { 24 this(HttpRequest request = new HttpRequest) 25 { 26 this._request = request; 27 } 28 29 void onMethod(const(char)[] method) 30 { 31 _request.method(getHttpMethodFromString(method.to!string)); 32 } 33 34 void onUri(const(char)[] uri) 35 { 36 _request.uri(Url(uri.to!string)); 37 } 38 39 int onVersion(const(char)[] ver) 40 { 41 auto minorVer = parseHttpVersion(ver); 42 return minorVer >= 0 ? 0 : minorVer; 43 } 44 45 void onHeader(const(char)[] name, const(char)[] value) 46 { 47 _request.header(name.to!string, value.to!string); 48 } 49 50 void onStatus(int status) { 51 // Request 不处理 52 } 53 54 void onStatusMsg(const(char)[] statusMsg) { 55 // Request 不处理 56 } 57 58 HttpRequest request() 59 { 60 return _request; 61 } 62 63 void reset() 64 { 65 _request = new HttpRequest; 66 } 67 68 private HttpRequest _request; 69 }