public Optional<CacheControl> getCacheControl() { return getFirstHeader(HeaderConstants.CACHE_CONTROL).map(CacheControl::new); }
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 Optional<String> getFirstHeaderValue(String headerKey) { Optional<Header> header = getFirstHeader(headerKey); return header.map(Header::getValue); }
public Optional<Directives> getFirstHeaderValueAsDirectives(String headerKey) { Optional<Header> header = getFirstHeader(headerKey); return header.map(Header::getDirectives); }
public Header getFirstHeader(String headerKey) { return headers.getFirstHeader(headerKey).orElse(null); }
public Optional<LocalDateTime> getDate() { return getFirstHeader(HeaderConstants.DATE).flatMap(HeaderUtils::fromHttpDate); }
public Optional<LocalDateTime> getExpires() { return getFirstHeader(HeaderConstants.EXPIRES).flatMap(HeaderUtils::fromHttpDate); }
public Optional<LocalDateTime> getLastModified() { return getFirstHeader(HeaderConstants.LAST_MODIFIED).flatMap(HeaderUtils::fromHttpDate); }
public List<Preference> getAccept() { return Preference.parse(getFirstHeader(HeaderConstants.ACCEPT)); }
public List<Preference> getAcceptCharset() { return Preference.parse(getFirstHeader(HeaderConstants.ACCEPT_CHARSET)); }
public List<Preference> getAcceptLanguage() { return Preference.parse(getFirstHeader(HeaderConstants.ACCEPT_LANGUAGE)); }
public Set<HTTPMethod> getAllow() { Optional<Header> header = getFirstHeader(HeaderConstants.ALLOW); if (header.isPresent()) { return header.get().getDirectives().stream().map(d -> HTTPMethod.valueOf(d.getName().toUpperCase(Locale.ENGLISH))).collect(Collectors.toSet()); } return Collections.emptySet(); }
public AuthScheme afterSuccessfulAuthentication(AuthScheme scheme, Headers headers, boolean proxy) { Optional<Header> header; if (proxy) { header = headers.getFirstHeader(HeaderConstants.PROXY_AUTHENTICATION_INFO); } else { header = headers.getFirstHeader(HeaderConstants.AUTHENTICATION_INFO); } if (header.isPresent()) { String nextNonce = header.get().getDirectives().get("nextnonce"); if (nextNonce != null) { List<Parameter> params = scheme.getDirective().getParameters().stream(). filter(p -> !"nonce".equals(p.getName())). collect(Collectors.toList()); params.add(new QuotedParameter("nonce", nextNonce)); return new AuthScheme(new AuthDirective("Digest", null, params)); } } return scheme; } }
/** * Analyses the headers in the given request to figure out if this {@link Vary variation} matches. * * @param request the request to analyse * @return {@code true} if the request matches the variance. {@code false} if not. */ //todo: cleanup this public boolean matches(final HTTPRequest request) { if (varyHeaders.containsKey("ALL")) return false; Headers headers = request.getAllHeaders(); for (Map.Entry<String, String> varyEntry : varyHeaders.entrySet()) { if (request.getChallenge().isPresent() && varyEntry.getKey().equals(HeaderConstants.AUTHORIZATION)) { if (!request.getChallenge().get().getIdentifier().equals(varyEntry.getValue())) { return false; } } else { List<Header> requestHeaderValue = headers.getHeaders(varyEntry.getKey()); boolean valid = requestHeaderValue.isEmpty() ? varyEntry.getValue() == null : headers.getFirstHeader(varyEntry.getKey()).get().getValue().equals(varyEntry.getValue()); if (!valid) { return false; } } } List<Preference> preferences = new ArrayList<>(); preferences.addAll(headers.getAccept()); preferences.addAll(headers.getAcceptCharset()); preferences.addAll(headers.getAcceptLanguage()); return !(varyHeaders.isEmpty() && !preferences.isEmpty()); }