Package com.browserup.bup.util
Class HttpUtil
- java.lang.Object
-
- com.browserup.bup.util.HttpUtil
-
public class HttpUtil extends java.lang.ObjectContains utility methods for nettyHttpRequestand related objects.
-
-
Constructor Summary
Constructors Constructor Description HttpUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringgetHostAndPortFromRequest(io.netty.handler.codec.http.HttpRequest httpRequest)Gets the host and port from the specified request.static java.lang.StringgetHostAndPortFromUri(java.lang.String uriString)Retrieves the host and port from the specified URI.static java.lang.StringgetHostFromRequest(io.netty.handler.codec.http.HttpRequest httpRequest)Identify the host of an HTTP request.static booleanstartsWithHttpOrHttps(java.lang.String uri)Returns true if the string starts with http:// or https://.
-
-
-
Method Detail
-
getHostFromRequest
public static java.lang.String getHostFromRequest(io.netty.handler.codec.http.HttpRequest httpRequest)
Identify the host of an HTTP request. This method uses the URI of the request if possible, otherwise it attempts to find the host in the request headers.- Parameters:
httpRequest- HTTP request to parse the host from- Returns:
- the host the request is connecting to, or null if no host can be found
-
getHostAndPortFromRequest
public static java.lang.String getHostAndPortFromRequest(io.netty.handler.codec.http.HttpRequest httpRequest)
Gets the host and port from the specified request. Returns the host and port from the request URI if available, otherwise retrieves the host and port from the Host header.- Parameters:
httpRequest- HTTP request- Returns:
- host and port of the request
-
startsWithHttpOrHttps
public static boolean startsWithHttpOrHttps(java.lang.String uri)
Returns true if the string starts with http:// or https://.- Parameters:
uri- string to evaluate- Returns:
- true if the string starts with http:// or https://
-
getHostAndPortFromUri
public static java.lang.String getHostAndPortFromUri(java.lang.String uriString) throws java.net.URISyntaxExceptionRetrieves the host and port from the specified URI.- Parameters:
uriString- URI to retrieve the host and port from- Returns:
- the host and port from the URI as a String
- Throws:
java.net.URISyntaxException- if the specified URI is invalid or cannot be parsed
-
-