1 module hunt.http.codec.http.model.HttpComplianceSection; 2 3 import std.algorithm; 4 5 struct HttpComplianceSection { 6 enum HttpComplianceSection Null = HttpComplianceSection("Null", "", "Null"); 7 enum HttpComplianceSection CASE_INSENSITIVE_FIELD_VALUE_CACHE = HttpComplianceSection("CASE_INSENSITIVE_FIELD_VALUE_CACHE", "", "Use case insensitive field value cache"); 8 enum HttpComplianceSection METHOD_CASE_SENSITIVE = HttpComplianceSection("METHOD_CASE_SENSITIVE", "https://tools.ietf.org/html/rfc7230#section-3.1.1", "Method is case-sensitive"); 9 enum HttpComplianceSection FIELD_COLON = HttpComplianceSection("FIELD_COLON", "https://tools.ietf.org/html/rfc7230#section-3.2", "Fields must have a Colon"); 10 enum HttpComplianceSection FIELD_NAME_CASE_INSENSITIVE = HttpComplianceSection("FIELD_NAME_CASE_INSENSITIVE", "https://tools.ietf.org/html/rfc7230#section-3.2", "Field name is case-insensitive"); 11 enum HttpComplianceSection NO_WS_AFTER_FIELD_NAME = HttpComplianceSection("NO_WS_AFTER_FIELD_NAME", "https://tools.ietf.org/html/rfc7230#section-3.2.4", "Whitespace not allowed after field name"); 12 enum HttpComplianceSection NO_FIELD_FOLDING = HttpComplianceSection("NO_FIELD_FOLDING", "https://tools.ietf.org/html/rfc7230#section-3.2.4", "No line Folding"); 13 enum HttpComplianceSection NO_HTTP_0_9 = HttpComplianceSection("NO_HTTP_0_9", "https://tools.ietf.org/html/rfc7230#appendix-A.2", "No HTTP/0.9"); 14 15 private string _name; 16 string url; 17 string description; 18 19 this(string name, string url, string description) { 20 this._name = name; 21 this.url = url; 22 this.description = description; 23 } 24 25 string name() { return _name; } 26 27 string getURL() { 28 return url; 29 } 30 31 string getDescription() { 32 return description; 33 } 34 35 size_t toHash() @trusted nothrow { 36 return hashOf(_name); 37 } 38 39 int opCmp(ref HttpComplianceSection b) { 40 return std.algorithm.cmp(_name, b._name); 41 } 42 43 __gshared HttpComplianceSection[string] values; 44 45 shared static this() 46 { 47 values[CASE_INSENSITIVE_FIELD_VALUE_CACHE.name] = CASE_INSENSITIVE_FIELD_VALUE_CACHE; 48 values[METHOD_CASE_SENSITIVE.name] = METHOD_CASE_SENSITIVE; 49 values[FIELD_COLON.name] = FIELD_COLON; 50 values[FIELD_NAME_CASE_INSENSITIVE.name] = FIELD_NAME_CASE_INSENSITIVE; 51 values[NO_WS_AFTER_FIELD_NAME.name] = NO_WS_AFTER_FIELD_NAME; 52 values[NO_FIELD_FOLDING.name] = NO_FIELD_FOLDING; 53 values[NO_HTTP_0_9.name] = NO_HTTP_0_9; 54 55 } 56 57 58 static HttpComplianceSection valueOf(string name) 59 { 60 return values.get(name, HttpComplianceSection.Null); 61 } 62 63 }