java.lang.Object
org.cybergarage.http.HTTP
Utility class providing HTTP protocol constants and helper methods.
This class contains commonly used HTTP protocol constants including:
- HTTP methods (GET, POST, HEAD, etc.)
- HTTP headers (Content-Type, Host, etc.)
- HTTP status codes and versions
- UPnP-specific constants
Also provides utility methods for URL manipulation and validation.
Field Summary
Modifier and TypeFieldDescriptionstatic final StringBOOTID.UPNP.ORG header for UPnP device boot IDstatic final StringCache-Control HTTP header field namestatic final StringCALLBACK header for UPnP event subscriptionstatic final StringCharset parameter name within Content-Typestatic final StringChunked transfer encoding valueprivate static intCurrent default chunk size for HTTP transfer operationsstatic final StringConnection close directive valuestatic final StringConnection HTTP header field namestatic final StringContent-Language HTTP header field namestatic final StringContent-Length HTTP header field namestatic final StringContent-Range HTTP header field namestatic final StringBytes range unit value for Content-Rangestatic final StringContent-Type HTTP header field namestatic final byteCarriage return characterstatic final StringHTTP line terminator (CR+LF)static final StringDate HTTP header field namestatic final intDefault chunk size in bytes (512KB)static final intDefault HTTP portstatic final intDefault timeout in secondsstatic final StringEXT header confirming MAN was understoodstatic final StringGET HTTP methodstatic final StringHEAD HTTP methodstatic final StringHeader line delimiter (colon-space between name and value)static final StringHost HTTP header field namestatic final StringKeep-Alive HTTP header field namestatic final byteLine feed characterstatic final StringLocation HTTP header field name (used for redirects)static final StringM-SEARCH HTTP method (used by UPnP discovery)static final StringMAN (Mandatory Extension) header for UPnP discoverystatic final StringCache-Control max-age directive namestatic final StringMX (Maximum Wait) header for UPnP discoverystatic final StringMYNAME header for UPnP device identificationstatic final StringCache-Control no-cache directive valuestatic final StringNOTIFY HTTP method (used by UPnP eventing)static final StringNT (Notification Type) header for UPnP eventingstatic final StringNTS (Notification Sub Type) header for UPnP eventingstatic final StringPOST HTTP methodstatic final StringRange HTTP header field namestatic final StringRequest line delimiter (space between method, URI, version)static final StringSEQ (Sequence Number) header for UPnP eventingstatic final StringServer HTTP header field namestatic final StringSID (Session ID) header for UPnP eventingstatic final StringSOAPAction HTTP header field namestatic final StringST (Search Target) header for UPnP discoverystatic final StringStatus line delimiter (space between version, code, phrase)static final StringSUBSCRIBE HTTP method (used by UPnP eventing)static final StringTab characterstatic final StringTIMEOUT header for UPnP event subscriptionstatic final StringTransfer-Encoding HTTP header field namestatic final StringUNSUBSCRIBE HTTP method (used by UPnP eventing)static final StringUSN (Unique Service Name) header for UPnP discoverystatic final StringDefault HTTP version stringstatic final StringHTTP/1.0 version stringstatic final StringHTTP/1.1 version stringConstructor Summary
ConstructorsMethod Summary
All MethodsModifier and TypeMethodDescriptionstatic final StringgetAbsoluteURL(String baseURLStr, String relURlStr) Creates an absolute URL by combining base URL with relative URL.static final intGets the current default chunk size for HTTP operations.static final StringExtracts the host name from a URL string.static final intExtracts the port number from a URL string.static final StringgetRequestHostURL(String host, int port) Creates a request host URL from host and port.static final booleanisAbsoluteURL(String urlStr) Checks if a string represents an absolute URL.static final voidsetChunkSize(int size) Sets the default chunk size for HTTP operations.static final StringtoRelativeURL(String urlStr) Converts a URL to a relative URL path with query parameters.static final StringtoRelativeURL(String urlStr, boolean withParam) Converts a URL to a relative URL path.
Field Details
HOST
VERSION
VERSION_10
VERSION_11
CRLF
CR
LF
TAB
SOAP_ACTION
SOAPAction HTTP header field name- See Also:
M_SEARCH
M-SEARCH HTTP method (used by UPnP discovery)- See Also:
NOTIFY
NOTIFY HTTP method (used by UPnP eventing)- See Also:
POST
GET
HEAD
SUBSCRIBE
SUBSCRIBE HTTP method (used by UPnP eventing)- See Also:
UNSUBSCRIBE
UNSUBSCRIBE HTTP method (used by UPnP eventing)- See Also:
DATE
CACHE_CONTROL
Cache-Control HTTP header field name- See Also:
NO_CACHE
Cache-Control no-cache directive value- See Also:
MAX_AGE
Cache-Control max-age directive name- See Also:
CONNECTION
Connection HTTP header field name- See Also:
CLOSE
KEEP_ALIVE
Keep-Alive HTTP header field name- See Also:
CONTENT_TYPE
Content-Type HTTP header field name- See Also:
CHARSET
Charset parameter name within Content-Type- See Also:
CONTENT_LENGTH
Content-Length HTTP header field name- See Also:
CONTENT_LANGUAGE
Content-Language HTTP header field name- See Also:
CONTENT_RANGE
Content-Range HTTP header field name- See Also:
CONTENT_RANGE_BYTES
Bytes range unit value for Content-Range- See Also:
RANGE
TRANSFER_ENCODING
Transfer-Encoding HTTP header field name- See Also:
CHUNKED
LOCATION
Location HTTP header field name (used for redirects)- See Also:
SERVER
ST
ST (Search Target) header for UPnP discovery- See Also:
MX
MX (Maximum Wait) header for UPnP discovery- See Also:
MAN
MAN (Mandatory Extension) header for UPnP discovery- See Also:
NT
NT (Notification Type) header for UPnP eventing- See Also:
NTS
NTS (Notification Sub Type) header for UPnP eventing- See Also:
USN
USN (Unique Service Name) header for UPnP discovery- See Also:
EXT
EXT header confirming MAN was understood- See Also:
SID
SID (Session ID) header for UPnP eventing- See Also:
SEQ
SEQ (Sequence Number) header for UPnP eventing- See Also:
CALLBACK
CALLBACK header for UPnP event subscription- See Also:
TIMEOUT
TIMEOUT header for UPnP event subscription- See Also:
BOOTID_UPNP_ORG
BOOTID.UPNP.ORG header for UPnP device boot ID- See Also:
MYNAME
MYNAME header for UPnP device identification- See Also:
REQEST_LINE_DELIM
Request line delimiter (space between method, URI, version)- See Also:
HEADER_LINE_DELIM
Header line delimiter (colon-space between name and value)- See Also:
STATUS_LINE_DELIM
Status line delimiter (space between version, code, phrase)- See Also:
DEFAULT_PORT
DEFAULT_CHUNK_SIZE
public static final int DEFAULT_CHUNK_SIZEDefault chunk size in bytes (512KB)- See Also:
DEFAULT_TIMEOUT
chunkSize
private static int chunkSizeCurrent default chunk size for HTTP transfer operations
Constructor Details
HTTP
public HTTP()Constructor. The header names, status codes and URL helpers below are all static, so an instance holds nothing.
Method Details
isAbsoluteURL
Checks if a string represents an absolute URL.- Parameters:
urlStr- string to check- Returns:
- true if the string is a valid absolute URL, false otherwise
getHost
getPort
Extracts the port number from a URL string. Returns default HTTP port (80) if no port is specified.- Parameters:
urlStr- URL string to extract port from- Returns:
- port number, or default port (80) if URL is invalid or no port specified
getRequestHostURL
toRelativeURL
toRelativeURL
getAbsoluteURL
setChunkSize
public static final void setChunkSize(int size) Sets the default chunk size for HTTP operations.- Parameters:
size- chunk size in bytes
getChunkSize
public static final int getChunkSize()Gets the current default chunk size for HTTP operations.- Returns:
- chunk size in bytes