if (c == '=' && name == null) { if (pos != i) { name = decodeComponent(s.substring(pos, i)); addParam(params, decodeComponent(s.substring(pos, i)), ""); } else if (name != null) { addParam(params, name, decodeComponent(s.substring(pos, i))); name = null; addParam(params, decodeComponent(s.substring(pos, i)), ""); } else { // Yes and this must be the last value. addParam(params, name, decodeComponent(s.substring(pos, i))); addParam(params, name, "");
if (!decodingNeeded(s, size)) { return s; int pos = decode(s, size, buf); return new String(buf, 0, pos, charset);
throw new IllegalArgumentException("partial escape sequence at end of string: " + s); c = decodeHexNibble(c); final char c2 = decodeHexNibble(s.charAt(++i)); if (c == Character.MAX_VALUE || c2 == Character.MAX_VALUE) { throw new IllegalArgumentException(
builder = Netty4CorsConfigBuilder.forAnyOrigin(); } else { Pattern p = RestUtils.checkCorsSettingForRegex(origin); if (p == null) { builder = Netty4CorsConfigBuilder.forOrigins(RestUtils.corsSettingAsArray(origin)); } else { builder = Netty4CorsConfigBuilder.forPattern(p);
@Override public String decode(String value) { return RestUtils.decodeComponent(value); } };
private static Map<String, String> params(final String uri) { final Map<String, String> params = new HashMap<>(); int index = uri.indexOf('?'); if (index >= 0) { try { RestUtils.decodeQueryString(uri, index + 1, params); } catch (final IllegalArgumentException e) { throw new BadParameterException(e); } } return params; }
private Netty3CorsConfig buildCorsConfig(Settings settings) { if (SETTING_CORS_ENABLED.get(settings) == false) { return Netty3CorsConfigBuilder.forOrigins().disable().build(); } String origin = SETTING_CORS_ALLOW_ORIGIN.get(settings); final Netty3CorsConfigBuilder builder; if (Strings.isNullOrEmpty(origin)) { builder = Netty3CorsConfigBuilder.forOrigins(); } else if (origin.equals(ANY_ORIGIN)) { builder = Netty3CorsConfigBuilder.forAnyOrigin(); } else { Pattern p = RestUtils.checkCorsSettingForRegex(origin); if (p == null) { builder = Netty3CorsConfigBuilder.forOrigins(RestUtils.corsSettingAsArray(origin)); } else { builder = Netty3CorsConfigBuilder.forPattern(p); } } if (SETTING_CORS_ALLOW_CREDENTIALS.get(settings)) { builder.allowCredentials(); } Set<String> strMethods = Strings.splitStringByCommaToSet(SETTING_CORS_ALLOW_METHODS.get(settings)); return builder.allowedRequestMethods(strMethods.stream().map(HttpMethod::valueOf).collect(Collectors.toSet())) .maxAge(SETTING_CORS_MAX_AGE.get(settings)) .allowedRequestHeaders(Strings.splitStringByCommaToSet(SETTING_CORS_ALLOW_HEADERS.get(settings))) .shortCircuit() .build(); }
/** * Decodes a bit of an URL encoded by a browser. * <p> * This is equivalent to calling {@link #decodeComponent(String, Charset)} * with the UTF-8 charset (recommended to comply with RFC 3986, Section 2). * * @param s The string to decode (can be empty). * @return The decoded string, or {@code s} if there's nothing to decode. * If the string to decode is {@code null}, returns an empty string. * @throws IllegalArgumentException if the string contains a malformed * escape sequence. */ public static String decodeComponent(final String s) { return decodeComponent(s, StandardCharsets.UTF_8); }
private static Map<String, String> params(final String uri) { final Map<String, String> params = new HashMap<>(); int index = uri.indexOf('?'); if (index >= 0) { try { RestUtils.decodeQueryString(uri, index + 1, params); } catch (final IllegalArgumentException e) { throw new BadParameterException(e); } } return params; }
builder = Netty4CorsConfigBuilder.forAnyOrigin(); } else { Pattern p = RestUtils.checkCorsSettingForRegex(origin); if (p == null) { builder = Netty4CorsConfigBuilder.forOrigins(RestUtils.corsSettingAsArray(origin)); } else { builder = Netty4CorsConfigBuilder.forPattern(p);
if (!decodingNeeded(s, size)) { return s; int pos = decode(s, size, buf); return new String(buf, 0, pos, charset);
if (c == '=' && name == null) { if (pos != i) { name = decodeComponent(s.substring(pos, i)); addParam(params, decodeComponent(s.substring(pos, i)), ""); } else if (name != null) { addParam(params, name, decodeComponent(s.substring(pos, i))); name = null; addParam(params, decodeComponent(s.substring(pos, i)), ""); } else { // Yes and this must be the last value. addParam(params, name, decodeComponent(s.substring(pos, i))); addParam(params, name, "");
/** * The path part of the URI (without the query string), decoded. */ public final String path() { return RestUtils.decodeComponent(rawPath()); }
private static Map<String, String> params(final String uri) { final Map<String, String> params = new HashMap<>(); int index = uri.indexOf('?'); if (index >= 0) { try { RestUtils.decodeQueryString(uri, index + 1, params); } catch (final IllegalArgumentException e) { throw new BadParameterException(e); } } return params; }
throw new IllegalArgumentException("partial escape sequence at end of string: " + s); c = decodeHexNibble(c); final char c2 = decodeHexNibble(s.charAt(++i)); if (c == Character.MAX_VALUE || c2 == Character.MAX_VALUE) { throw new IllegalArgumentException(
} else { try { Pattern p = RestUtils.checkCorsSettingForRegex(origin); if (p == null) { builder = Netty4CorsConfigBuilder.forOrigins(RestUtils.corsSettingAsArray(origin)); } else { builder = Netty4CorsConfigBuilder.forPattern(p);
if (!decodingNeeded(s, size)) { return s; int pos = decode(s, size, buf); return new String(buf, 0, pos, charset);
if (c == '=' && name == null) { if (pos != i) { name = decodeComponent(s.substring(pos, i)); addParam(params, decodeComponent(s.substring(pos, i)), ""); } else if (name != null) { addParam(params, name, decodeComponent(s.substring(pos, i))); name = null; addParam(params, decodeComponent(s.substring(pos, i)), ""); } else { // Yes and this must be the last value. addParam(params, name, decodeComponent(s.substring(pos, i))); addParam(params, name, "");
@Override public String decode(String value) { return RestUtils.decodeComponent(value); } };
/** * Creates a new RestRequest * @param xContentRegistry the xContentRegistry to use when parsing XContent * @param uri the URI of the request that potentially contains request parameters * @param headers a map of the headers. This map should implement a Case-Insensitive hashing for keys as HTTP header names are case * insensitive */ public RestRequest(NamedXContentRegistry xContentRegistry, String uri, Map<String, List<String>> headers) { this.xContentRegistry = xContentRegistry; final Map<String, String> params = new HashMap<>(); int pathEndPos = uri.indexOf('?'); if (pathEndPos < 0) { this.rawPath = uri; } else { this.rawPath = uri.substring(0, pathEndPos); RestUtils.decodeQueryString(uri, pathEndPos + 1, params); } this.params = params; this.headers = Collections.unmodifiableMap(headers); final List<String> contentType = getAllHeaderValues("Content-Type"); final XContentType xContentType = parseContentType(contentType); if (xContentType != null) { this.xContentType.set(xContentType); } }