package io.vertx.core.http.impl;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http2.Http2Headers;
import io.vertx.core.MultiMap;
import java.util.AbstractList;
import java.util.AbstractMap;
import java.util.AbstractSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
public class implements MultiMap {
static CharSequence (CharSequence s) {
StringBuilder buffer = null;
int len = s.length();
for (int index = 0; index < len; index++) {
char c = s.charAt(index);
if (c >= 'A' && c <= 'Z') {
if (buffer == null) {
buffer = new StringBuilder(s);
}
buffer.setCharAt(index, (char)(c + ('a' - 'A')));
}
}
if (buffer != null) {
return buffer.toString();
} else {
return s;
}
}
private final Http2Headers ;
private Set<String> ;
public Http2HeadersAdaptor(Http2Headers headers) {
List<CharSequence> cookies = headers.getAll(HttpHeaderNames.COOKIE);
if (cookies != null && cookies.size() > 1) {
String value = cookies.stream().collect(Collectors.joining("; "));
headers.set(HttpHeaderNames.COOKIE, value);
}
this.headers = headers;
}
@Override
public String (String name) {
CharSequence val = headers.get(toLowerCase(name));
return val != null ? val.toString() : null;
}
@Override
public List<String> (String name) {
List<CharSequence> all = headers.getAll(toLowerCase(name));
if (all != null) {
return new AbstractList<String>() {
@Override
public String (int index) {
return all.get(index).toString();
}
@Override
public int () {
return all.size();
}
};
}
return null;
}
@Override
public List<Map.Entry<String, String>> () {
return headers.names()
.stream()
.map(name -> new AbstractMap.SimpleEntry<>(name.toString(), headers.get(name).toString()))
.collect(Collectors.toList());
}
@Override
public boolean (String name) {
return headers.contains(toLowerCase(name));
}
@Override
public boolean (String name, String value, boolean caseInsensitive) {
return headers.contains(toLowerCase(name), value, caseInsensitive);
}
@Override
public boolean () {
return headers.isEmpty();
}
@Override
public Set<String> () {
if (names == null) {
names = new AbstractSet<String>() {
@Override
public Iterator<String> () {
Iterator<CharSequence> it = headers.names().iterator();
return new Iterator<String>() {
@Override
public boolean () {
return it.hasNext();
}
@Override
public String () {
return it.next().toString();
}
};
}
@Override
public int () {
return headers.size();
}
};
}
return names;
}
@Override
public MultiMap (String name, String value) {
if (!io.vertx.core.http.HttpHeaders.DISABLE_HTTP_HEADERS_VALIDATION) {
HttpUtils.validateHeader(name, value);
}
headers.add(toLowerCase(name), value);
return this;
}
@Override
public MultiMap (String name, Iterable<String> values) {
if (!io.vertx.core.http.HttpHeaders.DISABLE_HTTP_HEADERS_VALIDATION) {
HttpUtils.validateHeader(name, values);
}
headers.add(toLowerCase(name), values);
return this;
}
@Override
public MultiMap (MultiMap headers) {
for (Map.Entry<String, String> entry: headers.entries()) {
add(entry.getKey(), entry.getValue());
}
return this;
}
@Override
public MultiMap (Map<String, String> map) {
for (Map.Entry<String, String> entry: map.entrySet()) {
add(entry.getKey(), entry.getValue());
}
return this;
}
@Override
public MultiMap (String name, String value) {
if (!io.vertx.core.http.HttpHeaders.DISABLE_HTTP_HEADERS_VALIDATION) {
HttpUtils.validateHeader(name, value);
}
headers.set(toLowerCase(name), value);
return this;
}
@Override
public MultiMap (String name, Iterable<String> values) {
if (!io.vertx.core.http.HttpHeaders.DISABLE_HTTP_HEADERS_VALIDATION) {
HttpUtils.validateHeader(name, values);
}
headers.set(toLowerCase(name), values);
return this;
}
@Override
public MultiMap (MultiMap httpHeaders) {
clear();
for (Map.Entry<String, String> entry: httpHeaders) {
add(entry.getKey(), entry.getValue());
}
return this;
}
@Override
public MultiMap (String name) {
headers.remove(toLowerCase(name));
return this;
}
@Override
public MultiMap () {
headers.clear();
return this;
}
@Override
public Iterator<Map.Entry<String, String>> () {
return entries().iterator();
}
@Override
public int () {
return names().size();
}
@Override
public MultiMap (Map<String, String> headers) {
for (Map.Entry<String, String> entry: headers.entrySet()) {
add(entry.getKey(), entry.getValue());
}
return this;
}
@Override
public String (CharSequence name) {
CharSequence val = headers.get(toLowerCase(name));
return val != null ? val.toString() : null;
}
@Override
public List<String> (CharSequence name) {
List<CharSequence> all = headers.getAll(toLowerCase(name));
return all != null ? all.stream().map(CharSequence::toString).collect(Collectors.toList()) : null;
}
@Override
public boolean (CharSequence name) {
return headers.contains(toLowerCase(name));
}
@Override
public boolean (CharSequence name, CharSequence value, boolean caseInsensitive) {
return headers.contains(toLowerCase(name), value, caseInsensitive);
}
@Override
public MultiMap (CharSequence name, CharSequence value) {
if (!io.vertx.core.http.HttpHeaders.DISABLE_HTTP_HEADERS_VALIDATION) {
HttpUtils.validateHeader(name, value);
}
headers.add(toLowerCase(name), value);
return this;
}
@Override
public MultiMap (CharSequence name, Iterable<CharSequence> values) {
if (!io.vertx.core.http.HttpHeaders.DISABLE_HTTP_HEADERS_VALIDATION) {
HttpUtils.validateHeader(name, values);
}
headers.add(toLowerCase(name), values);
return this;
}
@Override
public MultiMap (CharSequence name, CharSequence value) {
if (!io.vertx.core.http.HttpHeaders.DISABLE_HTTP_HEADERS_VALIDATION) {
HttpUtils.validateHeader(name, value);
}
headers.set(toLowerCase(name), value);
return this;
}
@Override
public MultiMap (CharSequence name, Iterable<CharSequence> values) {
if (!io.vertx.core.http.HttpHeaders.DISABLE_HTTP_HEADERS_VALIDATION) {
HttpUtils.validateHeader(name, values);
}
headers.set(toLowerCase(name), values);
return this;
}
@Override
public MultiMap (CharSequence name) {
headers.remove(toLowerCase(name));
return this;
}
}