@Override public List<String> all(String name) { return parameters.all(name); }
@Override public Optional<String> first(String name) { return parameters.first(name); }
/** * Creates an instance from provided multi-map. * * @param parameters parameters to copy. */ public ReadOnlyParameters(Parameters parameters) { this(parameters == null ? null : parameters.toMap()); }
private static void decodeQueryParam(Parameters params, String param, boolean decodeNames, boolean decodeValues) { try { int equals = param.indexOf('='); if (equals > 0) { params.add((decodeNames) ? URLDecoder.decode(param.substring(0, equals), "UTF-8") : param.substring(0, equals), (decodeValues) ? URLDecoder.decode(param.substring(equals + 1), "UTF-8") : param.substring(equals + 1)); } else if (equals == 0) { // no key declared, ignore return; } else if (!param.isEmpty()) { params.add((decodeNames) ? URLDecoder.decode(param, "UTF-8") : param, ""); } } catch (UnsupportedEncodingException ex) { // This should never occur throw new IllegalArgumentException("Should never occur!", ex); } } }
@Override public Parameters cookies() { if (cookies == null) { synchronized (internalLock) { if (cookies == null) { List<Parameters> list = all(Http.Header.COOKIE).stream() .map(CookieParser::parse) .collect(Collectors.toList()); cookies = Parameters.toUnmodifiableParameters(HashParameters.concat(list)); } } } return cookies; }
result.add(name, unwrap(value));
/** * Accept requests only when the specified query parameter is valid. * * @param name query parameter name * @param predicate to match the query parameter value * @return composed predicate representing the logical expression between * this predicate <b>AND</b> the provided predicate * @throws NullPointerException if the specified name or predicate is null */ public RequestPredicate containsQueryParameter(final String name, final Predicate<String> predicate) { Objects.requireNonNull(name, "query param name"); Objects.requireNonNull(predicate, "query param predicate"); return and((req) -> req.queryParams() .all(name) .stream() .anyMatch(predicate)); }
/** * Returns a charset from {@code Content-Type} header parameter or {@code null} if not defined. * * @param headers parameters representing request or response headers * @return a charset or {@code null} * @throws RuntimeException if charset is not supported */ private Charset determineCharset(Parameters headers) { return headers.first(Http.Header.CONTENT_TYPE) .map(MediaType::parse) .flatMap(MediaType::charset) .map(sch -> { try { return Charset.forName(sch); } catch (Exception e) { return null; // Do not need default charset. Can use JSON specification. } }) .orElse(null); }
/** * Creates a new instance from provided data. * Initial data are copied. * * @param initialContent initial content. */ HashParameters(Parameters initialContent) { this(initialContent == null ? null : initialContent.toMap()); }
/** * Accept requests only when the specified cookie is valid. * * @param name cookie name * @param predicate predicate to match the cookie value * @return composed predicate representing the logical expression between * this predicate <b>AND</b> the provided predicate * @throws NullPointerException if the specified name or predicate is null */ public RequestPredicate containsCookie(final String name, final Predicate<String> predicate) { Objects.requireNonNull(name, "cookie name"); Objects.requireNonNull(predicate, "cookie predicate"); return and((req) -> req.headers() .cookies() .all(name) .stream() .anyMatch(predicate)); }
/** * Returns content as {@link String} when response is completed when coding charset is get from response and defaults to * {@code UTF-8}. * * @return a completion stage of response. */ public CompletableFuture<String> asString() { Charset charset = headers.first(Http.Header.CONTENT_TYPE) .map(MediaType::parse) .flatMap(MediaType::charset) .map(s -> { try { return Charset.forName(s); } catch (Exception e) { return null; } }) .orElse(StandardCharsets.UTF_8); return asBytes().thenApply(bts -> new String(bts, charset)); }
@Override public Map<String, List<String>> toMap() { return parameters.toMap(); }
void extract(ServerRequest req, Map<String, List<String>> headers) { List<String> values = req.queryParams().all(queryParamName); values.forEach(token -> { String tokenValue = headerHandler.extractToken(token); headerHandler.addHeader(headers, tokenValue); } ); } }
private void processError(ServerRequest req, ServerResponse res) { String error = req.queryParams().first("error").orElse("invalid_request"); String errorDescription = req.queryParams().first("error_description") .orElseGet(() -> "Failed to process authorization request. Expected redirect from OIDC server with code" + " parameter, but got: " + req.query()); LOGGER.log(Level.WARNING, () -> "Received request on OIDC endpoint with no code. Error: " + error + " Error description: " + errorDescription); res.status(Http.Status.BAD_REQUEST_400); res.send("{\"error\": \"" + error + "\", \"error_description\": \"" + errorDescription + "\"}"); }
@Override public void putAll(Parameters parameters) { if (parameters == null) { return; } for (Map.Entry<String, List<String>> entry : parameters.toMap().entrySet()) { List<String> values = entry.getValue(); if (values != null && !values.isEmpty()) { content.put(entry.getKey(), Collections.unmodifiableList(values)); } } }
private void process(ServerRequest req, ServerResponse res) { Set<String> filters = new HashSet<>(req.queryParams().all("name[]")); Enumeration<Collector.MetricFamilySamples> mfs = collectorRegistry.filteredMetricFamilySamples(filters); res.headers().contentType(CONTENT_TYPE); res.send(compose(mfs)); }
rules.get(oidcConfig.redirectUri(), (req, res) -> { Optional<String> codeParam = req.queryParams().first(CODE_PARAM_NAME);
@Override public void addAll(Parameters parameters) { if (parameters == null) { return; } Map<String, List<String>> map = parameters.toMap(); for (Map.Entry<String, List<String>> entry : map.entrySet()) { add(entry.getKey(), entry.getValue()); } }
void extract(ServerRequest req, Map<String, List<String>> headers) { List<String> values = req.queryParams().all(queryParamName); values.forEach(token -> { String tokenValue = headerHandler.extractToken(token); headerHandler.addHeader(headers, tokenValue); } ); } }
String tokenValue = jsonResponse.getString("access_token"); String state = req.queryParams().first(STATE_PARAM_NAME).orElse(DEFAULT_REDIRECT); res.status(Http.Status.TEMPORARY_REDIRECT_307); if (oidcConfig.useParam()) {