| 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 and the charset parameter. |
| 482 */ | 485 */ |
| 483 factory ContentType([String primaryType = "", String subType = ""]) { | 486 factory ContentType([String primaryType = "", |
| 484 return new _ContentType(primaryType, subType); | 487 String subType = "", |
| 488 String charset]) { |
| 489 return new _ContentType(primaryType, subType, charset); |
| 485 } | 490 } |
| 486 | 491 |
| 487 /** | 492 /** |
| 488 * Creates a new content type object from parsing a Content-Type | 493 * Creates a new content type object from parsing a Content-Type |
| 489 * header value. As primary type, sub type and parameter names and | 494 * header value. As primary type, sub type and parameter names and |
| 490 * values are not case sensitive all these values will be converted | 495 * values are not case sensitive all these values will be converted |
| 491 * to lower case. Parsing this string | 496 * to lower case. Parsing this string |
| 492 * | 497 * |
| 493 * text/html; charset=utf-8 | 498 * text/html; charset=utf-8 |
| 494 * | 499 * |
| 495 * will create a content type object with primary type [:text:], sub | 500 * will create a content type object with primary type [:text:], sub |
| 496 * type [:html:] and parameter [:charset:] with value [:utf-8:]. | 501 * type [:html:] and parameter [:charset:] with value [:utf-8:]. |
| 497 */ | 502 */ |
| 498 factory ContentType.fromString(String value) { | 503 factory ContentType.fromString(String value) { |
| 499 return new _ContentType.fromString(value); | 504 return new _ContentType.fromString(value); |
| 500 } | 505 } |
| 501 | 506 |
| 502 /** | 507 /** |
| 503 * Gets and sets the content type in the form "primaryType/subType". | 508 * Gets the primary type. |
| 504 */ | 509 */ |
| 505 String value; | 510 String get primaryType; |
| 506 | 511 |
| 507 /** | 512 /** |
| 508 * Gets and sets the primary type. | 513 * Gets the sub type. |
| 509 */ | 514 */ |
| 510 String primaryType; | 515 String get subType; |
| 511 | 516 |
| 512 /** | 517 /** |
| 513 * Gets and sets the sub type. | 518 * Gets the character set. |
| 514 */ | 519 */ |
| 515 String subType; | 520 String get charset; |
| 516 | |
| 517 /** | |
| 518 * Gets and sets the character set. | |
| 519 */ | |
| 520 String charset; | |
| 521 } | 521 } |
| 522 | 522 |
| 523 | 523 |
| 524 /** | 524 /** |
| 525 * Representation of a cookie. For cookies received by the server as | 525 * Representation of a cookie. For cookies received by the server as |
| 526 * Cookie header values only [:name:] and [:value:] fields will be | 526 * Cookie header values only [:name:] and [:value:] fields will be |
| 527 * set. When building a cookie for the 'set-cookie' header in the server | 527 * 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 | 528 * and when receiving cookies in the client as 'set-cookie' headers all |
| 529 * fields can be used. | 529 * fields can be used. |
| 530 */ | 530 */ |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 class RedirectLimitExceededException extends RedirectException { | 1117 class RedirectLimitExceededException extends RedirectException { |
| 1118 const RedirectLimitExceededException(List<RedirectInfo> redirects) | 1118 const RedirectLimitExceededException(List<RedirectInfo> redirects) |
| 1119 : super("Redirect limit exceeded", redirects); | 1119 : super("Redirect limit exceeded", redirects); |
| 1120 } | 1120 } |
| 1121 | 1121 |
| 1122 | 1122 |
| 1123 class RedirectLoopException extends RedirectException { | 1123 class RedirectLoopException extends RedirectException { |
| 1124 const RedirectLoopException(List<RedirectInfo> redirects) | 1124 const RedirectLoopException(List<RedirectInfo> redirects) |
| 1125 : super("Redirect loop detected", redirects); | 1125 : super("Redirect loop detected", redirects); |
| 1126 } | 1126 } |
| OLD | NEW |