public class MockLowLevelHttpRequest extends LowLevelHttpRequest
LowLevelHttpRequest
.
Implementation is not thread-safe.
Constructor and Description |
---|
MockLowLevelHttpRequest() |
MockLowLevelHttpRequest(String url) |
Modifier and Type | Method and Description |
---|---|
void |
addHeader(String name,
String value)
Adds a header to the HTTP request.
|
LowLevelHttpResponse |
execute()
Executes the request and returns a low-level HTTP response object.
|
HttpContent |
getContent()
Returns the HTTP content or
null for none. |
String |
getContentAsString()
Returns HTTP content as a string, taking care of any encodings of the content if necessary.
|
String |
getFirstHeaderValue(String name)
Returns the value of the first header of the given name or
null for none. |
Map<String,List<String>> |
getHeaders()
Deprecated.
(scheduled in 1.14 to have the return type changed to ListMultimap
getFirstHeaderValue(String) or
getHeaderValues(String) |
List<String> |
getHeaderValues(String name)
Returns the unmodifiable list of values of the headers of the given name (may be empty).
|
MockLowLevelHttpResponse |
getResponse()
HTTP response to return from
execute() . |
String |
getUrl()
Returns the request URL or
null for none. |
void |
setContent(HttpContent content)
Sets the HTTP request content.
|
MockLowLevelHttpRequest |
setResponse(MockLowLevelHttpResponse response)
Sets the HTTP response to return from
execute() . |
MockLowLevelHttpRequest |
setUrl(String url)
Sets the request URL or
null for none. |
setTimeout
public MockLowLevelHttpRequest()
public MockLowLevelHttpRequest(String url)
url
- Request URL or null
for nonepublic void addHeader(String name, String value) throws IOException
LowLevelHttpRequest
Note that multiple headers of the same name need to be supported, in which case
LowLevelHttpRequest.addHeader(java.lang.String, java.lang.String)
will be called for each instance of the header.
addHeader
in class LowLevelHttpRequest
name
- header namevalue
- header valueIOException
public LowLevelHttpResponse execute() throws IOException
LowLevelHttpRequest
execute
in class LowLevelHttpRequest
IOException
public void setContent(HttpContent content) throws IOException
LowLevelHttpRequest
setContent
in class LowLevelHttpRequest
IOException
public String getUrl()
null
for none.@Deprecated public Map<String,List<String>> getHeaders()
getFirstHeaderValue(String)
or
getHeaderValues(String)
public String getFirstHeaderValue(String name)
null
for none.name
- header name (may be any case)public List<String> getHeaderValues(String name)
name
- header name (may be any case)public MockLowLevelHttpRequest setUrl(String url)
null
for none.public HttpContent getContent()
null
for none.public String getContentAsString() throws IOException
IOException
public MockLowLevelHttpResponse getResponse()
execute()
.public MockLowLevelHttpRequest setResponse(MockLowLevelHttpResponse response)
execute()
.
By default this is a new instance of MockLowLevelHttpResponse
.
Copyright © 2011-2012 Google. All Rights Reserved.