/** * Return the resource location as specified by the {@link #LOCATION} header. * @return location URI, if available */ default Optional<URI> getLocation() { return getHeaderValue(LOCATION).map(v -> URI.create(v)); }
/** * Get the first (most qualified) {@link Locale} using the {@link #ACCEPT_LANGUAGE} header, if present. * @return The first (most qualified) {@link Locale} using the {@link #ACCEPT_LANGUAGE} header, if available */ default Optional<Locale> getLocale() { final List<Locale> locales = getLocales(); return (!locales.isEmpty()) ? Optional.ofNullable(locales.get(0)) : Optional.empty(); }
/** * Get a HTTP header as a single string value. * @param name The header name (not null) * @return The HTTP header value. If the HTTP header is present more than once then the values are joined together * and separated by a ',' character. */ default Optional<String> getHeaderValue(String name) { ObjectUtils.argumentNotNull(name, "Header name must be not null"); return getHeader(name).filter(l -> l != null && !l.isEmpty()).map(l -> l.get(0)); }
/** * Return the length of the request body in bytes, as specified by the {@link #CONTENT_LENGTH} header. * @return Content length in bytes, if available */ default Optional<Long> getContentLength() { return getHeaderValue(CONTENT_LENGTH).map(v -> Long.parseLong(v)); }
/** * Return the authorization <em>bearer</em> token from the {@link #AUTHORIZATION} header, if present and of scheme * type {@link #SCHEME_BEARER}. * @return Authorization bearer token, if available */ default Optional<String> getAuthorizationBearer() { return getHeaderValue(AUTHORIZATION).map(v -> HttpUtils.extractAuthorizationBearer(v)); }
/** * Try to get a list of {@link Locale} using the {@link #ACCEPT_LANGUAGE} header, if present. If more than one * language is specified in the <code>Accept-Language</code> header, returned Locales will be ordered relying on * <i>quality</i> parameter, if specified. * @return List of Locale for the languages of the <code>Accept-Language</code> header, if any. If header is not * present, an empty list is returned. */ default List<Locale> getLocales() { return HttpUtils.getAcceptLanguageLocales(getHeaderValue(ACCEPT_LANGUAGE).orElse(null)); }
/** * Return the <em>basic</em> authorization credential values from the {@link #AUTHORIZATION} header, if present and * of scheme type {@link #SCHEME_BASIC}. * <p> * The authorization credentials are decoded from Base64 before returning them to caller. * </p> * @return Basic authorization credentials as an array which contains the <em>username</em> at index 0 and the * <em>password</em> at index 1, if available */ default Optional<String[]> getAuthorizationBasicCredentials() { return getHeaderValue(AUTHORIZATION).map(v -> HttpUtils.extractAuthorizationBasicCredentials(v)); }
/** * Return the date and time at which the message was created, as specified by the {@link #DATE} header. * @return Message date/time, if available */ default Optional<Date> getDate() { return getHeaderValue(DATE).map(d -> HttpUtils.parseHeaderDate(d)); }