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 = null) 25 { 26 this._request = request; 27 if (_request is null) 28 _request = new HttpRequest; 29 } 30 31 void onMethod(const(char)[] method) 32 { 33 _request.method(getHttpMethodFromString(method.to!string)); 34 } 35 36 void onUri(const(char)[] uri) 37 { 38 _request.uri(Url(uri.to!string)); 39 } 40 41 int onVersion(const(char)[] ver) 42 { 43 auto minorVer = parseHttpVersion(ver); 44 return minorVer >= 0 ? 0 : minorVer; 45 } 46 47 void onHeader(const(char)[] name, const(char)[] value) 48 { 49 _request.header(name.to!string, value.to!string); 50 } 51 52 void onStatus(int status) { 53 // Request 不处理 54 } 55 56 void onStatusMsg(const(char)[] statusMsg) { 57 // Request 不处理 58 } 59 60 HttpRequest request() 61 { 62 return _request; 63 } 64 65 // void reset() 66 // { 67 // _request.reset(); 68 // } 69 70 private HttpRequest _request; 71 }