|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.vertx.groovy.core.http.HttpClientRequest
class HttpClientRequest
Represents a client-side HTTP request.
Instances of this class are created by an HttpClient instance, via one of the methods corresponding to the specific HTTP methods, or the generic HttpClient#request#request method.
Once a request has been obtained, headers can be set on it, and data can be written to its body if required. Once you are ready to send the request, the #end() method should be called.
Nothing is actually sent until the request has been internally assigned an HTTP connection. The HttpClient instance will return an instance of this class immediately, even if there are no HTTP connections available in the pool. Any requests sent before a connection is assigned will be queued internally and actually sent when an HTTP connection becomes available from the pool.
The headers of the request are actually sent either when the #end() method is called, or, when the first part of the body is written, whichever occurs first.
This class supports both chunked and non-chunked HTTP.
It implements WriteStream so it can be used with org.vertx.java.core.streams.Pump to pump data with flow control.
Instances of this class are not thread-safe
An example of using this class is as follows:
def req = httpClient.post("/some-url") { response -> println "Got response: ${response.statusCode}" } req.putHeader("some-header", "hello") req.putHeader("Content-Length", 5) req.write << buffer req.write << "some-string" req.end()The headers are also accessible as a Map so you can use index notation to access them.
Constructor Summary | |
protected HttpClientRequest(JHttpClientRequest jRequest)
|
Method Summary | |
---|---|
void
|
continueHandler(groovy.lang.Closure handler)
If you send an HTTP request with the header Expect set to the value 100-continue and the server responds with an interim HTTP response with a status code of 100 and a continue handler has been set using this method, then the handler will be called. |
void
|
drainHandler(groovy.lang.Closure handler)
{@inheritDoc} |
void
|
end(java.lang.String chunk)
Same as end(Buffer) but writes a String with the default encoding |
void
|
end(java.lang.String chunk, java.lang.String enc)
Same as end(Buffer) but writes a String with the specified encoding |
void
|
end(Buffer chunk)
Same as end() but writes some data to the request body before ending. |
void
|
end()
Ends the request. |
void
|
exceptionHandler(groovy.lang.Closure handler)
{@inheritDoc} |
java.util.Map
|
getHeaders()
@return The HTTP headers |
boolean
|
isWriteQueueFull()
{@inheritDoc} |
HttpClientRequest
|
leftShift(Buffer buff)
Same as write(Buffer) |
HttpClientRequest
|
leftShift(java.lang.String str)
Same as write(String) |
HttpClientRequest
|
putHeader(java.lang.String name, java.lang.Object value)
Put an HTTP header - fluent API |
HttpClientRequest
|
sendHead()
Forces the head of the request to be written before end() is called on the request. |
HttpClientRequest
|
setChunked(boolean chunked)
If chunked is true then the request will be set into HTTP chunked mode |
void
|
setWriteQueueMaxSize(int maxSize)
{@inheritDoc} |
HttpClientRequest
|
write(Buffer chunk)
Write a Buffer to the request body. |
HttpClientRequest
|
write(java.lang.String chunk)
Write a java.lang.String to the request body, encoded in UTF-8. |
HttpClientRequest
|
write(java.lang.String chunk, java.lang.String enc)
Write a java.lang.String to the request body, encoded using the encoding enc. |
HttpClientRequest
|
write(Buffer chunk, groovy.lang.Closure doneHandler)
Write a Buffer to the request body. |
HttpClientRequest
|
write(java.lang.String chunk, groovy.lang.Closure doneHandler)
Write a java.lang.String to the request body, encoded in UTF-8. |
HttpClientRequest
|
write(java.lang.String chunk, java.lang.String enc, groovy.lang.Closure doneHandler)
Write a java.lang.String to the request body, encoded with encoding enc. |
void
|
writeBuffer(Buffer chunk)
{@inheritDoc} |
Methods inherited from class java.lang.Object | |
---|---|
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Constructor Detail |
---|
protected HttpClientRequest(JHttpClientRequest jRequest)
Method Detail |
---|
void continueHandler(groovy.lang.Closure handler)
You can then continue to write data to the request body and later end it. This is normally used in conjunction with the sendHead() method to force the request header to be written before the request has ended.
void drainHandler(groovy.lang.Closure handler)
void end(java.lang.String chunk)
void end(java.lang.String chunk, java.lang.String enc)
void end(Buffer chunk)
void end()
Once the request has ended, it cannot be used any more, and if keep alive is true the underlying connection will be returned to the HttpClient pool so it can be assigned to another request.
void exceptionHandler(groovy.lang.Closure handler)
java.util.Map getHeaders()
boolean isWriteQueueFull()
HttpClientRequest leftShift(Buffer buff)
buff
- The buffer to write
HttpClientRequest leftShift(java.lang.String str)
buff
- The buffer to write
HttpClientRequest putHeader(java.lang.String name, java.lang.Object value)
name
- The header namevalue
- The header value
HttpClientRequest sendHead()
HttpClientRequest setChunked(boolean chunked)
void setWriteQueueMaxSize(int maxSize)
HttpClientRequest write(Buffer chunk)
HttpClientRequest write(java.lang.String chunk)
HttpClientRequest write(java.lang.String chunk, java.lang.String enc)
HttpClientRequest write(Buffer chunk, groovy.lang.Closure doneHandler)
HttpClientRequest write(java.lang.String chunk, groovy.lang.Closure doneHandler)
HttpClientRequest write(java.lang.String chunk, java.lang.String enc, groovy.lang.Closure doneHandler)
void writeBuffer(Buffer chunk)
Groovy Documentation