Skip to content

Commit

Permalink
Clarify how to set the body without a content type header (#1014)
Browse files Browse the repository at this point in the history
  • Loading branch information
brianquinlan authored Aug 31, 2023
1 parent cad7d60 commit 7fb6fd6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkgs/http/lib/src/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,16 @@ class Request extends BaseRequest {
///
/// This is converted to and from [body] using [encoding].
///
/// This list should only be set, not be modified in place.
/// This list should only be set, not modified in place.
///
/// Unlike [body], setting [bodyBytes] does not implicitly set a
/// `Content-Type` header.
///
/// ```dart
/// final request = Request('GET', Uri.https('example.com', 'whatsit/create'))
/// ..bodyBytes = utf8.encode(jsonEncode({}))
/// ..headers['content-type'] = 'application/json';
/// ```
Uint8List get bodyBytes => _bodyBytes;
Uint8List _bodyBytes;

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

set body(String value) {
Expand Down

0 comments on commit 7fb6fd6

Please sign in to comment.