@Beta public class MockLowLevelHttpRequest extends LowLevelHttpRequest
Constructor and Description |
---|
MockLowLevelHttpRequest() |
MockLowLevelHttpRequest(java.lang.String url) |
Modifier and Type | Method and Description |
---|---|
void |
addHeader(java.lang.String name,
java.lang.String value)
Adds a header to the HTTP request.
|
LowLevelHttpResponse |
execute()
Executes the request and returns a low-level HTTP response object.
|
java.lang.String |
getContentAsString()
Returns HTTP content as a string, taking care of any encodings of the content if necessary.
|
java.lang.String |
getFirstHeaderValue(java.lang.String name)
Returns the value of the first header of the given name or
null for none. |
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getHeaders()
Returns an unmodifiable view of the map of lowercase header name to values.
|
java.util.List<java.lang.String> |
getHeaderValues(java.lang.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() . |
java.lang.String |
getUrl()
Returns the request URL or
null for none. |
MockLowLevelHttpRequest |
setResponse(MockLowLevelHttpResponse response)
Sets the HTTP response to return from
execute() . |
MockLowLevelHttpRequest |
setUrl(java.lang.String url)
Sets the request URL or
null for none. |
getContentEncoding, getContentLength, getContentType, getStreamingContent, setContentEncoding, setContentLength, setContentType, setStreamingContent, setTimeout
public MockLowLevelHttpRequest()
public MockLowLevelHttpRequest(java.lang.String url)
url
- Request URL or null
for nonepublic void addHeader(java.lang.String name, java.lang.String value) throws java.io.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 valuejava.io.IOException
public LowLevelHttpResponse execute() throws java.io.IOException
LowLevelHttpRequest
execute
in class LowLevelHttpRequest
java.io.IOException
public java.lang.String getUrl()
null
for none.public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaders()
Note that unlike this method, getFirstHeaderValue(String)
and
getHeaderValues(String)
are not case sensitive with respect to the input header name.
public java.lang.String getFirstHeaderValue(java.lang.String name)
null
for none.name
- header name (may be any case)public java.util.List<java.lang.String> getHeaderValues(java.lang.String name)
name
- header name (may be any case)public MockLowLevelHttpRequest setUrl(java.lang.String url)
null
for none.public java.lang.String getContentAsString() throws java.io.IOException
Returns an empty string if there is no HTTP content.
java.io.IOException
public MockLowLevelHttpResponse getResponse()
execute()
.public MockLowLevelHttpRequest setResponse(MockLowLevelHttpResponse response)
execute()
.
By default this is a new instance of MockLowLevelHttpResponse
.
Copyright © 2011-2018 Google. All Rights Reserved.