All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.microsoft.graph.http.HttpResponseHeadersHelper Maven / Gradle / Ivy

There is a newer version: 6.16.0
Show newest version
package com.microsoft.graph.http;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import okhttp3.Headers;
import okhttp3.Response;

public class HttpResponseHeadersHelper {
    /**
	 * Gets the response headers from OkHttp Response
	 *
	 * @param response the OkHttp response
	 * @return           the set of headers names and value
	 */
	public Map getResponseHeadersAsMapStringString(final Response response) {
		final Map headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
		int index = 0;
		Headers responseHeaders = response.headers();
		while (index < responseHeaders.size()) {
			final String headerName = responseHeaders.name(index);
			final String headerValue = responseHeaders.value(index);
			if (headerName == null || headerValue == null) {
				break;
			}
			headers.put(headerName, headerValue);
			index++;
		}
		return headers;
    }
    
    /**
	 * Gets the response headers from OkHttp Response
	 *
	 * @param response the OkHttp response
	 * @return           the set of headers names and value
	 */
	public Map> getResponseHeadersAsMapOfStringList(Response response) {
		Map> headerFields = response.headers().toMultimap();
		// Add the response code
		List list = new ArrayList<>();
		list.add(String.format("%d", response.code()));
		headerFields.put("responseCode", list);
		return headerFields;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy