public static HTTPResponse createResponse(final StatusLine line, final Headers responseHeaders, final Optional<InputStream> stream) { Optional<String> contentLengthHeader = responseHeaders.getFirstHeaderValue(HeaderConstants.CONTENT_LENGTH); MIMEType type = responseHeaders.getContentType().orElse(MIMEType.APPLICATION_OCTET_STREAM); Optional<Long> length = responseHeaders.getContentLength(); Optional<Payload> payload = stream. filter(is -> line.getStatus().isBodyContentAllowed()). map(is -> new InputStreamPayload(is, type, length.orElse(-1L))); return new HTTPResponse(payload, line, responseHeaders); } }
public static Conditionals valueOf(Headers headers) { List<Tag> ifMatch = makeTags(headers.getFirstHeaderValue(HeaderConstants.IF_MATCH).orElse(null)); List<Tag> ifNoneMatch = makeTags(headers.getFirstHeaderValue(HeaderConstants.IF_NONE_MATCH).orElse(null)); Optional<LocalDateTime> modifiedSince = headers.getFirstHeader(HeaderConstants.IF_MODIFIED_SINCE).flatMap(HeaderUtils::fromHttpDate); Optional<LocalDateTime> unModifiedSince = headers.getFirstHeader(HeaderConstants.IF_UNMODIFIED_SINCE).flatMap(HeaderUtils::fromHttpDate); return new Conditionals(ifMatch, ifNoneMatch, modifiedSince, unModifiedSince); }
public HTTPRequest addIfNoneMatch(Tag tag) { return headers(headers.withConditionals(headers.getConditionals().addIfNoneMatch(tag))); }
public HTTPRequest addIfMatch(Tag tag) { return headers(headers.withConditionals(headers.getConditionals().addIfMatch(tag))); }
public HTTPRequest withIfUnModifiedSince(LocalDateTime dt) { return headers(headers.withConditionals(headers.getConditionals().ifUnModifiedSince(dt))); }
public HTTPRequest withIfModifiedSince(LocalDateTime dt) { return headers(headers.withConditionals(headers.getConditionals().ifModifiedSince(dt))); }
public Headers withExpires(LocalDateTime expires) { return set(HeaderUtils.toHttpDate(HeaderConstants.EXPIRES, expires)); }
public HTTPRequest addHeader(Header header) { Headers headers = this.headers.add(header); return new HTTPRequest(requestURI, method, headers, challenge, payload); }
public String getParameterValue(String name) { Parameter param = getParameter(name); if (param != null) { return param.getValue(); } return null; }
@Override public String toString() { return getName() + "=" + getQuotedValue(); } }
private void addDirective(String name, String value, boolean quoted) { if (quoted) { directives.put(name, new QuotedDirective(name, value)); } else { directives.put(name, new Directive(name, value)); } } }
public Headers withLastModified(LocalDateTime lm) { return set(HeaderUtils.toHttpDate(HeaderConstants.LAST_MODIFIED, lm)); }