Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Side by Side Diff: runtime/bin/http.dart

Issue 10082003: Start refactoring of the HTTP header handling (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/bin/http_impl.dart » ('j') | runtime/bin/http_impl.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * HTTP status codes. 6 * HTTP status codes.
7 */ 7 */
8 interface HttpStatus { 8 interface HttpStatus {
9 static final int CONTINUE = 100; 9 static final int CONTINUE = 100;
10 static final int SWITCHING_PROTOCOLS = 101; 10 static final int SWITCHING_PROTOCOLS = 101;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 void set onRequest(void callback(HttpRequest, HttpResponse)); 93 void set onRequest(void callback(HttpRequest, HttpResponse));
94 94
95 /** 95 /**
96 * Sets the error handler that is called when a connection error occurs. 96 * Sets the error handler that is called when a connection error occurs.
97 */ 97 */
98 void set onError(void callback(Exception e)); 98 void set onError(void callback(Exception e));
99 } 99 }
100 100
101 101
102 /** 102 /**
103 * Access to the HTTP headers for requests and responses. In some
104 * situations the headers will be imutable and the mutating methods
105 * will then throw exceptions.
106 *
107 * For all operation on HTTP headers the header name is
108 * case-insensitive.
109 */
110 interface HttpHeaders default _HttpHeaders {
111 static final ACCEPT = "Accept";
112 static final ACCEPT_CHARSET = "Accept-Charset";
113 static final ACCEPT_ENCODING = "Accept-Encoding";
114 static final ACCEPT_LANGUAGE = "Accept-Language";
115 static final ACCEPT_RANGES = "Accept-Ranges";
116 static final AGE = "Age";
117 static final ALLOW = "Allow";
118 static final AUTHORIZATION = "Authorization";
119 static final CACHE_CONTROL = "Cache-Control";
120 static final CONNECTION = "Connection";
121 static final CONTENT_ENCODING = "Content-Encoding";
122 static final CONTENT_LANGUAGE = "Content-Language";
123 static final CONTENT_LENGTH = "Content-Length";
124 static final CONTENT_LOCATION = "Content-Location";
125 static final CONTENT_MD5 = "Content-MD5";
126 static final CONTENT_RANGE = "Content-Range";
127 static final CONTENT_TYPE = "Content-Type";
128 static final DATE = "Date";
129 static final ETAG = "ETag";
130 static final EXPECT = "Expect";
131 static final EXPIRES = "Expires";
132 static final FROM = "From";
133 static final HOST = "Host";
134 static final IF_MATCH = "If-Match";
135 static final IF_MODIFIED_SINCE = "If-Modified-Since";
136 static final IF_NONE_MATCH = "If-None-Match";
137 static final IF_RANGE = "If-Range";
138 static final IF_UNMODIFIED_SINCE = "If-Unmodified-Since";
139 static final LAST_MODIFIED = "Last-Modified";
140 static final LOCATION = "Location";
141 static final MAX_FORWARDS = "Max-Forwards";
142 static final PRAGMA = "Pragma";
143 static final PROXY_AUTHENTICATE = "Proxy-Authenticate";
144 static final PROXY_AUTHORIZATION = "Proxy-Authorization";
145 static final RANGE = "Range";
146 static final REFERER = "Referer";
147 static final RETRY_AFTER = "Retry-After";
148 static final SERVER = "Server";
149 static final TE = "TE";
150 static final TRAILER = "Trailer";
151 static final TRANSFER_ENCODING = "Transfer-Encoding";
152 static final UPGRADE = "Upgrade";
153 static final USER_AGENT = "User-Agent";
154 static final VARY = "Vary";
155 static final VIA = "Via";
156 static final WARNING = "Warning";
157 static final WWW_AUTHENTICATE = "WWW-Authenticate";
158
159 static final GENERAL_HEADERS = const [CACHE_CONTROL,
160 CONNECTION,
161 DATE,
162 PRAGMA,
163 TRAILER,
164 TRANSFER_ENCODING,
165 UPGRADE,
166 VIA,
167 WARNING];
168
169 static final ENTITY_HEADERS = const [ALLOW,
170 CONTENT-ENCODING,
171 CONTENT-LANGUAGE,
172 CONTENT-LENGTH,
173 CONTENT-LOCATION,
174 CONTENT-MD5,
175 CONTENT-RANGE,
176 CONTENT-TYPE,
177 EXPIRES,
178 LAST-MODIFIED];
179
180
181 static final RESPONSE_HEADERS = const [ACCEPT-RANGES,
182 AGE,
183 ETAG,
184 LOCATION,
185 PROXY-AUTHENTICATE,
186 RETRY-AFTER,
187 SERVER,
188 VARY,
189 WWW-AUTHENTICATE];
190
191 static final REQUEST_HEADERS = const [ACCEPT,
192 ACCEPT-CHARSET,
193 ACCEPT-ENCODING,
194 ACCEPT-LANGUAGE,
195 AUTHORIZATION,
196 EXPECT,
197 FROM,
198 HOST,
199 IF-MATCH,
200 IF-MODIFIED-SINCE,
201 IF-NONE-MATCH,
202 IF-RANGE,
203 IF-UNMODIFIED-SINCE,
204 MAX-FORWARDS,
205 PROXY-AUTHORIZATION,
206 RANGE,
207 REFERER,
208 TE,
209 USER-AGENT];
210
211 /**
212 * Returns the list of values for the header named [name]. If there
213 * is no headers with the provided name null will be returned.
214 */
215 List<String> operator[](String name);
216
217 /**
218 * Adds a header value. The header named [name] will have the value
219 * [value] added to its list of values. Some headers are single
220 * values and for these adding a value will replace the previous
221 * value. If the value is of type Date a HTTP date format will be
222 * applied. If the value is a [:List:] each element of the list will
223 * be added separately. For all other types the default [:toString:]
224 * method will be used.
225 */
226 void add(String name, Object value);
227
228 /**
229 * Sets a header. The header named [name] will have all its values
230 * cleared before the value [value] is added as its value.
231 */
232 void set(String name, Object value);
233
234 /**
235 * Removes a specific value for a header name. Some headers have
236 * system supplied values and for these the system supplied values
237 * will still be added to the collection of values for the header.
238 */
239 void remove(String name, Object value);
240
241 /**
242 * Remove all values for the specified header name. Some headers
243 * have system supplied values and for these the system supplied
244 * values will still be added to the collection of values for the
245 * header.
246 */
247 void removeAll(String name);
248 }
249
250
251 /**
103 * Http request delivered to the HTTP server callback. 252 * Http request delivered to the HTTP server callback.
104 */ 253 */
105 interface HttpRequest default _HttpRequest { 254 interface HttpRequest default _HttpRequest {
106 /** 255 /**
107 * Returns the content length of the request body. If the size of 256 * Returns the content length of the request body. If the size of
108 * the request body is not known in advance this -1. 257 * the request body is not known in advance this -1.
109 */ 258 */
110 int get contentLength(); 259 int get contentLength();
111 260
112 /** 261 /**
(...skipping 17 matching lines...) Expand all
130 String get queryString(); 279 String get queryString();
131 280
132 /** 281 /**
133 * Returns the parsed query string. 282 * Returns the parsed query string.
134 */ 283 */
135 Map<String, String> get queryParameters(); 284 Map<String, String> get queryParameters();
136 285
137 /** 286 /**
138 * Returns the request headers. 287 * Returns the request headers.
139 */ 288 */
140 Map<String, String> get headers(); 289 HttpHeaders get headers();
141 290
142 /** 291 /**
143 * Returns the input stream for the request. This is used to read 292 * Returns the input stream for the request. This is used to read
144 * the request data. 293 * the request data.
145 */ 294 */
146 InputStream get inputStream(); 295 InputStream get inputStream();
147 } 296 }
148 297
149 298
150 /** 299 /**
(...skipping 20 matching lines...) Expand all
171 */ 320 */
172 String reasonPhrase; 321 String reasonPhrase;
173 322
174 /** 323 /**
175 * Gets and sets the expiry date. The value of this property will 324 * Gets and sets the expiry date. The value of this property will
176 * reflect the "Expires" header 325 * reflect the "Expires" header
177 */ 326 */
178 Date expires; 327 Date expires;
179 328
180 /** 329 /**
181 * Sets a header on the response. NOTE: If the same header name is
182 * set more than once only the last value will be part of the
183 * response.
184 */
185 void setHeader(String name, String value);
186
187 /**
188 * Returns the response headers. 330 * Returns the response headers.
189 */ 331 */
190 Map<String, String> get headers(); 332 HttpHeaders get headers();
191 333
192 /** 334 /**
193 * Returns the output stream for the response. This is used to write 335 * Returns the output stream for the response. This is used to write
194 * the response data. When all response data has been written close 336 * the response data. When all response data has been written close
195 * the stream to indicate the end of the response. 337 * the stream to indicate the end of the response.
196 * 338 *
197 * When this is accessed for the first time the response header is 339 * When this is accessed for the first time the response header is
198 * send. Calling any methods that will change the header after 340 * send. Calling any methods that will change the header after
199 * having retrieved the output stream will throw an exception. 341 * having retrieved the output stream will throw an exception.
200 */ 342 */
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 String host; 452 String host;
311 453
312 /** 454 /**
313 * Gets and sets the port part of the "Host" header for the 455 * Gets and sets the port part of the "Host" header for the
314 * connection. By default this will be set to the value of the port 456 * connection. By default this will be set to the value of the port
315 * used when initiating the connection. 457 * used when initiating the connection.
316 */ 458 */
317 int port; 459 int port;
318 460
319 /** 461 /**
320 * Sets a header on the request. NOTE: If the same header name is
321 * set more than once only the last value set will be part of the
322 * request.
323 */
324 void setHeader(String name, String value);
325
326 /**
327 * Returns the request headers. 462 * Returns the request headers.
328 */ 463 */
329 Map<String, String> get headers(); 464 HttpHeaders get headers();
330 465
331 /** 466 /**
332 * Returns the output stream for the request. This is used to write 467 * Returns the output stream for the request. This is used to write
333 * the request data. When all request data has been written close 468 * the request data. When all request data has been written close
334 * the stream to indicate the end of the request. 469 * the stream to indicate the end of the request.
335 * 470 *
336 * When this is accessed for the first time the request header is 471 * When this is accessed for the first time the request header is
337 * send. Calling any methods that will change the header after 472 * send. Calling any methods that will change the header after
338 * having retrieved the output stream will throw an exception. 473 * having retrieved the output stream will throw an exception.
339 */ 474 */
(...skipping 25 matching lines...) Expand all
365 * Returns the date value for the "Expires" header. Returns null if 500 * Returns the date value for the "Expires" header. Returns null if
366 * the response has no "Expires" header. Throws a HttpException if 501 * the response has no "Expires" header. Throws a HttpException if
367 * the response has an "Expires" header which is not formatted as a 502 * the response has an "Expires" header which is not formatted as a
368 * valid HTTP date. 503 * valid HTTP date.
369 */ 504 */
370 Date get expires(); 505 Date get expires();
371 506
372 /** 507 /**
373 * Returns the response headers. 508 * Returns the response headers.
374 */ 509 */
375 Map<String, String> get headers(); 510 HttpHeaders get headers();
376 511
377 /** 512 /**
378 * Returns the input stream for the response. This is used to read 513 * Returns the input stream for the response. This is used to read
379 * the response data. 514 * the response data.
380 */ 515 */
381 InputStream get inputStream(); 516 InputStream get inputStream();
382 } 517 }
383 518
384 519
385 class HttpException implements Exception { 520 class HttpException implements Exception {
386 const HttpException([String this.message = ""]); 521 const HttpException([String this.message = ""]);
387 String toString() => "HttpException: $message"; 522 String toString() => "HttpException: $message";
388 final String message; 523 final String message;
389 } 524 }
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/http_impl.dart » ('j') | runtime/bin/http_impl.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698