/*
 * Copyright 2014 Red Hat, Inc.
 *
 * Red Hat licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package io.vertx.reactivex.core.http;

import java.util.Map;
import io.reactivex.Observable;
import io.reactivex.Flowable;
import io.reactivex.Single;
import io.reactivex.Completable;
import io.reactivex.Maybe;
import io.vertx.core.http.StreamPriority;
import javax.net.ssl.SSLSession;
import io.vertx.core.http.HttpVersion;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;

Represents a server-side HTTP request.

Instances are created for each request and passed to the user via a handler.

Each instance of this class is associated with a corresponding HttpServerResponse instance via response.

It implements ReadStream so it can be used with Pump to pump data with flow control.

NOTE: This class has been automatically generated from the original non RX-ified interface using Vert.x codegen.
/** * Represents a server-side HTTP request. * <p> * Instances are created for each request and passed to the user via a handler. * <p> * Each instance of this class is associated with a corresponding {@link io.vertx.reactivex.core.http.HttpServerResponse} instance via * {@link io.vertx.reactivex.core.http.HttpServerRequest#response}.<p> * It implements {@link io.vertx.reactivex.core.streams.ReadStream} so it can be used with * {@link io.vertx.reactivex.core.streams.Pump} to pump data with flow control. * <p> * * <p/> * NOTE: This class has been automatically generated from the {@link io.vertx.core.http.HttpServerRequest original} non RX-ified interface using Vert.x codegen. */
@io.vertx.lang.rx.RxGen(io.vertx.core.http.HttpServerRequest.class) public class HttpServerRequest implements io.vertx.reactivex.core.streams.ReadStream<io.vertx.reactivex.core.buffer.Buffer> { @Override public String toString() { return delegate.toString(); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; HttpServerRequest that = (HttpServerRequest) o; return delegate.equals(that.delegate); } @Override public int hashCode() { return delegate.hashCode(); } public static final io.vertx.lang.rx.TypeArg<HttpServerRequest> __TYPE_ARG = new io.vertx.lang.rx.TypeArg<>( obj -> new HttpServerRequest((io.vertx.core.http.HttpServerRequest) obj), HttpServerRequest::getDelegate ); private final io.vertx.core.http.HttpServerRequest delegate; public HttpServerRequest(io.vertx.core.http.HttpServerRequest delegate) { this.delegate = delegate; } public io.vertx.core.http.HttpServerRequest getDelegate() { return delegate; } private io.reactivex.Observable<io.vertx.reactivex.core.buffer.Buffer> observable; private io.reactivex.Flowable<io.vertx.reactivex.core.buffer.Buffer> flowable; public synchronized io.reactivex.Observable<io.vertx.reactivex.core.buffer.Buffer> toObservable() { if (observable == null) { java.util.function.Function<io.vertx.core.buffer.Buffer, io.vertx.reactivex.core.buffer.Buffer> conv = io.vertx.reactivex.core.buffer.Buffer::newInstance; observable = io.vertx.reactivex.ObservableHelper.toObservable(delegate, conv); } return observable; } public synchronized io.reactivex.Flowable<io.vertx.reactivex.core.buffer.Buffer> toFlowable() { if (flowable == null) { java.util.function.Function<io.vertx.core.buffer.Buffer, io.vertx.reactivex.core.buffer.Buffer> conv = io.vertx.reactivex.core.buffer.Buffer::newInstance; flowable = io.vertx.reactivex.FlowableHelper.toFlowable(delegate, conv); } return flowable; }
Pause this stream and return a to transfer the elements of this stream to a destination .

The stream will be resumed when the pipe will be wired to a WriteStream.
Returns:a pipe
/** * Pause this stream and return a to transfer the elements of this stream to a destination . * <p/> * The stream will be resumed when the pipe will be wired to a <code>WriteStream</code>. * @return a pipe */
public io.vertx.reactivex.core.streams.Pipe<io.vertx.reactivex.core.buffer.Buffer> pipe() { io.vertx.reactivex.core.streams.Pipe<io.vertx.reactivex.core.buffer.Buffer> ret = io.vertx.reactivex.core.streams.Pipe.newInstance(delegate.pipe(), (io.vertx.lang.rx.TypeArg)io.vertx.reactivex.core.buffer.Buffer.__TYPE_ARG); return ret; }
Like ReadStream.pipeTo but with no completion handler.
Params:
  • dst –
/** * Like {@link io.vertx.reactivex.core.streams.ReadStream#pipeTo} but with no completion handler. * @param dst */
public void pipeTo(io.vertx.reactivex.core.streams.WriteStream<io.vertx.reactivex.core.buffer.Buffer> dst) { delegate.pipeTo(dst.getDelegate()); }
Pipe this ReadStream to the WriteStream.

Elements emitted by this stream will be written to the write stream until this stream ends or fails.

Once this stream has ended or failed, the write stream will be ended and the handler will be called with the result.

Params:
  • dst – the destination write stream
  • handler –
/** * Pipe this <code>ReadStream</code> to the <code>WriteStream</code>. * <p> * Elements emitted by this stream will be written to the write stream until this stream ends or fails. * <p> * Once this stream has ended or failed, the write stream will be ended and the <code>handler</code> will be * called with the result. * @param dst the destination write stream * @param handler */
public void pipeTo(io.vertx.reactivex.core.streams.WriteStream<io.vertx.reactivex.core.buffer.Buffer> dst, Handler<AsyncResult<Void>> handler) { delegate.pipeTo(dst.getDelegate(), handler); }
Pipe this ReadStream to the WriteStream.

Elements emitted by this stream will be written to the write stream until this stream ends or fails.

Once this stream has ended or failed, the write stream will be ended and the handler will be called with the result.

Params:
  • dst – the destination write stream
Returns:
/** * Pipe this <code>ReadStream</code> to the <code>WriteStream</code>. * <p> * Elements emitted by this stream will be written to the write stream until this stream ends or fails. * <p> * Once this stream has ended or failed, the write stream will be ended and the <code>handler</code> will be * called with the result. * @param dst the destination write stream * @return */
public Completable rxPipeTo(io.vertx.reactivex.core.streams.WriteStream<io.vertx.reactivex.core.buffer.Buffer> dst) { return io.vertx.reactivex.impl.AsyncResultCompletable.toCompletable(handler -> { pipeTo(dst, handler); }); } public io.vertx.reactivex.core.http.HttpServerRequest exceptionHandler(Handler<Throwable> handler) { delegate.exceptionHandler(handler); return this; } public io.vertx.reactivex.core.http.HttpServerRequest handler(Handler<io.vertx.reactivex.core.buffer.Buffer> handler) { delegate.handler(new Handler<io.vertx.core.buffer.Buffer>() { public void handle(io.vertx.core.buffer.Buffer event) { handler.handle(io.vertx.reactivex.core.buffer.Buffer.newInstance(event)); } }); return this; } public io.vertx.reactivex.core.http.HttpServerRequest pause() { delegate.pause(); return this; } public io.vertx.reactivex.core.http.HttpServerRequest resume() { delegate.resume(); return this; } public io.vertx.reactivex.core.http.HttpServerRequest fetch(long amount) { delegate.fetch(amount); return this; } public io.vertx.reactivex.core.http.HttpServerRequest endHandler(Handler<Void> endHandler) { delegate.endHandler(endHandler); return this; }
Returns:the HTTP version of the request
/** * @return the HTTP version of the request */
public HttpVersion version() { HttpVersion ret = delegate.version(); return ret; }
Returns:the HTTP method for the request.
/** * @return the HTTP method for the request. */
public HttpMethod method() { HttpMethod ret = delegate.method(); return ret; }
Returns:the HTTP method as sent by the client
/** * @return the HTTP method as sent by the client */
public String rawMethod() { String ret = delegate.rawMethod(); return ret; }
Returns:true if this NetSocket is encrypted via SSL/TLS
/** * @return true if this {@link io.vertx.reactivex.core.net.NetSocket} is encrypted via SSL/TLS */
public boolean isSSL() { boolean ret = delegate.isSSL(); return ret; }
Returns:the scheme of the request
/** * @return the scheme of the request */
public String scheme() { String ret = delegate.scheme(); return ret; }
Returns:the URI of the request. This is usually a relative URI
/** * @return the URI of the request. This is usually a relative URI */
public String uri() { String ret = delegate.uri(); return ret; }
Returns:The path part of the uri. For example /somepath/somemorepath/someresource.foo
/** * @return The path part of the uri. For example /somepath/somemorepath/someresource.foo */
public String path() { String ret = delegate.path(); return ret; }
Returns:the query part of the uri. For example someparam=32&someotherparam=x
/** * @return the query part of the uri. For example someparam=32&amp;someotherparam=x */
public String query() { String ret = delegate.query(); return ret; }
Returns:the request host. For HTTP2 it returns the pseudo header otherwise it returns the header
/** * @return the request host. For HTTP2 it returns the pseudo header otherwise it returns the header */
public String host() { String ret = delegate.host(); return ret; }
Returns:the total number of bytes read for the body of the request.
/** * @return the total number of bytes read for the body of the request. */
public long bytesRead() { long ret = delegate.bytesRead(); return ret; }
Returns:the response. Each instance of this class has an HttpServerResponse instance attached to it. This is used to send the response back to the client.
/** * @return the response. Each instance of this class has an {@link io.vertx.reactivex.core.http.HttpServerResponse} instance attached to it. This is used to send the response back to the client. */
public io.vertx.reactivex.core.http.HttpServerResponse response() { if (cached_0 != null) { return cached_0; } io.vertx.reactivex.core.http.HttpServerResponse ret = io.vertx.reactivex.core.http.HttpServerResponse.newInstance(delegate.response()); cached_0 = ret; return ret; }
Returns:the headers in the request.
/** * @return the headers in the request. */
public io.vertx.reactivex.core.MultiMap headers() { if (cached_1 != null) { return cached_1; } io.vertx.reactivex.core.MultiMap ret = io.vertx.reactivex.core.MultiMap.newInstance(delegate.headers()); cached_1 = ret; return ret; }
Return the first header value with the specified name
Params:
  • headerName – the header name
Returns:the header value
/** * Return the first header value with the specified name * @param headerName the header name * @return the header value */
public String getHeader(String headerName) { String ret = delegate.getHeader(headerName); return ret; }
Returns:the query parameters in the request
/** * @return the query parameters in the request */
public io.vertx.reactivex.core.MultiMap params() { if (cached_2 != null) { return cached_2; } io.vertx.reactivex.core.MultiMap ret = io.vertx.reactivex.core.MultiMap.newInstance(delegate.params()); cached_2 = ret; return ret; }
Return the first param value with the specified name
Params:
  • paramName – the param name
Returns:the param value
/** * Return the first param value with the specified name * @param paramName the param name * @return the param value */
public String getParam(String paramName) { String ret = delegate.getParam(paramName); return ret; }
Returns:the remote (client side) address of the request
/** * @return the remote (client side) address of the request */
public io.vertx.reactivex.core.net.SocketAddress remoteAddress() { if (cached_3 != null) { return cached_3; } io.vertx.reactivex.core.net.SocketAddress ret = io.vertx.reactivex.core.net.SocketAddress.newInstance(delegate.remoteAddress()); cached_3 = ret; return ret; }
Returns:the local (server side) address of the server that handles the request
/** * @return the local (server side) address of the server that handles the request */
public io.vertx.reactivex.core.net.SocketAddress localAddress() { if (cached_4 != null) { return cached_4; } io.vertx.reactivex.core.net.SocketAddress ret = io.vertx.reactivex.core.net.SocketAddress.newInstance(delegate.localAddress()); cached_4 = ret; return ret; }
Returns:the absolute URI corresponding to the the HTTP request
/** * @return the absolute URI corresponding to the the HTTP request */
public String absoluteURI() { String ret = delegate.absoluteURI(); return ret; }
Convenience method for receiving the entire request body in one piece.

This saves the user having to manually setting a data and end handler and append the chunks of the body until the whole body received. Don't use this if your request body is large - you could potentially run out of RAM.

Params:
  • bodyHandler – This handler will be called after all the body has been received
Returns:
/** * Convenience method for receiving the entire request body in one piece. * <p> * This saves the user having to manually setting a data and end handler and append the chunks of the body until * the whole body received. Don't use this if your request body is large - you could potentially run out of RAM. * @param bodyHandler This handler will be called after all the body has been received * @return */
public io.vertx.reactivex.core.http.HttpServerRequest bodyHandler(Handler<io.vertx.reactivex.core.buffer.Buffer> bodyHandler) { delegate.bodyHandler(new Handler<io.vertx.core.buffer.Buffer>() { public void handle(io.vertx.core.buffer.Buffer event) { bodyHandler.handle(io.vertx.reactivex.core.buffer.Buffer.newInstance(event)); } }); return this; }
Get a net socket for the underlying connection of this request.

This method must be called before the server response is ended.

With CONNECT requests, a 200 response is sent with no content-length header set before returning the socket.

server.requestHandler(req -> {
  if (req.method() == HttpMethod.CONNECT) {
    // Send a 200 response to accept the connect
    NetSocket socket = req.netSocket();
    socket.handler(buff -> {
      socket.write(buff);
    });
  }
  ...
});

For other HTTP/1 requests once you have called this method, you must handle writing to the connection yourself using the net socket, the server request instance will no longer be usable as normal. USE THIS WITH CAUTION! Writing to the socket directly if you don't know what you're doing can easily break the HTTP protocol.

With HTTP/2, a 200 response is always sent with no content-length header set before returning the socket like in the CONNECT case above.

Returns:the net socket
/** * Get a net socket for the underlying connection of this request. * <p/> * This method must be called before the server response is ended. * <p/> * With <code>CONNECT</code> requests, a <code>200</code> response is sent with no <code>content-length</code> header set * before returning the socket. * <p/> * <pre> * server.requestHandler(req -> { * if (req.method() == HttpMethod.CONNECT) { * // Send a 200 response to accept the connect * NetSocket socket = req.netSocket(); * socket.handler(buff -> { * socket.write(buff); * }); * } * ... * }); * </pre> * <p/> * For other HTTP/1 requests once you have called this method, you must handle writing to the connection yourself using * the net socket, the server request instance will no longer be usable as normal. USE THIS WITH CAUTION! Writing to the socket directly if you don't know what you're * doing can easily break the HTTP protocol. * <p/> * With HTTP/2, a <code>200</code> response is always sent with no <code>content-length</code> header set before returning the socket * like in the <code>CONNECT</code> case above. * <p/> * @return the net socket */
public io.vertx.reactivex.core.net.NetSocket netSocket() { if (cached_5 != null) { return cached_5; } io.vertx.reactivex.core.net.NetSocket ret = io.vertx.reactivex.core.net.NetSocket.newInstance(delegate.netSocket()); cached_5 = ret; return ret; }
Call this with true if you are expecting a multi-part body to be submitted in the request. This must be called before the body of the request has been received
Params:
  • expect – true - if you are expecting a multi-part body
Returns:a reference to this, so the API can be used fluently
/** * Call this with true if you are expecting a multi-part body to be submitted in the request. * This must be called before the body of the request has been received * @param expect true - if you are expecting a multi-part body * @return a reference to this, so the API can be used fluently */
public io.vertx.reactivex.core.http.HttpServerRequest setExpectMultipart(boolean expect) { delegate.setExpectMultipart(expect); return this; }
Returns:true if we are expecting a multi-part body for this request. See setExpectMultipart.
/** * @return true if we are expecting a multi-part body for this request. See {@link io.vertx.reactivex.core.http.HttpServerRequest#setExpectMultipart}. */
public boolean isExpectMultipart() { boolean ret = delegate.isExpectMultipart(); return ret; }
Set an upload handler. The handler will get notified once a new file upload was received to allow you to deal with the file upload.
Params:
  • uploadHandler –
Returns:a reference to this, so the API can be used fluently
/** * Set an upload handler. The handler will get notified once a new file upload was received to allow you to deal * with the file upload. * @param uploadHandler * @return a reference to this, so the API can be used fluently */
public io.vertx.reactivex.core.http.HttpServerRequest uploadHandler(Handler<io.vertx.reactivex.core.http.HttpServerFileUpload> uploadHandler) { delegate.uploadHandler(new Handler<io.vertx.core.http.HttpServerFileUpload>() { public void handle(io.vertx.core.http.HttpServerFileUpload event) { uploadHandler.handle(io.vertx.reactivex.core.http.HttpServerFileUpload.newInstance(event)); } }); return this; }
Returns a map of all form attributes in the request.

Be aware that the attributes will only be available after the whole body has been received, i.e. after the request end handler has been called.

setExpectMultipart must be called first before trying to get the form attributes.

Returns:the form attributes
/** * Returns a map of all form attributes in the request. * <p> * Be aware that the attributes will only be available after the whole body has been received, i.e. after * the request end handler has been called. * <p> * {@link io.vertx.reactivex.core.http.HttpServerRequest#setExpectMultipart} must be called first before trying to get the form attributes. * @return the form attributes */
public io.vertx.reactivex.core.MultiMap formAttributes() { if (cached_6 != null) { return cached_6; } io.vertx.reactivex.core.MultiMap ret = io.vertx.reactivex.core.MultiMap.newInstance(delegate.formAttributes()); cached_6 = ret; return ret; }
Return the first form attribute value with the specified name
Params:
  • attributeName – the attribute name
Returns:the attribute value
/** * Return the first form attribute value with the specified name * @param attributeName the attribute name * @return the attribute value */
public String getFormAttribute(String attributeName) { String ret = delegate.getFormAttribute(attributeName); return ret; }
Upgrade the connection to a WebSocket connection.

This is an alternative way of handling WebSockets and can only be used if no WebSocket handler is set on the HttpServer, and can only be used during the upgrade request during the WebSocket handshake.

Returns:the WebSocket
/** * Upgrade the connection to a WebSocket connection. * <p> * This is an alternative way of handling WebSockets and can only be used if no WebSocket handler is set on the * <code>HttpServer</code>, and can only be used during the upgrade request during the WebSocket handshake. * @return the WebSocket */
public io.vertx.reactivex.core.http.ServerWebSocket upgrade() { io.vertx.reactivex.core.http.ServerWebSocket ret = io.vertx.reactivex.core.http.ServerWebSocket.newInstance(delegate.upgrade()); return ret; }
Has the request ended? I.e. has the entire request, including the body been read?
Returns:true if ended
/** * Has the request ended? I.e. has the entire request, including the body been read? * @return true if ended */
public boolean isEnded() { boolean ret = delegate.isEnded(); return ret; }
Set a custom frame handler. The handler will get notified when the http stream receives an custom HTTP/2 frame. HTTP/2 permits extension of the protocol.
Params:
  • handler –
Returns:a reference to this, so the API can be used fluently
/** * Set a custom frame handler. The handler will get notified when the http stream receives an custom HTTP/2 * frame. HTTP/2 permits extension of the protocol. * @param handler * @return a reference to this, so the API can be used fluently */
public io.vertx.reactivex.core.http.HttpServerRequest customFrameHandler(Handler<io.vertx.reactivex.core.http.HttpFrame> handler) { delegate.customFrameHandler(new Handler<io.vertx.core.http.HttpFrame>() { public void handle(io.vertx.core.http.HttpFrame event) { handler.handle(io.vertx.reactivex.core.http.HttpFrame.newInstance(event)); } }); return this; }
Returns:the HttpConnection associated with this request
/** * @return the {@link io.vertx.reactivex.core.http.HttpConnection} associated with this request */
public io.vertx.reactivex.core.http.HttpConnection connection() { if (cached_7 != null) { return cached_7; } io.vertx.reactivex.core.http.HttpConnection ret = io.vertx.reactivex.core.http.HttpConnection.newInstance(delegate.connection()); cached_7 = ret; return ret; }
Returns:the priority of the associated HTTP/2 stream for HTTP/2 otherwise null
/** * @return the priority of the associated HTTP/2 stream for HTTP/2 otherwise <code>null</code> */
public StreamPriority streamPriority() { StreamPriority ret = delegate.streamPriority(); return ret; }
Set an handler for stream priority changes

This is not implemented for HTTP/1.x.

Params:
  • handler – the handler to be called when stream priority changes
Returns:
/** * Set an handler for stream priority changes * <p> * This is not implemented for HTTP/1.x. * @param handler the handler to be called when stream priority changes * @return */
public io.vertx.reactivex.core.http.HttpServerRequest streamPriorityHandler(Handler<StreamPriority> handler) { delegate.streamPriorityHandler(handler); return this; }
Return the first header value with the specified name
Params:
  • headerName – the header name
Returns:the header value
/** * Return the first header value with the specified name * @param headerName the header name * @return the header value */
public String getHeader(CharSequence headerName) { String ret = delegate.getHeader(headerName); return ret; }
Returns:SSLSession associated with the underlying socket. Returns null if connection is not SSL.
/** * @return SSLSession associated with the underlying socket. Returns null if connection is not SSL. */
public SSLSession sslSession() { SSLSession ret = delegate.sslSession(); return ret; } private io.vertx.reactivex.core.http.HttpServerResponse cached_0; private io.vertx.reactivex.core.MultiMap cached_1; private io.vertx.reactivex.core.MultiMap cached_2; private io.vertx.reactivex.core.net.SocketAddress cached_3; private io.vertx.reactivex.core.net.SocketAddress cached_4; private io.vertx.reactivex.core.net.NetSocket cached_5; private io.vertx.reactivex.core.MultiMap cached_6; private io.vertx.reactivex.core.http.HttpConnection cached_7; public static HttpServerRequest newInstance(io.vertx.core.http.HttpServerRequest arg) { return arg != null ? new HttpServerRequest(arg) : null; } }