Skip to content

Commit

Permalink
fix(Form): set default contentType to application/json
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Feb 19, 2022
1 parent af36b2e commit 8920ac3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
8 changes: 2 additions & 6 deletions lib/src/binding_coap/coap_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,8 @@ class _CoapRequest {
}

void _applyFormInformation() {
if (_form.contentType != null) {
_coapRequest.accept = coap.CoapMediaType.parse(_form.contentType);
} else {
// TODO(JKRhb): Should a default accept option be set?
_coapRequest.accept = coap.CoapMediaType.applicationJson;
}
// TODO(JKRhb): Should the accept option be the form's contentType?
_coapRequest.accept = coap.CoapMediaType.parse(_form.contentType);
}
}

Expand Down
4 changes: 1 addition & 3 deletions lib/src/binding_http/http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ class HttpClient extends ProtocolClient {
}

static Content _contentFromResponse(Form form, http.Response response) {
final type = response.headers["Content-Type"] ??
form.contentType ??
"application/octet-stream";
final type = response.headers["Content-Type"] ?? form.contentType;
final body = Stream.value(response.bodyBytes);
return Content(type, body);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/definitions/form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Form {
List<String>? op;

/// The [contentType] supported by this [Form].
String? contentType;
String contentType = "application/json";

/// The list of [security] definitions applied to this [Form].
List<String>? security;
Expand All @@ -47,7 +47,7 @@ class Form {
///
/// An [href] has to be provided. A [contentType] is optional.
Form(this.href,
{this.contentType,
{this.contentType = "application/json",
this.subprotocol,
this.security,
this.scopes,
Expand Down

0 comments on commit 8920ac3

Please sign in to comment.