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

Content-Type not set to application/json (does not work when using a dart client) #44

Closed
adamlofts opened this issue Sep 14, 2022 · 1 comment · Fixed by #45
Closed
Labels
bug Something isn't working

Comments

@adamlofts
Copy link

adamlofts commented Sep 14, 2022

When inserting data using the dart bigquery API the client crashes.

Unhandled exception:
ApiRequestError(message: Unable to read response with content-type text/plain; charset=utf-8.)
#0      ApiRequester.request (package:_discoveryapis_commons/src/clients.dart:86:9)
<asynchronous suspension>
#1      DatasetsResourceApi.insert (package:googleapis/bigquery/v2.dart:234:32)

The problem seems to be that although the response is JSON the Content-Type header is text/plain. You can see the dart code checking for this here:

Stream<String>? _decodeStreamAsText(http.StreamedResponse response) {
  // TODO: Correctly handle the response content-types, using correct
  // decoder.
  // Currently we assume that the api endpoint is responding with json
  // encoded in UTF8.
  if (isJson(response.headers['content-type'])) {
    return response.stream.transform(const Utf8Decoder(allowMalformed: true));
  } else {
    return null;
  }
}

Would suggest fixing by setting Content-Type: application/json; charset=utf-8 on all JSON responses.

@goccy goccy added the bug Something isn't working label Sep 15, 2022
@goccy goccy closed this as completed in #45 Sep 15, 2022
@goccy
Copy link
Owner

goccy commented Sep 16, 2022

Thank you for reporting !
I fixed this problem with v0.1.12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants