@Beta public class MockLowLevelHttpRequest extends LowLevelHttpRequest
| 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.
|
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()
Returns an unmodifiable view of the map of lowercase header name to values.
|
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. |
MockLowLevelHttpRequest |
setResponse(MockLowLevelHttpResponse response)
Sets the HTTP response to return from
execute(). |
MockLowLevelHttpRequest |
setUrl(String url)
Sets the request URL or
null for none. |
getContentEncoding, getContentLength, getContentType, getStreamingContent, setContentEncoding, setContentLength, setContentType, setStreamingContent, setTimeout, setWriteTimeoutpublic MockLowLevelHttpRequest()
public MockLowLevelHttpRequest(String url)
url - Request URL or null for nonepublic void addHeader(String name, String value) throws IOException
LowLevelHttpRequestNote 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 LowLevelHttpRequestname - header namevalue - header valueIOExceptionpublic LowLevelHttpResponse execute() throws IOException
LowLevelHttpRequestexecute in class LowLevelHttpRequestIOExceptionpublic String getUrl()
null for none.public Map<String,List<String>> getHeaders()
Note that unlike this method, getFirstHeaderValue(String) and getHeaderValues(String) are not case sensitive with respect to the input header name.
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 String getContentAsString() throws IOException
Returns an empty string if there is no HTTP content.
IOExceptionpublic MockLowLevelHttpResponse getResponse()
execute().public MockLowLevelHttpRequest setResponse(MockLowLevelHttpResponse response)
execute().
By default this is a new instance of MockLowLevelHttpResponse.
Copyright © 2011–2025 Google. All rights reserved.