-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This URL encodes the username when supplying it as part of the URL (rather than as part of an auth header).
- Loading branch information
Showing
2 changed files
with
33 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.elastic.support.util; | ||
|
||
import java.net.URLEncoder; | ||
import java.nio.charset.StandardCharsets; | ||
import java.io.UnsupportedEncodingException; | ||
|
||
/** | ||
* {@code UrlUtils} contains helpful methods for dealing with URLs. | ||
*/ | ||
public class UrlUtils { | ||
/** | ||
* URL Encode the {@code value}. | ||
* | ||
* @param value The value to URL encode. | ||
* @return Never {@code null}. | ||
* @throws RuntimeException if encoding throws an exception. | ||
*/ | ||
public static String encodeValue(String value) { | ||
try { | ||
return URLEncoder.encode(value, StandardCharsets.UTF_8.toString()); | ||
} catch (UnsupportedEncodingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |