Skip to content

Commit a22386e

Browse files
brianquinlankevmoo
andauthored
Clarify the behavior of response headers. (#1853)
* Clarify the behavior of response headers. * Update pkgs/http/CHANGELOG.md Co-authored-by: Kevin Moore <[email protected]> --------- Co-authored-by: Kevin Moore <[email protected]>
1 parent 9f0e8d9 commit a22386e

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

pkgs/http/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.6.1-wip
2+
3+
* Clarified the behavior of response headers in API documentation comments.
4+
15
## 1.6.0
26

37
* **Breaking** Change the behavior of `Request.body` so that a charset

pkgs/http/lib/src/base_response.dart

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,38 @@ abstract class BaseResponse {
3232
/// The HTTP headers returned by the server.
3333
///
3434
/// The header names are converted to lowercase and stored with their
35-
/// associated header values.
35+
/// associated header values. Because header names are lower-cased, you should
36+
/// always use lowercase keys to access them (e.g.,
37+
/// `response.headers['content-type']`).
3638
///
3739
/// If the server returns multiple headers with the same name then the header
38-
/// values will be associated with a single key and seperated by commas and
40+
/// values will be associated with a single key and separated by commas and
3941
/// possibly whitespace. For example:
4042
/// ```dart
4143
/// // HTTP/1.1 200 OK
4244
/// // Fruit: Apple
4345
/// // Fruit: Banana
4446
/// // Fruit: Grape
45-
/// final values = response.headers['fruit']!.split(RegExp(r'\s*,\s*'));
46-
/// // values = ['Apple', 'Banana', 'Grape']
47+
/// final values = response.headers['fruit']!;
48+
/// // values = 'Apple, Banana, Grape'
4749
/// ```
4850
///
4951
/// To retrieve the header values as a `List<String>`, use
50-
/// [HeadersWithSplitValues.headersSplitValues].
52+
/// [HeadersWithSplitValues.headersSplitValues]. This is particularly
53+
/// important for the `Set-Cookie` header, as the values may contain commas
54+
/// that make manual splitting difficult.
5155
///
5256
/// If a header value contains whitespace then that whitespace may be replaced
5357
/// by a single space. Leading and trailing whitespace in header values are
5458
/// always removed.
5559
///
5660
/// Some headers may be excluded by the [Client] for security or privacy
5761
/// reasons. For example, browser-based clients can only return headers in the
58-
/// CORS safelist or specifically allowed by the server.
62+
/// CORS safelist or specifically allowed by the server. The server can
63+
/// control which headers are exposed to clients running in the browser by
64+
/// setting the
65+
/// [`Access-Control-Expose-Headers`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers)
66+
/// header.
5967
final Map<String, String> headers;
6068

6169
final bool isRedirect;

pkgs/http/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: http
2-
version: 1.6.0
2+
version: 1.6.1-wip
33
description: A composable, multi-platform, Future-based API for HTTP requests.
44
repository: https://github.com/dart-lang/http/tree/master/pkgs/http
55

0 commit comments

Comments
 (0)