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

Invalid argument(s), when response without the header: "content-type" #480

Closed
1 task
laxian opened this issue Sep 24, 2019 · 1 comment
Closed
1 task

Comments

@laxian
Copy link

laxian commented Sep 24, 2019

New Issue Checklist

  • I have searched for a similar issue in the project and found none

Issue Info

Info Value
Platform Name ios / android
Platform Version 3.0.1
Dio Version 2.5.0 "macos_x64"
Android Studio / Xcode Version
Repro rate 100%

Issue Description and Steps

In my case, I tried to request a url with header "content-type: application/json",
I got response with code:401, while response headers do not contain "content-type",
then I got an exception


Exception has occurred.
DioError (DioError [DioErrorType.DEFAULT]: Invalid argument(s)
#0 _RegExp.matchAsPrefix (dart:core-patch/regexp_patch.dart:238:28)
#1 StringScanner.matches (package:string_scanner/src/string_scanner.dart:169:26)
#2 StringScanner.scan (package:string_scanner/src/string_scanner.dart:126:19)
#3 new MediaType.parse. (package:http_parser/src/media_type.dart:48:15)
#4 wrapFormatException (package:http_parser/src/utils.dart:13:16)
#5 new MediaType.parse (package:http_parser/src/media_type.dart:46:12)
#6 DefaultTransformer._isJsonMime (package:dio/src/transformer.dart:140:22)
#7 DefaultTransformer.transformResponse (package:dio/src/transformer.dart:129:9)

#8 DioMixin._dispatchRequest (package:dio/src/dio.dart:924:38)

#9 DioMixin._request._interceptorWrapper... (package:dio/src/dio.dart:828:37)
#10 DioMixin.checkIfNeedEnqueue (package:dio/src/dio.dart:1100:22)
#11 DioMixin._request._interceptorWrapper.. (package:dio/src/dio.dart:825:22)
#12 new Future. (dart:async/future.dart:176:37)
#13 _rootRun (dart:async/zone.dart:1120:38)
#14 _CustomZone.run (dart:async/zone.dart:1021:19)
#15 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
#16 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:963:23)
#17 _rootRun (dart:async/zone.dart:1124:13)
#18 _CustomZone.run (dart:async/zone.dart:1021:19)
#19 _CustomZone.bindCallback. (dart:async/zone.dart:947:23)
#20 Timer._createTimer. (dart:async-patch/timer_patch.dart:21:15)
#21 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:382:19)
#22 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:416:5)
#23 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
)


response headers:
HTTP/1.1 401
X-Application-Context gateway-service:test:8089
X-Foo 08011803-62de-4917-812c-1ebb2595faac
Transfer-Encoding chunked
Date Tue, 24 Sep 2019 06:57:25 GMT
Connection keep-alive


I found that exception here:

if (responseBody != null &&
        responseBody.isNotEmpty &&
        options.responseType == ResponseType.json &&
       
        //THIS LINE!!! the arg passed to _jsJsonMine is null
        _isJsonMime(response.headers[Headers.contentTypeHeader]?.first)) {
      if (jsonDecodeCallback != null) {
        return jsonDecodeCallback(responseBody);
      } else {
        return json.decode(responseBody);
      }
    }

I got exception because the RESPONSE HEADERS DO NOT CONTAIN "content-type".
Is it necessary?
Or it is a bug?

wendux added a commit that referenced this issue Sep 26, 2019
@stale
Copy link

stale bot commented Oct 25, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

@stale stale bot added the stale label Oct 25, 2019
@stale stale bot closed this as completed Nov 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant