Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify how to set the body without a content type header #1014

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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