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

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

Issue 10407002: Add special handling of the content type HTTP header (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Removed the content type caching to simplify. Created 8 years, 7 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') | no next file with comments »
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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 IF-UNMODIFIED-SINCE, 218 IF-UNMODIFIED-SINCE,
219 MAX-FORWARDS, 219 MAX-FORWARDS,
220 PROXY-AUTHORIZATION, 220 PROXY-AUTHORIZATION,
221 RANGE, 221 RANGE,
222 REFERER, 222 REFERER,
223 TE, 223 TE,
224 USER-AGENT]; 224 USER-AGENT];
225 225
226 /** 226 /**
227 * Returns the list of values for the header named [name]. If there 227 * Returns the list of values for the header named [name]. If there
228 * is no headers with the provided name null will be returned. 228 * is no headers with the provided name [:null:] will be returned.
229 */ 229 */
230 List<String> operator[](String name); 230 List<String> operator[](String name);
231 231
232 /** 232 /**
233 * Convenience method for the value for a single values header. If 233 * Convenience method for the value for a single values header. If
234 * there is no header with the provided name null will be 234 * there is no header with the provided name [:null:] will be
235 * returned. If the header has more than one value an exception is 235 * returned. If the header has more than one value an exception is
236 * thrown. 236 * thrown.
237 */ 237 */
238 String value(String name); 238 String value(String name);
239 239
240 /** 240 /**
241 * Adds a header value. The header named [name] will have the value 241 * Adds a header value. The header named [name] will have the value
242 * [value] added to its list of values. Some headers are single 242 * [value] added to its list of values. Some headers are single
243 * values and for these adding a value will replace the previous 243 * values and for these adding a value will replace the previous
244 * value. If the value is of type Date a HTTP date format will be 244 * value. If the value is of type Date a HTTP date format will be
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 * Gets and sets the host part of the "Host" header for the 292 * Gets and sets the host part of the "Host" header for the
293 * connection. 293 * connection.
294 */ 294 */
295 String host; 295 String host;
296 296
297 /** 297 /**
298 * Gets and sets the port part of the "Host" header for the 298 * Gets and sets the port part of the "Host" header for the
299 * connection. 299 * connection.
300 */ 300 */
301 int port; 301 int port;
302
303 /**
304 * Gets and sets the content type. Note that the content type in the
305 * header will only be updated if this field is set
306 * directly. Mutating the returned current value will have no
307 * effect.
308 */
309 ContentType contentType;
302 } 310 }
303 311
304 312
313 /**
314 * Representation of a header value in the form:
315 *
316 * [:value; parameter1=value1; parameter2=value2:]
317 *
318 * [HeaderValue] can be used to conveniently build and parse header
319 * values on this form.
320 *
321 * To build an [:Accepts:] header with the value
322 *
323 * text/plain; q=0.3, text/html
324 *
325 * use code like this:
326 *
327 * HttpClientRequest request = ...;
328 * var v = new HeaderValue();
329 * v.value = "text/plain";
330 * v.parameters["q"] = "0.3"
331 * request.headers.add(HttpHeaders.ACCEPT, v);
332 * request.headers.add(HttpHeaders.ACCEPT, "text/html");
333 *
334 * To parse the header values use the [:fromString:] constructor.
335 *
336 * HttpRequest request = ...;
337 * List<String> values = request.headers[HttpHeaders.ACCEPT];
338 * values.forEach((value) {
339 * HeaderValue v = new HeaderValue.fromString(value);
340 * // Use v.value and v.parameters
341 * });
342 */
343 interface HeaderValue default _HeaderValue {
344 /**
345 * Creates a new header value object setting the value part.
346 */
347 HeaderValue([String value]);
348
349 /**
350 * Creates a new header value object from parsing a header value
351 * string with both value and optional parameters.
352 */
353 HeaderValue.fromString(String value);
354
355 /**
356 * Gets and sets the header value.
357 */
358 String value;
359
360 /**
361 * Gets the map of parameters.
362 */
363 Map<String, String> get parameters();
364
365 /**
366 * Returns the formatted string representation in the form:
367 *
368 * value; parameter1=value1; parameter2=value2
369 */
370 String toString();
371
372 }
373
374
375 /**
376 * Representation of a content type.
377 */
378 interface ContentType extends HeaderValue default _ContentType {
379 /**
380 * Creates a new content type object setting the primary type and
381 * sub type. If either is not passed their values will be the empty
382 * string.
383 */
384 ContentType([String primaryType, String subType]);
385
386 /**
387 * Creates a new content type object from parsing a Content-Type
388 * header value. As primary type, sub type and parameter names and
389 * values are not case sensitive all these values will be converted
390 * to lower case. Parsing this string
391 *
392 * text/html; charset=utf-8
393 *
394 * will create a content type object with primary type [:text:], sub
395 * type [:html:] and parameter [:charset:] with value [:utf-8:].
396 */
397 ContentType.fromString(String value);
398
399 /**
400 * Gets and sets the content type in the form "primaryType/subType".
401 */
402 String value;
403
404 /**
405 * Gets and sets the primary type.
406 */
407 String primaryType;
408
409 /**
410 * Gets and sets the sub type.
411 */
412 String subType;
413
414 /**
415 * Gets and sets the character set.
416 */
417 String charset;
418 }
419
420
305 /** 421 /**
306 * Http request delivered to the HTTP server callback. 422 * Http request delivered to the HTTP server callback.
307 */ 423 */
308 interface HttpRequest default _HttpRequest { 424 interface HttpRequest default _HttpRequest {
309 /** 425 /**
310 * Returns the content length of the request body. If the size of 426 * Returns the content length of the request body. If the size of
311 * the request body is not known in advance this -1. 427 * the request body is not known in advance this -1.
312 */ 428 */
313 int get contentLength(); 429 int get contentLength();
314 430
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 class RedirectLimitExceededException extends RedirectException { 788 class RedirectLimitExceededException extends RedirectException {
673 const RedirectLimitExceededException(List<RedirectInfo> redirects) 789 const RedirectLimitExceededException(List<RedirectInfo> redirects)
674 : super("Redirect limit exceeded", redirects); 790 : super("Redirect limit exceeded", redirects);
675 } 791 }
676 792
677 793
678 class RedirectLoopException extends RedirectException { 794 class RedirectLoopException extends RedirectException {
679 const RedirectLoopException(List<RedirectInfo> redirects) 795 const RedirectLoopException(List<RedirectInfo> redirects)
680 : super("Redirect loop detected", redirects); 796 : super("Redirect loop detected", redirects);
681 } 797 }
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/http_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698