Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 50e2f302 authored by desperateCoder's avatar desperateCoder
Browse files

add Response-Headers to response for Call<T>

parent a3348874
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -137,7 +137,7 @@ public class NextcloudAPI {
        return convertStreamToTargetEntity(response.getBody(), type);
    }

    private <T> T convertStreamToTargetEntity(InputStream inputStream, Type targetEntity) throws IOException {
    public <T> T convertStreamToTargetEntity(InputStream inputStream, Type targetEntity) throws IOException {
        final T result;
        try (InputStream os = inputStream;
             Reader targetReader = new InputStreamReader(os)) {
+8 −2
Original line number Diff line number Diff line
@@ -7,7 +7,9 @@ import com.nextcloud.android.sso.api.NextcloudAPI;
import com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException;

import java.lang.reflect.Type;
import java.util.List;

import okhttp3.Headers;
import okhttp3.MediaType;
import okhttp3.Protocol;
import okhttp3.Request;
@@ -53,8 +55,12 @@ public final class Retrofit2Helper {
            @Override
            public Response<T> execute() {
                try {
                    T body = nextcloudAPI.performRequestV2(resType, nextcloudRequest);
                    return Response.success(body);
                    com.nextcloud.android.sso.api.Response response = nextcloudAPI.performNetworkRequestV2(nextcloudRequest);

                    T body = nextcloudAPI.convertStreamToTargetEntity(response.getBody(), resType);
                    return Response.success(body,
                        Headers.of((String[]) response.getPlainHeaders().stream().map(h -> List.of(h.getName(), h.getValue())).toArray())
                    );
                } catch (NextcloudHttpRequestFailedException e) {
                    final Throwable cause = e.getCause();
                    return convertExceptionToResponse(e.getStatusCode(), cause == null ? e.getMessage() : cause.getMessage());
+20 −10
Original line number Diff line number Diff line
@@ -113,7 +113,8 @@ public class TestRetrofitAPI {

        Type type = new TypeToken<List<String>>() {}.getType();
        try {
            verify(nextcloudApiMock).performRequestV2(eq(type), eq(request));
            verify(nextcloudApiMock).performNetworkRequestV2(eq(request));
            verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type));
        } catch (Exception e) {
            fail(e.getMessage());
        }
@@ -199,7 +200,8 @@ public class TestRetrofitAPI {

        Type type = new TypeToken<List<String>>() {}.getType();
        try {
            verify(nextcloudApiMock).performRequestV2(eq(type), eq(request));
            verify(nextcloudApiMock).performNetworkRequestV2(eq(request));
            verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type));
        } catch (Exception e) {
            fail(e.getMessage());
        }
@@ -260,7 +262,8 @@ public class TestRetrofitAPI {

        Type type = new TypeToken<Void>() {}.getType();
        try {
            verify(nextcloudApiMock).performRequestV2(eq(type), eq(request));
            verify(nextcloudApiMock).performNetworkRequestV2(eq(request));
            verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type));
        } catch (Exception e) {
            fail(e.getMessage());
        }
@@ -319,7 +322,8 @@ public class TestRetrofitAPI {

        Type type = new TypeToken<Void>() {}.getType();
        try {
            verify(nextcloudApiMock).performRequestV2(eq(type), eq(request));
            verify(nextcloudApiMock).performNetworkRequestV2(eq(request));
            verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type));
        } catch (Exception e) {
            fail(e.getMessage());
        }
@@ -350,7 +354,8 @@ public class TestRetrofitAPI {

        Type type = new TypeToken<Void>() {}.getType();
        try {
            verify(nextcloudApiMock).performRequestV2(eq(type), eq(request));
            verify(nextcloudApiMock).performNetworkRequestV2(eq(request));
            verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type));
        } catch (Exception e) {
            fail(e.getMessage());
        }
@@ -377,7 +382,8 @@ public class TestRetrofitAPI {

        Type type = new TypeToken<Void>() {}.getType();
        try {
            verify(nextcloudApiMock).performRequestV2(eq(type), eq(request));
            verify(nextcloudApiMock).performNetworkRequestV2(eq(request));
            verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type));
        } catch (Exception e) {
            fail(e.getMessage());
        }
@@ -401,7 +407,8 @@ public class TestRetrofitAPI {

        Type type = new TypeToken<ResponseBody>() {}.getType();
        try {
            verify(nextcloudApiMock).performRequestV2(eq(type), eq(request));
            verify(nextcloudApiMock).performNetworkRequestV2(eq(request));
            verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type));
        } catch (Exception e) {
            fail(e.getMessage());
        }
@@ -426,7 +433,8 @@ public class TestRetrofitAPI {

        Type type = new TypeToken<ResponseBody>() {}.getType();
        try {
            verify(nextcloudApiMock).performRequestV2(eq(type), eq(request));
            verify(nextcloudApiMock).performNetworkRequestV2(eq(request));
            verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type));
        } catch (Exception e) {
            fail(e.getMessage());
        }
@@ -454,7 +462,8 @@ public class TestRetrofitAPI {
        Type type = new TypeToken<ResponseBody>() {
        }.getType();
        try {
            verify(nextcloudApiMock).performRequestV2(eq(type), eq(request));
            verify(nextcloudApiMock).performNetworkRequestV2(eq(request));
            verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type));
        } catch (Exception e) {
            fail(e.getMessage());
        }
@@ -482,7 +491,8 @@ public class TestRetrofitAPI {
        Type type = new TypeToken<ResponseBody>() {
        }.getType();
        try {
            verify(nextcloudApiMock).performRequestV2(eq(type), eq(request));
            verify(nextcloudApiMock).performNetworkRequestV2(eq(request));
            verify(nextcloudApiMock).convertStreamToTargetEntity(any(), eq(type));
        } catch (Exception e) {
            fail(e.getMessage());
        }