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

com.qwazr.extractor.HttpHeadersImpl Maven / Gradle / Ivy

There is a newer version: 1.5.1
Show newest version
/*
 * Copyright 2015-2020 Emmanuel Keller
 * 

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.qwazr.extractor; import java.util.Date; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.function.Function; import javax.ws.rs.core.Cookie; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; /** * Partial immplementation for tests */ class HttpHeadersImpl implements HttpHeaders { private final MultivaluedHashMap headers; HttpHeadersImpl(final Map headers) { this.headers = new MultivaluedHashMap<>(); headers.forEach(this.headers::add); } @Override public List getRequestHeader(String name) { return headers.get(name); } @Override public String getHeaderString(String name) { return headers.getFirst(name); } @Override public MultivaluedMap getRequestHeaders() { return headers; } private T getFirst(String name, Function function, T defaultValue) { final String value = headers.getFirst(name); return value == null ? defaultValue : function.apply(value); } @Override public List getAcceptableMediaTypes() { return null; } @Override public List getAcceptableLanguages() { return null; } @Override public MediaType getMediaType() { return getFirst(HttpHeaders.CONTENT_TYPE, h -> MediaType.valueOf(h), null); } @Override public Locale getLanguage() { return null; } @Override public Map getCookies() { return null; } @Override public Date getDate() { return null; } @Override public int getLength() { return 0; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy