1 /******************************************************************************
2 
3     HTTP header managing base class
4 
5     The names of all header fields whose values will be accessed must be added,
6     except the General-Header fields specified in RFC 2616 section 4.5.
7 
8     See_Also: http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.5
9 
10     Copyright:
11         Copyright (c) 2009-2016 dunnhumby Germany GmbH.
12         All rights reserved.
13 
14     License:
15         Boost Software License Version 1.0. See LICENSE_BOOST.txt for details.
16         Alternatively, this file may be distributed under the terms of the Tango
17         3-Clause BSD License (see LICENSE_BSD.txt for details).
18 
19  ******************************************************************************/
20 
21 module ocean.net.http.message.HttpHeader;
22 
23 
24 import ocean.meta.types.Qualifiers;
25 
26 import ocean.core.TypeConvert;
27 import ocean.core.Verify;
28 
29 import ocean.net.http.consts.HeaderFieldNames,
30        ocean.net.http.consts.HttpVersion;
31 
32 import ocean.net.util.ParamSet;
33 
34 /******************************************************************************/
35 
36 abstract class HttpHeader : ParamSet
37 {
38     /**************************************************************************
39 
40         Type alias for request header field constant definitions
41 
42      **************************************************************************/
43 
44     alias .HeaderFieldNames HeaderFieldNames;
45 
46     /**************************************************************************
47 
48         HTTP version
49 
50      **************************************************************************/
51 
52     protected HttpVersion http_version_;
53 
54     /**************************************************************************
55 
56         Constructor
57 
58      **************************************************************************/
59 
60     protected this ( in cstring[][] standard_header_lists ... )
61     {
62         super.addKeys(HeaderFieldNames.General.NameList);
63 
64         foreach (standard_headers; standard_header_lists)
65         {
66             super.addKeys(standard_headers);
67         }
68 
69         super.rehash();
70     }
71 
72     /**************************************************************************
73 
74         Sets the response HTTP version to v. v must be a known HttpVersion
75         enumerator value and not be HttpVersion.Undefined.
76 
77         reset() will not change this value.
78 
79         Params:
80             v = response HTTP version
81 
82         Returns
83             response HTTP version
84 
85      **************************************************************************/
86 
87     public HttpVersion http_version ( HttpVersion v )
88     {
89         verify(v != 0, "HTTP version undefined");
90         verify(v <= v.max, "invalid HttpVersion enumerator value");
91 
92         this.http_version_ = v;
93 
94         return v;
95     }
96 
97     /**************************************************************************
98 
99         Gets the response HTTP version.
100 
101         Returns:
102             response HTTP version
103 
104      **************************************************************************/
105 
106     public HttpVersion http_version ( )
107     {
108         return this.http_version_;
109     }
110 
111     /**************************************************************************
112 
113         Adds the elements of header_field_names to the set of request message
114         header fields of interest.
115 
116         Params:
117             header_field_names = list of header field names of interest
118 
119         Returns:
120             this instance
121 
122      **************************************************************************/
123 
124     public void addCustomHeaders ( in cstring[] header_field_names ... )
125     {
126         super.addKeys(header_field_names);
127 
128         super.rehash();
129     }
130 }