Skip to content

Commit 7fb6fd6

Browse files
authored
Clarify how to set the body without a content type header (#1014)
1 parent cad7d60 commit 7fb6fd6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pkgs/http/lib/src/request.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,16 @@ class Request extends BaseRequest {
6969
///
7070
/// This is converted to and from [body] using [encoding].
7171
///
72-
/// This list should only be set, not be modified in place.
72+
/// This list should only be set, not modified in place.
73+
///
74+
/// Unlike [body], setting [bodyBytes] does not implicitly set a
75+
/// `Content-Type` header.
76+
///
77+
/// ```dart
78+
/// final request = Request('GET', Uri.https('example.com', 'whatsit/create'))
79+
/// ..bodyBytes = utf8.encode(jsonEncode({}))
80+
/// ..headers['content-type'] = 'application/json';
81+
/// ```
7382
Uint8List get bodyBytes => _bodyBytes;
7483
Uint8List _bodyBytes;
7584

@@ -86,6 +95,9 @@ class Request extends BaseRequest {
8695
/// header, one will be added with the type `text/plain`. Then the `charset`
8796
/// parameter of the `Content-Type` header (whether new or pre-existing) will
8897
/// be set to [encoding] if it wasn't already set.
98+
///
99+
/// To set the body of the request, without setting the `Content-Type` header,
100+
/// use [bodyBytes].
89101
String get body => encoding.decode(bodyBytes);
90102

91103
set body(String value) {

0 commit comments

Comments
 (0)