Package org.elasticsearch.rest
Class RestUtils
- java.lang.Object
-
- org.elasticsearch.rest.RestUtils
-
public class RestUtils extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static PathTrie.DecoderREST_DECODER
-
Constructor Summary
Constructors Constructor Description RestUtils()
-
Method Summary
Modifier and Type Method Description static java.util.regex.PatterncheckCorsSettingForRegex(java.lang.String corsSetting)Determine if CORS setting is a regexstatic java.lang.String[]corsSettingAsArray(java.lang.String corsSetting)Return the CORS setting as an array of origins.static java.lang.StringdecodeComponent(java.lang.String s)Decodes a bit of an URL encoded by a browser.static java.lang.StringdecodeComponent(java.lang.String s, java.nio.charset.Charset charset)Decodes a bit of an URL encoded by a browser.static voiddecodeQueryString(java.lang.String s, int fromIndex, java.util.Map<java.lang.String,java.lang.String> params)
-
-
-
Field Detail
-
REST_DECODER
public static final PathTrie.Decoder REST_DECODER
-
-
Method Detail
-
decodeQueryString
public static void decodeQueryString(java.lang.String s, int fromIndex, java.util.Map<java.lang.String,java.lang.String> params)
-
decodeComponent
public static java.lang.String decodeComponent(java.lang.String s)
Decodes a bit of an URL encoded by a browser.This is equivalent to calling
decodeComponent(String, Charset)with the UTF-8 charset (recommended to comply with RFC 3986, Section 2).- Parameters:
s- The string to decode (can be empty).- Returns:
- The decoded string, or
sif there's nothing to decode. If the string to decode isnull, returns an empty string. - Throws:
java.lang.IllegalArgumentException- if the string contains a malformed escape sequence.
-
decodeComponent
public static java.lang.String decodeComponent(java.lang.String s, java.nio.charset.Charset charset)Decodes a bit of an URL encoded by a browser.The string is expected to be encoded as per RFC 3986, Section 2. This is the encoding used by JavaScript functions
encodeURIandencodeURIComponent, but notescape. For example in this encoding, é (in UnicodeU+00E9or in UTF-80xC3 0xA9) is encoded as%C3%A9or%c3%a9.This is essentially equivalent to calling
except that it's over 2x faster and generates less garbage for the GC. Actually this function doesn't allocate any memory if there's nothing to decode, the argument itself is returned.URLDecoder.URLDecoder.decode(String, String)- Parameters:
s- The string to decode (can be empty).charset- The charset to use to decode the string (should really beStandardCharsets.UTF_8.- Returns:
- The decoded string, or
sif there's nothing to decode. If the string to decode isnull, returns an empty string. - Throws:
java.lang.IllegalArgumentException- if the string contains a malformed escape sequence.
-
checkCorsSettingForRegex
public static java.util.regex.Pattern checkCorsSettingForRegex(java.lang.String corsSetting)
Determine if CORS setting is a regex- Returns:
- a corresponding
Patternif so and o.w. null.
-
corsSettingAsArray
public static java.lang.String[] corsSettingAsArray(java.lang.String corsSetting)
Return the CORS setting as an array of origins.- Parameters:
corsSetting- the CORS allow origin setting as configured by the user; should never pass null, but we check for it anyway.- Returns:
- an array of origins if set, otherwise
null.
-
-