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

Unified Diff: sdk/lib/io/http.dart

Issue 12440002: Make instances of HeaderValue and ContentType immutable (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments from nweiz@ Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/http/test/request_test.dart ('k') | sdk/lib/io/http_headers.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/http.dart
diff --git a/sdk/lib/io/http.dart b/sdk/lib/io/http.dart
index feaeb0e4edbd1e7e9066dcc7f782e18df095cdb0..2eddf7ca202419f8c5f59e15e6832a2123389257 100644
--- a/sdk/lib/io/http.dart
+++ b/sdk/lib/io/http.dart
@@ -399,9 +399,7 @@ abstract class HttpHeaders {
* use code like this:
*
* HttpClientRequest request = ...;
- * var v = new HeaderValue();
- * v.value = "text/plain";
- * v.parameters["q"] = "0.3"
+ * var v = new HeaderValue("text/plain", {"q": "0.3"});
* request.headers.add(HttpHeaders.ACCEPT, v);
* request.headers.add(HttpHeaders.ACCEPT, "text/html");
*
@@ -413,12 +411,16 @@ abstract class HttpHeaders {
* HeaderValue v = new HeaderValue.fromString(value);
* // Use v.value and v.parameters
* });
+ *
+ * An instance of [HeaderValue] is immutable.
*/
abstract class HeaderValue {
/**
* Creates a new header value object setting the value part.
*/
- factory HeaderValue([String value = ""]) => new _HeaderValue(value);
+ factory HeaderValue([String value = "", Map<String, String> parameters]) {
+ return new _HeaderValue(value, parameters);
+ }
/**
* Creates a new header value object from parsing a header value
@@ -431,9 +433,9 @@ abstract class HeaderValue {
}
/**
- * Gets and sets the header value.
+ * Gets the header value.
*/
- String value;
+ String get value;
/**
* Gets the map of parameters.
@@ -473,15 +475,22 @@ abstract class HttpSession implements Map {
/**
- * Representation of a content type.
+ * Representation of a content type. An instance of [ContentType] is
+ * immutable.
*/
abstract class ContentType implements HeaderValue {
/**
* Creates a new content type object setting the primary type and
- * sub type.
- */
- factory ContentType([String primaryType = "", String subType = ""]) {
- return new _ContentType(primaryType, subType);
+ * sub type. The charset and additional parameters can also be set
+ * using [charset] and [parameters]. If charset is passed and
+ * [parameters] contains charset as well the passed [charset] will
+ * override the value in parameters. Keys and values passed in
+ * parameters will be converted to lower case.
+ */
+ factory ContentType(String primaryType,
+ String subType,
+ {String charset, Map<String, String> parameters}) {
+ return new _ContentType(primaryType, subType, charset, parameters);
}
/**
@@ -500,24 +509,19 @@ abstract class ContentType implements HeaderValue {
}
/**
- * Gets and sets the content type in the form "primaryType/subType".
- */
- String value;
-
- /**
- * Gets and sets the primary type.
+ * Gets the primary type.
*/
- String primaryType;
+ String get primaryType;
/**
- * Gets and sets the sub type.
+ * Gets the sub type.
*/
- String subType;
+ String get subType;
/**
- * Gets and sets the character set.
+ * Gets the character set.
*/
- String charset;
+ String get charset;
}
« no previous file with comments | « pkg/http/test/request_test.dart ('k') | sdk/lib/io/http_headers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698