1 /*******************************************************************************
2 3 Copyright:
4 Copyright (c) 2004 Kris Bell.
5 Some parts copyright (c) 2009-2016 dunnhumby Germany GmbH.
6 All rights reserved.
7 8 License:
9 Tango Dual License: 3-Clause BSD License / Academic Free License v3.0.
10 See LICENSE_TANGO.txt for details.
11 12 Version: Initial release: April 2004
13 14 Authors: Kris
15 16 *******************************************************************************/17 18 moduleocean.net.http.HttpParams;
19 20 importocean.meta.types.Qualifiers;
21 22 importocean.time.Time;
23 24 importocean.io.model.IConduit;
25 26 importocean.net.http.HttpTokens;
27 28 importocean.io.stream.Delimiters;
29 30 publicimportocean.net.http.model.HttpParamsView;
31 32 /******************************************************************************
33 34 Maintains a set of query parameters, parsed from an HTTP request.
35 Use HttpParams instead for output parameters.
36 37 Note that these input params may have been encoded by the user-
38 agent. Unfortunately there has been little consensus on what that
39 encoding should be (especially regarding GET query-params). With
40 luck, that will change to a consistent usage of UTF-8 within the
41 near future.
42 43 ******************************************************************************/44 45 classHttpParams : HttpTokens, HttpParamsView46 {
47 // tell compiler to expose super.parse() also48 aliasHttpTokens.parseparse;
49 50 privateDelimitersamp;
51 52 /**********************************************************************
53 54 Construct parameters by telling the HttpStack that
55 name/value pairs are separated by a '=' character.
56 57 **********************************************************************/58 59 this ()
60 {
61 super ('=');
62 63 // construct a line tokenizer for later usage64 amp = newDelimiters("&");
65 }
66 67 /**********************************************************************
68 69 Return the number of headers
70 71 **********************************************************************/72 73 uintsize ()
74 {
75 returnsuper.stack.size;
76 }
77 78 /**********************************************************************
79 80 Read all query parameters. Everything is mapped rather
81 than being allocated & copied
82 83 **********************************************************************/84 85 overridevoidparse (InputBufferinput)
86 {
87 setParsed (true);
88 amp.set (input);
89 90 while (amp.next || amp.get.length)
91 stack.push (amp.get);
92 }
93 94 /**********************************************************************
95 96 Add a name/value pair to the query list
97 98 **********************************************************************/99 100 overridevoidadd (cstringname, cstringvalue)
101 {
102 super.add (name, value);
103 }
104 105 /**********************************************************************
106 107 Add a name/integer pair to the query list
108 109 **********************************************************************/110 111 overridevoidaddInt (cstringname, intvalue)
112 {
113 super.addInt (name, value);
114 }
115 116 117 /**********************************************************************
118 119 Add a name/date(long) pair to the query list
120 121 **********************************************************************/122 123 overridevoidaddDate (cstringname, Timevalue)
124 {
125 super.addDate (name, value);
126 }
127 128 /**********************************************************************
129 130 Return the value of the provided header, or null if the
131 header does not exist
132 133 **********************************************************************/134 135 overridecstringget (cstringname, cstringret = null)
136 {
137 returnsuper.get (name, ret);
138 }
139 140 /**********************************************************************
141 142 Return the integer value of the provided header, or the
143 provided default-value if the header does not exist
144 145 **********************************************************************/146 147 overrideintgetInt (cstringname, intret = -1)
148 {
149 returnsuper.getInt (name, ret);
150 }
151 152 /**********************************************************************
153 154 Return the date value of the provided header, or the
155 provided default-value if the header does not exist
156 157 **********************************************************************/158 159 overrideTimegetDate (cstringname, Timeret = Time.epoch)
160 {
161 returnsuper.getDate (name, ret);
162 }
163 164 165 /**********************************************************************
166 167 Output the param list to the provided consumer
168 169 **********************************************************************/170 171 overridevoidproduce (scopesize_tdelegate(const(void)[]) consume, cstringeol=null)
172 {
173 returnsuper.produce (consume, eol);
174 }
175 }