public class HTTPServer.Request extends Object
Request class encapsulates a single HTTP request.| 限定符和类型 | 字段和说明 |
|---|---|
protected URL |
baseURL |
protected InputStream |
body |
protected HTTPServer.VirtualHost.ContextInfo |
context |
protected HTTPServer.Headers |
headers |
protected HTTPServer.VirtualHost |
host |
protected String |
method |
protected Map<String,String> |
params |
protected Socket |
sock |
protected URI |
uri |
protected String |
version |
| 构造器和说明 |
|---|
Request(InputStream in,
Socket sock)
Constructs a Request from the data in the given input stream.
|
| 限定符和类型 | 方法和说明 |
|---|---|
URL |
getBaseURL()
Returns the base URL (scheme, host and port) of the request resource.
|
InputStream |
getBody()
Returns the input stream containing the request body.
|
HTTPServer.VirtualHost.ContextInfo |
getContext()
Returns the info of the context handling this request.
|
HTTPServer.Headers |
getHeaders()
Returns the request headers.
|
String |
getMethod()
Returns the request method.
|
Map<String,String> |
getParams()
Returns the request parameters, which are parsed both from the query
part of the request URI, and from the request body if its content
type is "application/x-www-form-urlencoded" (i.e. a submitted form).
|
List<String[]> |
getParamsList() |
String |
getPath()
Returns the path component of the request URI, after
URL decoding has been applied (using the UTF-8 charset).
|
long[] |
getRange(long length)
Returns the absolute (zero-based) content range value read
from the Range header.
|
Socket |
getSocket()
Returns the underlying socket, which can be used to retrieve connection meta-data.
|
URI |
getURI()
Returns the request URI.
|
String |
getVersion()
Returns the request version string.
|
HTTPServer.VirtualHost |
getVirtualHost()
Returns the virtual host corresponding to the requested host name,
or the default host if none exists.
|
protected void |
readRequestLine(InputStream in)
Reads the request line, parsing the method, URI and version string.
|
void |
setPath(String path)
Sets the path component of the request URI.
|
protected String method
protected URI uri
protected URL baseURL
protected String version
protected HTTPServer.Headers headers
protected InputStream body
protected Socket sock
protected HTTPServer.VirtualHost host
protected HTTPServer.VirtualHost.ContextInfo context
public Request(InputStream in, Socket sock) throws IOException
in - the input stream from which the request is readsock - the underlying connected socketIOException - if an error occurspublic String getMethod()
public URI getURI()
public String getVersion()
public HTTPServer.Headers getHeaders()
public InputStream getBody()
public Socket getSocket()
public String getPath()
public void setPath(String path)
path - the path to setIllegalArgumentException - if the given path is malformedpublic URL getBaseURL()
public List<String[]> getParamsList() throws IOException
IOExceptionpublic Map<String,String> getParams() throws IOException
For multivalued parameters (i.e. multiple parameters with the same
name), only the first one is considered. For access to all values,
use getParamsList() instead.
The map iteration retains the original order of the parameters.
IOException - if an error occursgetParamsList()public long[] getRange(long length)
length - the full length of the requested resourceprotected void readRequestLine(InputStream in) throws IOException
in - the input stream from which the request line is readIOException - if an error occurs or the request line is invalidpublic HTTPServer.VirtualHost getVirtualHost()
public HTTPServer.VirtualHost.ContextInfo getContext()
Copyright © 2022. All rights reserved.