Skip to content

Commit

Permalink
Merge pull request #35 from techery/fix-okclient-nocontent
Browse files Browse the repository at this point in the history
Fix parsing for contentType in OkClient when a response has no body.
  • Loading branch information
almozavr committed Mar 16, 2016
2 parents b8ba429 + f9f5023 commit 3540f84
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ public OkClient(com.squareup.okhttp.OkHttpClient okHttpClient) {
for (String headerName : okResponse.headers().names()) {
responseHeaders.add(new Header(headerName, okResponse.header(headerName)));
}
ActionBody responseBody = new BytesArrayBody(
okResponse.body().contentType().toString(), okResponse.body().bytes()
);
ActionBody responseBody = null;
if (okResponse.body() != null) {
String contentType = null;
MediaType mediaType = okResponse.body().contentType();
if (mediaType != null) {
contentType = mediaType.toString();
}
responseBody = new BytesArrayBody(contentType, okResponse.body().bytes());
}
return new Response(
okResponse.request().url().toString(),
okResponse.code(), okResponse.message(), responseHeaders, responseBody
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,15 @@ public OkClient(OkHttpClient okHttpClient) {
for (String headerName : okResponse.headers().names()) {
responseHeaders.add(new Header(headerName, okResponse.header(headerName)));
}
ActionBody responseBody = new BytesArrayBody(
okResponse.body().contentType().toString(), okResponse.body().bytes()
);
ActionBody responseBody = null;
if (okResponse.body() != null) {
String contentType = null;
MediaType mediaType = okResponse.body().contentType();
if (mediaType != null) {
contentType = mediaType.toString();
}
responseBody = new BytesArrayBody(contentType, okResponse.body().bytes());
}
return new Response(
okResponse.request().url().toString(),
okResponse.code(), okResponse.message(), responseHeaders, responseBody
Expand Down

0 comments on commit 3540f84

Please sign in to comment.