OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 /** | 7 /** |
8 * HTTP status codes. | 8 * HTTP status codes. |
9 */ | 9 */ |
10 abstract class HttpStatus { | 10 abstract class HttpStatus { |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 * [HeaderValue] can be used to conveniently build and parse header | 392 * [HeaderValue] can be used to conveniently build and parse header |
393 * values on this form. | 393 * values on this form. |
394 * | 394 * |
395 * To build an [:accepts:] header with the value | 395 * To build an [:accepts:] header with the value |
396 * | 396 * |
397 * text/plain; q=0.3, text/html | 397 * text/plain; q=0.3, text/html |
398 * | 398 * |
399 * use code like this: | 399 * use code like this: |
400 * | 400 * |
401 * HttpClientRequest request = ...; | 401 * HttpClientRequest request = ...; |
402 * var v = new HeaderValue(); | 402 * var v = new HeaderValue("text/plain", {"q": "0.3"}); |
403 * v.value = "text/plain"; | |
404 * v.parameters["q"] = "0.3" | |
405 * request.headers.add(HttpHeaders.ACCEPT, v); | 403 * request.headers.add(HttpHeaders.ACCEPT, v); |
406 * request.headers.add(HttpHeaders.ACCEPT, "text/html"); | 404 * request.headers.add(HttpHeaders.ACCEPT, "text/html"); |
407 * | 405 * |
408 * To parse the header values use the [:fromString:] constructor. | 406 * To parse the header values use the [:fromString:] constructor. |
409 * | 407 * |
410 * HttpRequest request = ...; | 408 * HttpRequest request = ...; |
411 * List<String> values = request.headers[HttpHeaders.ACCEPT]; | 409 * List<String> values = request.headers[HttpHeaders.ACCEPT]; |
412 * values.forEach((value) { | 410 * values.forEach((value) { |
413 * HeaderValue v = new HeaderValue.fromString(value); | 411 * HeaderValue v = new HeaderValue.fromString(value); |
414 * // Use v.value and v.parameters | 412 * // Use v.value and v.parameters |
415 * }); | 413 * }); |
| 414 * |
| 415 * An instance of [HeaderValue] is immutable. |
416 */ | 416 */ |
417 abstract class HeaderValue { | 417 abstract class HeaderValue { |
418 /** | 418 /** |
419 * Creates a new header value object setting the value part. | 419 * Creates a new header value object setting the value part. |
420 */ | 420 */ |
421 factory HeaderValue([String value = ""]) => new _HeaderValue(value); | 421 factory HeaderValue([String value = "", Map<String, String> parameters]) { |
| 422 return new _HeaderValue(value, parameters); |
| 423 } |
422 | 424 |
423 /** | 425 /** |
424 * Creates a new header value object from parsing a header value | 426 * Creates a new header value object from parsing a header value |
425 * string with both value and optional parameters. | 427 * string with both value and optional parameters. |
426 */ | 428 */ |
427 factory HeaderValue.fromString(String value, | 429 factory HeaderValue.fromString(String value, |
428 {String parameterSeparator: ";"}) { | 430 {String parameterSeparator: ";"}) { |
429 return new _HeaderValue.fromString( | 431 return new _HeaderValue.fromString( |
430 value, parameterSeparator: parameterSeparator); | 432 value, parameterSeparator: parameterSeparator); |
431 } | 433 } |
432 | 434 |
433 /** | 435 /** |
434 * Gets and sets the header value. | 436 * Gets the header value. |
435 */ | 437 */ |
436 String value; | 438 String get value; |
437 | 439 |
438 /** | 440 /** |
439 * Gets the map of parameters. | 441 * Gets the map of parameters. |
440 */ | 442 */ |
441 Map<String, String> get parameters; | 443 Map<String, String> get parameters; |
442 | 444 |
443 /** | 445 /** |
444 * Returns the formatted string representation in the form: | 446 * Returns the formatted string representation in the form: |
445 * | 447 * |
446 * value; parameter1=value1; parameter2=value2 | 448 * value; parameter1=value1; parameter2=value2 |
(...skipping 19 matching lines...) Expand all Loading... |
466 void set onTimeout(void callback()); | 468 void set onTimeout(void callback()); |
467 | 469 |
468 /** | 470 /** |
469 * Is true if the session has not been sent to the client yet. | 471 * Is true if the session has not been sent to the client yet. |
470 */ | 472 */ |
471 bool get isNew; | 473 bool get isNew; |
472 } | 474 } |
473 | 475 |
474 | 476 |
475 /** | 477 /** |
476 * Representation of a content type. | 478 * Representation of a content type. An instance of [ContentType] is |
| 479 * immutable. |
477 */ | 480 */ |
478 abstract class ContentType implements HeaderValue { | 481 abstract class ContentType implements HeaderValue { |
479 /** | 482 /** |
480 * Creates a new content type object setting the primary type and | 483 * Creates a new content type object setting the primary type and |
481 * sub type. | 484 * sub type. The charset and additional parameters can also be set |
| 485 * using [charset] and [parameters]. If charset is passed and |
| 486 * [parameters] contains charset as well the passed [charset] will |
| 487 * override the value in parameters. Keys and values passed in |
| 488 * parameters will be converted to lower case. |
482 */ | 489 */ |
483 factory ContentType([String primaryType = "", String subType = ""]) { | 490 factory ContentType(String primaryType, |
484 return new _ContentType(primaryType, subType); | 491 String subType, |
| 492 {String charset, Map<String, String> parameters}) { |
| 493 return new _ContentType(primaryType, subType, charset, parameters); |
485 } | 494 } |
486 | 495 |
487 /** | 496 /** |
488 * Creates a new content type object from parsing a Content-Type | 497 * Creates a new content type object from parsing a Content-Type |
489 * header value. As primary type, sub type and parameter names and | 498 * header value. As primary type, sub type and parameter names and |
490 * values are not case sensitive all these values will be converted | 499 * values are not case sensitive all these values will be converted |
491 * to lower case. Parsing this string | 500 * to lower case. Parsing this string |
492 * | 501 * |
493 * text/html; charset=utf-8 | 502 * text/html; charset=utf-8 |
494 * | 503 * |
495 * will create a content type object with primary type [:text:], sub | 504 * will create a content type object with primary type [:text:], sub |
496 * type [:html:] and parameter [:charset:] with value [:utf-8:]. | 505 * type [:html:] and parameter [:charset:] with value [:utf-8:]. |
497 */ | 506 */ |
498 factory ContentType.fromString(String value) { | 507 factory ContentType.fromString(String value) { |
499 return new _ContentType.fromString(value); | 508 return new _ContentType.fromString(value); |
500 } | 509 } |
501 | 510 |
502 /** | 511 /** |
503 * Gets and sets the content type in the form "primaryType/subType". | 512 * Gets the primary type. |
504 */ | 513 */ |
505 String value; | 514 String get primaryType; |
506 | 515 |
507 /** | 516 /** |
508 * Gets and sets the primary type. | 517 * Gets the sub type. |
509 */ | 518 */ |
510 String primaryType; | 519 String get subType; |
511 | 520 |
512 /** | 521 /** |
513 * Gets and sets the sub type. | 522 * Gets the character set. |
514 */ | 523 */ |
515 String subType; | 524 String get charset; |
516 | |
517 /** | |
518 * Gets and sets the character set. | |
519 */ | |
520 String charset; | |
521 } | 525 } |
522 | 526 |
523 | 527 |
524 /** | 528 /** |
525 * Representation of a cookie. For cookies received by the server as | 529 * Representation of a cookie. For cookies received by the server as |
526 * Cookie header values only [:name:] and [:value:] fields will be | 530 * Cookie header values only [:name:] and [:value:] fields will be |
527 * set. When building a cookie for the 'set-cookie' header in the server | 531 * set. When building a cookie for the 'set-cookie' header in the server |
528 * and when receiving cookies in the client as 'set-cookie' headers all | 532 * and when receiving cookies in the client as 'set-cookie' headers all |
529 * fields can be used. | 533 * fields can be used. |
530 */ | 534 */ |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1117 class RedirectLimitExceededException extends RedirectException { | 1121 class RedirectLimitExceededException extends RedirectException { |
1118 const RedirectLimitExceededException(List<RedirectInfo> redirects) | 1122 const RedirectLimitExceededException(List<RedirectInfo> redirects) |
1119 : super("Redirect limit exceeded", redirects); | 1123 : super("Redirect limit exceeded", redirects); |
1120 } | 1124 } |
1121 | 1125 |
1122 | 1126 |
1123 class RedirectLoopException extends RedirectException { | 1127 class RedirectLoopException extends RedirectException { |
1124 const RedirectLoopException(List<RedirectInfo> redirects) | 1128 const RedirectLoopException(List<RedirectInfo> redirects) |
1125 : super("Redirect loop detected", redirects); | 1129 : super("Redirect loop detected", redirects); |
1126 } | 1130 } |
OLD | NEW |