public MutableHeaders() { this(new Headers()); }
public HTTPRequest(URI requestURI, HTTPMethod method) { this(requestURI, method, new Headers(), Optional.<Challenge>empty(), Optional.<Payload>empty()); }
private Headers getResponseHeaders(HttpURLConnection connection) { Headers headers = new Headers(); Map<String, List<String>> headerFields = connection.getHeaderFields(); for (Map.Entry<String, List<String>> entry : headerFields.entrySet()) { for (String headerValue : entry.getValue()) { if (entry.getKey() != null) { headers = headers.add(entry.getKey(), headerValue); } } } return headers; }
public HTTPRequest(URI requestURI, HTTPMethod method, Headers headers, Optional<Challenge> challenge, Optional<Payload> payload) { this.requestURI = Objects.requireNonNull(requestURI, "You MUST have a URI"); this.normalizedURI = URIBuilder.fromURI(requestURI).toNormalizedURI(); this.method = method == null ? HTTPMethod.GET : method; this.headers = headers == null ? new Headers() : headers; this.challenge = Objects.requireNonNull(challenge, "Challenge may not be null"); this.payload = Objects.requireNonNull(payload, "Payload may not be null"); }
public static Headers parse(String input) { if (input == null || input.trim().isEmpty()) { return new Headers(); } MutableHeaders headers = new MutableHeaders(); String[] fields = input.split("\r\n"); for (String field : fields) { headers.add(Header.valueOf(field.trim())); } return headers.toHeaders(); }
public Headers remove(String name) { HeaderHashMap heads = copyMap(); heads.remove(name); return new Headers(heads); }
public Headers add(Iterable<Header> headers) { HeaderHashMap map = copyMap(); for (Header header : headers) { List<String> list = new ArrayList<>(map.get(header.getName())); String value = normalizeValue(header.getName(), header.getValue()); if (!list.contains(value)) { list.add(value); } map.put(header.getName(), list); } return new Headers(map); }
public Headers set(Header header) { HeaderHashMap headers = copyMap(); String normalized = normalizeValue(header.getName(), header.getValue()); headers.put(header.getName(), new ArrayList<>(Arrays.asList(normalized))); return new Headers(headers); }
/** * Converts the Conditionals into real headers. * @return real headers. */ public Headers toHeaders() { Headers headers = new Headers(); if (!getMatch().isEmpty()) { headers = headers.add(new Header(HeaderConstants.IF_MATCH, buildTagHeaderValue(getMatch()))); } if (!getNoneMatch().isEmpty()) { headers = headers.add(new Header(HeaderConstants.IF_NONE_MATCH, buildTagHeaderValue(getNoneMatch()))); } if (modifiedSince.isPresent()) { headers = headers.set(HeaderUtils.toHttpDate(HeaderConstants.IF_MODIFIED_SINCE, modifiedSince.get())); } if (unModifiedSince.isPresent()) { headers = headers.set(HeaderUtils.toHttpDate(HeaderConstants.IF_UNMODIFIED_SINCE, unModifiedSince.get())); } return headers; }