MCPcopy Index your code
hub / github.com/ccxt/ccxt / processResponse

Method processResponse

java/lib/src/main/java/io/github/ccxt/Exchange.java:2146–2216  ·  view source on GitHub ↗
(HttpResponse<byte[]> response, String url, String method, Map<String, Object> requestHeaders, String body)

Source from the content-addressed store, hash-verified

2144 }
2145
2146 private Object processResponse(HttpResponse<byte[]> response, String url, String method, Map<String, Object> requestHeaders, String body) {
2147 String result;
2148 byte[] bodyBytes = response.body();
2149 List<String> encHeader = response.headers().allValues("Content-Encoding");
2150 boolean gzip = false;
2151 for (String encVal : encHeader) {
2152 if (encVal.toLowerCase().contains("gzip")) {
2153 gzip = true;
2154 break;
2155 }
2156 }
2157
2158 if (gzip) {
2159 try (java.io.ByteArrayInputStream bais = new java.io.ByteArrayInputStream(bodyBytes);
2160 java.util.zip.GZIPInputStream gis = new java.util.zip.GZIPInputStream(bais)) {
2161 result = new String(gis.readAllBytes(), java.nio.charset.StandardCharsets.UTF_8);
2162 } catch (Exception inner) {
2163 throw new RuntimeException(inner);
2164 }
2165 } else {
2166 result = new String(bodyBytes, java.nio.charset.StandardCharsets.UTF_8);
2167 }
2168
2169 Map<String, String> responseHeaders = null;
2170 int httpStatusCode = -1;
2171 String httpStatusText = null;
2172
2173 try {
2174 Map<String, List<String>> map = response.headers().map();
2175 responseHeaders = new java.util.HashMap<>();
2176 for (Map.Entry<String, List<String>> entry : map.entrySet()) {
2177 if (entry.getValue() != null && !entry.getValue().isEmpty()) {
2178 responseHeaders.put(entry.getKey(), entry.getValue().get(0));
2179 }
2180 }
2181 this.last_response_headers = responseHeaders;
2182 this.last_request_headers = requestHeaders;
2183 httpStatusCode = response.statusCode();
2184 httpStatusText = null;
2185 } catch (Exception ignored) {
2186 }
2187
2188 if (this.verbose) {
2189 this.log(
2190 "handleRestResponse:\n"
2191 + this.id + " " + method + " " + url + " " + httpStatusCode + " " + httpStatusText
2192 + "\nResponseHeaders:\n" + this.json(responseHeaders)
2193 + "\nResponseBody:\n" + result + "\n"
2194 );
2195 }
2196
2197 Object responseBody;
2198 try {
2199 responseBody = JsonHelper.deserialize(result);
2200 if (this.returnResponseHeaders && responseBody instanceof Map) {
2201 @SuppressWarnings("unchecked")
2202 Map<String, Object> dict = (Map<String, Object>) responseBody;
2203 dict.put("headers", responseHeaders);

Callers 1

fetchMethod · 0.95

Calls 11

logMethod · 0.95
jsonMethod · 0.95
deserializeMethod · 0.95
handleErrorsMethod · 0.95
handleHttpStatusCodeMethod · 0.95
isEmptyMethod · 0.80
bodyMethod · 0.45
headersMethod · 0.45
mapMethod · 0.45
getValueMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected