Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.vertx.groovy.core.http
[Groovy] Class HttpClientRequest

    java.lang.Object
      org.vertx.groovy.core.http.HttpClientRequest

All Implemented Interfaces:
  WriteStream

    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.

Authors:
  Tim Fox

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, int), java.lang.Object#wait(long), 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

### HttpClientRequest

    protected HttpClientRequest(JHttpClientRequest jRequest)

Method Detail

### continueHandler

    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.

  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.

### drainHandler

    void drainHandler(groovy.lang.Closure handler)

  {@inheritDoc}

### end

    void end(java.lang.String chunk)

  Same as end(Buffer) but writes a String with the default encoding

### end

    void end(java.lang.String chunk, java.lang.String enc)

  Same as end(Buffer) but writes a String with the specified encoding

### end

    void end(Buffer chunk)

  Same as end() but writes some data to the request body before ending. If the request is not chunked and no other data has been written then the Content-Length header will be automatically set

### end

    void end()

  Ends the request. If no data has been written to the request body, and sendHead() has not been called then the actual request won't get written until this method gets called.

  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.

### exceptionHandler

    void exceptionHandler(groovy.lang.Closure handler)

  {@inheritDoc}

### getHeaders

    java.util.Map getHeaders()

  Returns:
    The HTTP headers

### isWriteQueueFull

    boolean isWriteQueueFull()

  {@inheritDoc}

### leftShift

    HttpClientRequest leftShift(Buffer buff)

  Same as write(Buffer)
  Parameters:
    `buff` - The buffer to write
  Returns:
    @return A reference to this, so multiple method calls can be chained.

### leftShift

    HttpClientRequest leftShift(java.lang.String str)

  Same as write(String)
  Parameters:
    `buff` - The buffer to write
  Returns:
    @return A reference to this, so multiple method calls can be chained.

### putHeader

    HttpClientRequest putHeader(java.lang.String name, java.lang.Object value)

  Put an HTTP header - fluent API
  Parameters:
    `name` - The header name
    `value` - The header value
  Returns:
    A reference to this, so multiple method calls can be chained.

### sendHead

    HttpClientRequest sendHead()

  Forces the head of the request to be written before end() is called on the request. This is normally used to implement HTTP 100-continue handling, see continueHandler(Closure) for more information.
  Returns:
    A reference to this, so multiple method calls can be chained.

### setChunked

    HttpClientRequest setChunked(boolean chunked)

  If chunked is true then the request will be set into HTTP chunked mode
  Parameters:
    chunked
  Returns:
    A reference to this, so multiple method calls can be chained.

### setWriteQueueMaxSize

    void setWriteQueueMaxSize(int maxSize)

  {@inheritDoc}

### write

    HttpClientRequest write(Buffer chunk)

  Write a Buffer to the request body.
  Returns:
    A reference to this, so multiple method calls can be chained.

### write

    HttpClientRequest write(java.lang.String chunk)

  Write a java.lang.String to the request body, encoded in UTF-8.
  Returns:
    A reference to this, so multiple method calls can be chained.

### write

    HttpClientRequest write(java.lang.String chunk, java.lang.String enc)

  Write a java.lang.String to the request body, encoded using the encoding `enc`.
  Returns:
    A reference to this, so multiple method calls can be chained.

### write

    HttpClientRequest write(Buffer chunk, groovy.lang.Closure doneHandler)

  Write a Buffer to the request body. The `doneHandler` is called after the buffer is actually written to the wire.
  Returns:
    A reference to this, so multiple method calls can be chained.

### write

    HttpClientRequest write(java.lang.String chunk, groovy.lang.Closure doneHandler)

  Write a java.lang.String to the request body, encoded in UTF-8. The `doneHandler` is called after the buffer is actually written to the wire.
  Returns:
    A reference to this, so multiple method calls can be chained.

### write

    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`. The `doneHandler` is called after the buffer is actually written to the wire.
  Returns:
    A reference to this, so multiple method calls can be chained.

### writeBuffer

    void writeBuffer(Buffer chunk)

  {@inheritDoc}

Groovy Documentation