public final class HttpRequestHeaders extends Object
| Modifier and Type | Field and Description |
|---|---|
protected static byte[] |
SPACE |
| Constructor and Description |
|---|
HttpRequestHeaders(InputStream inputStream)
This creates an instance of this class by reading request line and headers from a stream
|
HttpRequestHeaders(String requestLine,
String... headers)
This creates an instance of HttpRequestHeaders
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addHeader(String line)
Adds a header, if header header with this name already exists, it adds a new entry without deleting existing
|
void |
addHeader(String headerName,
String headerValue)
Adds a header, if header header with this name already exists, it adds a new entry without deleting existing
|
static HttpRequestHeaders |
connectRequest(String host)
Creates request headers for CONNECT request
|
long |
getContentLength() |
String |
getHeader(String headerName)
This returns a header by name, if there are more then one header with this name, the first one will be returned
Returns null if header does not exit
|
List<String> |
getHeaders(String headerName)
This returns headers by name, if there are more then one header with this name, all of them will be returned
|
String |
getHost()
This returns host from Host header or, if Host header does not exist (e.g.
|
String |
getMethod() |
String |
getPath() |
static HttpRequestHeaders |
getRequest(String url)
Creates request headers for GET request
|
URL |
getUrl()
This returns Url based on command line and host header.
|
String |
getVersion() |
boolean |
hasChunkedBody() |
List<String> |
listHeaderNames() |
static HttpRequestHeaders |
postRequest(String url)
Creates request headers for POST request
|
protected void |
readHeaders(serguei.http.HeaderLineReader reader)
Read headers into the stream
|
void |
removeHeader(String headerName)
Removes header with a specified name
|
void |
setHeader(String headerName,
String value)
Sets header If headers with this name already exists, replaces it
|
String |
toString() |
void |
write(OutputStream outputStream)
This writes the request line and headers into the output stream
This includes an empty line separating headers and body (i.e.
|
public HttpRequestHeaders(String requestLine, String... headers) throws HttpException
requestLine - - request line, e.g. "GET / HTTP/1."headers - - headers in the form "Host: www.google.co.uk"HttpException - - can be thrown when request line or headers do not follow HTTP standardspublic HttpRequestHeaders(InputStream inputStream) throws IOException
inputStream - IOException - - thrown when the data is not HTTP or IO errorspublic URL getUrl() throws HttpException
HttpException - - thrown when URL is incorrectpublic String getHost() throws HttpException
HttpException - - thrown if there was an error parsing path in request linepublic void write(OutputStream outputStream) throws IOException
IOExceptionpublic String getMethod()
public String getVersion()
public String getPath()
public String toString()
public static HttpRequestHeaders connectRequest(String host)
public static HttpRequestHeaders getRequest(String url) throws IOException
IOExceptionpublic static HttpRequestHeaders postRequest(String url) throws IOException
IOExceptionprotected void readHeaders(serguei.http.HeaderLineReader reader)
throws IOException
IOExceptionpublic String getHeader(String headerName)
public List<String> getHeaders(String headerName)
public long getContentLength()
public boolean hasChunkedBody()
protected void addHeader(String line) throws HttpException
HttpExceptionpublic void setHeader(String headerName, String value)
public void addHeader(String headerName, String headerValue)
public void removeHeader(String headerName)
Copyright © 2019. All rights reserved.