// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. package com.microsoft.aad.msal4j; import com.azure.json.JsonProviders; import com.azure.json.JsonReader; import java.io.IOException; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; /** * HTTP response */ public class HttpResponse implements IHttpResponse { /** * HTTP response status code */ private int statusCode; /** * HTTP response headers */ private Map> headers = new HashMap<>(); /** * HTTP response body */ private String body; /** * @param responseHeaders Map of HTTP headers returned from HTTP client */ public void addHeaders(Map> responseHeaders) { for (Map.Entry> entry : responseHeaders.entrySet()) { if (entry.getKey() == null) { continue; } List values = entry.getValue(); if (values == null || values.isEmpty() || values.get(0) == null) { continue; } addHeader(entry.getKey(), values.toArray(new String[]{})); } } void addHeader(final String name, final String... values) { if (values != null && values.length > 0) { headers.put(name, Arrays.asList(values)); } else { headers.remove(name); } } List getHeader(String key) { return headers.get(key); } Map getBodyAsMap() { return JsonHelper.convertJsonToMap(this.body); } public int statusCode() { return this.statusCode; } public Map> headers() { return this.headers; } public String body() { return this.body; } public HttpResponse statusCode(int statusCode) { this.statusCode = statusCode; return this; } public HttpResponse body(String body) { this.body = body; return this; } }