Mercurial > projects > ldc
comparison tango/tango/net/http/HttpParams.d @ 132:1700239cab2e trunk
[svn r136] MAJOR UNSTABLE UPDATE!!!
Initial commit after moving to Tango instead of Phobos.
Lots of bugfixes...
This build is not suitable for most things.
author | lindquist |
---|---|
date | Fri, 11 Jan 2008 17:57:40 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
131:5825d48b27d1 | 132:1700239cab2e |
---|---|
1 /******************************************************************************* | |
2 | |
3 copyright: Copyright (c) 2004 Kris Bell. All rights reserved | |
4 | |
5 license: BSD style: $(LICENSE) | |
6 | |
7 version: Initial release: April 2004 | |
8 | |
9 author: Kris | |
10 | |
11 *******************************************************************************/ | |
12 | |
13 module tango.net.http.HttpParams; | |
14 | |
15 private import tango.time.Time; | |
16 | |
17 private import tango.io.model.IBuffer; | |
18 | |
19 private import tango.net.http.HttpTokens; | |
20 | |
21 private import tango.io.protocol.model.IWriter; | |
22 | |
23 private import tango.text.stream.SimpleIterator; | |
24 | |
25 public import tango.net.http.model.HttpParamsView; | |
26 | |
27 /****************************************************************************** | |
28 | |
29 Maintains a set of query parameters, parsed from an HTTP request. | |
30 Use HttpParams instead for output parameters. | |
31 | |
32 Note that these input params may have been encoded by the user- | |
33 agent. Unfortunately there has been little consensus on what that | |
34 encoding should be (especially regarding GET query-params). With | |
35 luck, that will change to a consistent usage of UTF-8 within the | |
36 near future. | |
37 | |
38 ******************************************************************************/ | |
39 | |
40 class HttpParams : HttpTokens, HttpParamsView | |
41 { | |
42 // tell compiler to expose super.parse() also | |
43 alias HttpTokens.parse parse; | |
44 | |
45 private SimpleIterator!(char) amp; | |
46 | |
47 /********************************************************************** | |
48 | |
49 Construct parameters by telling the HttpStack that | |
50 name/value pairs are seperated by a '=' character. | |
51 | |
52 **********************************************************************/ | |
53 | |
54 this () | |
55 { | |
56 super ('='); | |
57 | |
58 // construct a line tokenizer for later usage | |
59 amp = new SimpleIterator!(char) ("&"); | |
60 } | |
61 | |
62 /********************************************************************** | |
63 | |
64 Construct output params upon the provided IBuffer | |
65 | |
66 **********************************************************************/ | |
67 | |
68 this (IBuffer output) | |
69 { | |
70 this(); | |
71 setOutputBuffer (output); | |
72 } | |
73 | |
74 /********************************************************************** | |
75 | |
76 Read all query parameters. Everything is mapped rather | |
77 than being allocated & copied | |
78 | |
79 **********************************************************************/ | |
80 | |
81 void parse (IBuffer input) | |
82 { | |
83 setParsed (true); | |
84 amp.set (input); | |
85 | |
86 while (amp.next || amp.get.length) | |
87 stack.push (amp.get); | |
88 } | |
89 | |
90 /********************************************************************** | |
91 | |
92 Add a name/value pair to the query list | |
93 | |
94 **********************************************************************/ | |
95 | |
96 void add (char[] name, char[] value) | |
97 { | |
98 super.add (name, value); | |
99 } | |
100 | |
101 /********************************************************************** | |
102 | |
103 Add a name/integer pair to the query list | |
104 | |
105 **********************************************************************/ | |
106 | |
107 void addInt (char[] name, int value) | |
108 { | |
109 super.addInt (name, value); | |
110 } | |
111 | |
112 | |
113 /********************************************************************** | |
114 | |
115 Add a name/date(long) pair to the query list | |
116 | |
117 **********************************************************************/ | |
118 | |
119 void addDate (char[] name, Time value) | |
120 { | |
121 super.addDate (name, value); | |
122 } | |
123 | |
124 /********************************************************************** | |
125 | |
126 Return the value of the provided header, or null if the | |
127 header does not exist | |
128 | |
129 **********************************************************************/ | |
130 | |
131 char[] get (char[] name, char[] ret = null) | |
132 { | |
133 return super.get (name, ret); | |
134 } | |
135 | |
136 /********************************************************************** | |
137 | |
138 Return the integer value of the provided header, or the | |
139 provided default-value if the header does not exist | |
140 | |
141 **********************************************************************/ | |
142 | |
143 int getInt (char[] name, int ret = -1) | |
144 { | |
145 return super.getInt (name, ret); | |
146 } | |
147 | |
148 /********************************************************************** | |
149 | |
150 Return the date value of the provided header, or the | |
151 provided default-value if the header does not exist | |
152 | |
153 **********************************************************************/ | |
154 | |
155 Time getDate (char[] name, Time ret = Time.epoch) | |
156 { | |
157 return super.getDate (name, ret); | |
158 } | |
159 | |
160 /********************************************************************** | |
161 | |
162 Output the token list to the provided writer | |
163 | |
164 **********************************************************************/ | |
165 | |
166 void write (IWriter writer) | |
167 { | |
168 super.write (writer); | |
169 } | |
170 | |
171 /********************************************************************** | |
172 | |
173 Output the param list to the provided consumer | |
174 | |
175 **********************************************************************/ | |
176 | |
177 void produce (void delegate (void[]) consume, char[] eol) | |
178 { | |
179 super.produce (consume, eol); | |
180 } | |
181 } |