All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.rxjava.core.http.HttpServerResponse Maven / Gradle / Ivy

There is a newer version: 5.0.0.CR2
Show newest version
/*
 * 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.rxjava.core.http;

import rx.Observable;
import rx.Single;
import io.vertx.rx.java.RxHelper;
import io.vertx.rx.java.WriteStreamSubscriber;
import io.vertx.rx.java.SingleOnSubscribeAdapter;
import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.Iterator;
import java.util.function.Function;
import java.util.stream.Collectors;
import io.vertx.core.Handler;
import io.vertx.core.AsyncResult;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.lang.rx.RxGen;
import io.vertx.lang.rx.TypeArg;
import io.vertx.lang.rx.MappingIterator;

/**
 * Represents a server-side HTTP response.
 * 

* An instance of this is created and associated to every instance of * {@link io.vertx.rxjava.core.http.HttpServerRequest} that. *

* It allows the developer to control the HTTP response that is sent back to the * client for a particular HTTP request. *

* It contains methods that allow HTTP headers and trailers to be set, and for a body to be written out to the response. *

* It also allows files to be streamed by the kernel directly from disk to the * outgoing HTTP connection, bypassing user space altogether (where supported by * the underlying operating system). This is a very efficient way of * serving files from the server since buffers do not have to be read one by one * from the file and written to the outgoing socket. *

* It implements {@link io.vertx.rxjava.core.streams.WriteStream} so it can be used with * {@link io.vertx.rxjava.core.streams.Pump} to pump data with flow control. * *

* NOTE: This class has been automatically generated from the {@link io.vertx.core.http.HttpServerResponse original} non RX-ified interface using Vert.x codegen. */ @RxGen(io.vertx.core.http.HttpServerResponse.class) public class HttpServerResponse implements io.vertx.rxjava.core.streams.WriteStream { @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; HttpServerResponse that = (HttpServerResponse) o; return delegate.equals(that.delegate); } @Override public int hashCode() { return delegate.hashCode(); } public static final TypeArg __TYPE_ARG = new TypeArg<>( obj -> new HttpServerResponse((io.vertx.core.http.HttpServerResponse) obj), HttpServerResponse::getDelegate ); private final io.vertx.core.http.HttpServerResponse delegate; public HttpServerResponse(io.vertx.core.http.HttpServerResponse delegate) { this.delegate = delegate; } public HttpServerResponse(Object delegate) { this.delegate = (io.vertx.core.http.HttpServerResponse)delegate; } public io.vertx.core.http.HttpServerResponse getDelegate() { return delegate; } private WriteStreamSubscriber subscriber; public synchronized WriteStreamSubscriber toSubscriber() { if (subscriber == null) { Function conv = io.vertx.rxjava.core.buffer.Buffer::getDelegate; subscriber = RxHelper.toSubscriber(getDelegate(), conv); } return subscriber; } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#end} but with an handler called when the operation completes * @param handler */ public void end(Handler> handler) { delegate.end(handler); } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#end} but with an handler called when the operation completes * @return * @deprecated use {@link #rxEnd} instead */ @Deprecated() public Observable endObservable() { io.vertx.rx.java.ObservableFuture handler = io.vertx.rx.java.RxHelper.observableFuture(); end(handler.toHandler()); return handler; } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#end} but with an handler called when the operation completes * @return */ public Single rxEnd() { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { end(fut); })); } /** * This will return true if there are more bytes in the write queue than the value set using {@link io.vertx.rxjava.core.http.HttpServerResponse#setWriteQueueMaxSize} * @return true if write queue is full */ public boolean writeQueueFull() { boolean ret = delegate.writeQueueFull(); return ret; } public io.vertx.rxjava.core.http.HttpServerResponse exceptionHandler(Handler handler) { delegate.exceptionHandler(handler); return this; } public io.vertx.rxjava.core.http.HttpServerResponse write(io.vertx.rxjava.core.buffer.Buffer data) { delegate.write(data.getDelegate()); return this; } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#write} but with an handler called when the operation completes * @param data * @param handler * @return */ public io.vertx.rxjava.core.http.HttpServerResponse write(io.vertx.rxjava.core.buffer.Buffer data, Handler> handler) { delegate.write(data.getDelegate(), handler); return this; } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#write} but with an handler called when the operation completes * @param data * @return * @deprecated use {@link #rxWrite} instead */ @Deprecated() public Observable writeObservable(io.vertx.rxjava.core.buffer.Buffer data) { io.vertx.rx.java.ObservableFuture handler = io.vertx.rx.java.RxHelper.observableFuture(); write(data, handler.toHandler()); return handler; } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#write} but with an handler called when the operation completes * @param data * @return */ public Single rxWrite(io.vertx.rxjava.core.buffer.Buffer data) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { write(data, fut); })); } public io.vertx.rxjava.core.http.HttpServerResponse setWriteQueueMaxSize(int maxSize) { delegate.setWriteQueueMaxSize(maxSize); return this; } public io.vertx.rxjava.core.http.HttpServerResponse drainHandler(Handler handler) { delegate.drainHandler(handler); return this; } /** * @return the HTTP status code of the response. The default is 200 representing OK. */ public int getStatusCode() { int ret = delegate.getStatusCode(); return ret; } /** * Set the status code. If the status message hasn't been explicitly set, a default status message corresponding * to the code will be looked-up and used. * @param statusCode * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpServerResponse setStatusCode(int statusCode) { delegate.setStatusCode(statusCode); return this; } /** * @return the HTTP status message of the response. If this is not specified a default value will be used depending on what {@link io.vertx.rxjava.core.http.HttpServerResponse#setStatusCode} has been set to. */ public String getStatusMessage() { String ret = delegate.getStatusMessage(); return ret; } /** * Set the status message * @param statusMessage * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpServerResponse setStatusMessage(String statusMessage) { delegate.setStatusMessage(statusMessage); return this; } /** * If chunked is true, this response will use HTTP chunked encoding, and each call to write to the body * will correspond to a new HTTP chunk sent on the wire. *

* If chunked encoding is used the HTTP header Transfer-Encoding with a value of Chunked will be * automatically inserted in the response. *

* If chunked is false, this response will not use HTTP chunked encoding, and therefore the total size * of any data that is written in the respone body must be set in the Content-Length header before any * data is written out. *

* An HTTP chunked response is typically used when you do not know the total size of the request body up front. * @param chunked * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpServerResponse setChunked(boolean chunked) { delegate.setChunked(chunked); return this; } /** * @return is the response chunked? */ public boolean isChunked() { boolean ret = delegate.isChunked(); return ret; } /** * @return The HTTP headers */ public io.vertx.rxjava.core.MultiMap headers() { if (cached_0 != null) { return cached_0; } io.vertx.rxjava.core.MultiMap ret = io.vertx.rxjava.core.MultiMap.newInstance((io.vertx.core.MultiMap)delegate.headers()); cached_0 = ret; return ret; } /** * Put an HTTP header * @param name the header name * @param value the header value. * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpServerResponse putHeader(String name, String value) { delegate.putHeader(name, value); return this; } /** * @return The HTTP trailers */ public io.vertx.rxjava.core.MultiMap trailers() { if (cached_1 != null) { return cached_1; } io.vertx.rxjava.core.MultiMap ret = io.vertx.rxjava.core.MultiMap.newInstance((io.vertx.core.MultiMap)delegate.trailers()); cached_1 = ret; return ret; } /** * Put an HTTP trailer * @param name the trailer name * @param value the trailer value * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpServerResponse putTrailer(String name, String value) { delegate.putTrailer(name, value); return this; } /** * Set a close handler for the response, this is called when the underlying connection is closed and the response * was still using the connection. *

* For HTTP/1.x it is called when the connection is closed before end() is called, therefore it is not * guaranteed to be called. *

* For HTTP/2 it is called when the related stream is closed, and therefore it will be always be called. * @param handler the handler * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpServerResponse closeHandler(Handler handler) { delegate.closeHandler(handler); return this; } /** * Set an end handler for the response. This will be called when the response is disposed to allow consistent cleanup * of the response. * @param handler the handler * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpServerResponse endHandler(Handler handler) { delegate.endHandler(handler); return this; } /** * Write a {@link java.lang.String} to the response body, encoded using the encoding enc. * @param chunk the string to write * @param enc the encoding to use * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpServerResponse write(String chunk, String enc) { delegate.write(chunk, enc); return this; } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#write} but with an handler called when the operation completes * @param chunk * @param enc * @param handler * @return */ public io.vertx.rxjava.core.http.HttpServerResponse write(String chunk, String enc, Handler> handler) { delegate.write(chunk, enc, handler); return this; } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#write} but with an handler called when the operation completes * @param chunk * @param enc * @return * @deprecated use {@link #rxWrite} instead */ @Deprecated() public Observable writeObservable(String chunk, String enc) { io.vertx.rx.java.ObservableFuture handler = io.vertx.rx.java.RxHelper.observableFuture(); write(chunk, enc, handler.toHandler()); return handler; } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#write} but with an handler called when the operation completes * @param chunk * @param enc * @return */ public Single rxWrite(String chunk, String enc) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { write(chunk, enc, fut); })); } /** * Write a {@link java.lang.String} to the response body, encoded in UTF-8. * @param chunk the string to write * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpServerResponse write(String chunk) { delegate.write(chunk); return this; } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#write} but with an handler called when the operation completes * @param chunk * @param handler * @return */ public io.vertx.rxjava.core.http.HttpServerResponse write(String chunk, Handler> handler) { delegate.write(chunk, handler); return this; } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#write} but with an handler called when the operation completes * @param chunk * @return * @deprecated use {@link #rxWrite} instead */ @Deprecated() public Observable writeObservable(String chunk) { io.vertx.rx.java.ObservableFuture handler = io.vertx.rx.java.RxHelper.observableFuture(); write(chunk, handler.toHandler()); return handler; } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#write} but with an handler called when the operation completes * @param chunk * @return */ public Single rxWrite(String chunk) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { write(chunk, fut); })); } /** * Used to write an interim 100 Continue response to signify that the client should send the rest of the request. * Must only be used if the request contains an "Expect:100-Continue" header * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpServerResponse writeContinue() { delegate.writeContinue(); return this; } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#end} but writes a String in UTF-8 encoding before ending the response. * @param chunk the string to write before ending the response */ public void end(String chunk) { delegate.end(chunk); } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#end} but with an handler called when the operation completes * @param chunk * @param handler */ public void end(String chunk, Handler> handler) { delegate.end(chunk, handler); } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#end} but with an handler called when the operation completes * @param chunk * @return * @deprecated use {@link #rxEnd} instead */ @Deprecated() public Observable endObservable(String chunk) { io.vertx.rx.java.ObservableFuture handler = io.vertx.rx.java.RxHelper.observableFuture(); end(chunk, handler.toHandler()); return handler; } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#end} but with an handler called when the operation completes * @param chunk * @return */ public Single rxEnd(String chunk) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { end(chunk, fut); })); } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#end} but writes a String with the specified encoding before ending the response. * @param chunk the string to write before ending the response * @param enc the encoding to use */ public void end(String chunk, String enc) { delegate.end(chunk, enc); } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#end} but with an handler called when the operation completes * @param chunk * @param enc * @param handler */ public void end(String chunk, String enc, Handler> handler) { delegate.end(chunk, enc, handler); } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#end} but with an handler called when the operation completes * @param chunk * @param enc * @return * @deprecated use {@link #rxEnd} instead */ @Deprecated() public Observable endObservable(String chunk, String enc) { io.vertx.rx.java.ObservableFuture handler = io.vertx.rx.java.RxHelper.observableFuture(); end(chunk, enc, handler.toHandler()); return handler; } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#end} but with an handler called when the operation completes * @param chunk * @param enc * @return */ public Single rxEnd(String chunk, String enc) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { end(chunk, enc, fut); })); } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#end} but writes some data to the response body before ending. If the response is not chunked and * no other data has been written then the @code{Content-Length} header will be automatically set. * @param chunk the buffer to write before ending the response */ public void end(io.vertx.rxjava.core.buffer.Buffer chunk) { delegate.end(chunk.getDelegate()); } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#end} but with an handler called when the operation completes * @param chunk * @param handler */ public void end(io.vertx.rxjava.core.buffer.Buffer chunk, Handler> handler) { delegate.end(chunk.getDelegate(), handler); } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#end} but with an handler called when the operation completes * @param chunk * @return * @deprecated use {@link #rxEnd} instead */ @Deprecated() public Observable endObservable(io.vertx.rxjava.core.buffer.Buffer chunk) { io.vertx.rx.java.ObservableFuture handler = io.vertx.rx.java.RxHelper.observableFuture(); end(chunk, handler.toHandler()); return handler; } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#end} but with an handler called when the operation completes * @param chunk * @return */ public Single rxEnd(io.vertx.rxjava.core.buffer.Buffer chunk) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { end(chunk, fut); })); } /** * Ends the response. If no data has been written to the response body, * the actual response won't get written until this method gets called. *

* Once the response has ended, it cannot be used any more. */ public void end() { delegate.end(); } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#sendFile} using offset @code{0} which means starting from the beginning of the file. * @param filename path to the file to serve * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpServerResponse sendFile(String filename) { delegate.sendFile(filename); return this; } /** * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#sendFile} using length @code{Long.MAX_VALUE} which means until the end of the * file. * @param filename path to the file to serve * @param offset offset to start serving from * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpServerResponse sendFile(String filename, long offset) { delegate.sendFile(filename, offset); return this; } /** * Ask the OS to stream a file as specified by filename directly * from disk to the outgoing connection, bypassing userspace altogether * (where supported by the underlying operating system. * This is a very efficient way to serve files.

* The actual serve is asynchronous and may not complete until some time after this method has returned. * @param filename path to the file to serve * @param offset offset to start serving from * @param length the number of bytes to send * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpServerResponse sendFile(String filename, long offset, long length) { delegate.sendFile(filename, offset, length); return this; } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#sendFile} but providing a handler which will be notified once the file has been completely * written to the wire. * @param filename path to the file to serve * @param resultHandler handler that will be called on completion * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpServerResponse sendFile(String filename, Handler> resultHandler) { delegate.sendFile(filename, resultHandler); return this; } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#sendFile} but providing a handler which will be notified once the file has been completely * written to the wire. * @param filename path to the file to serve * @return a reference to this, so the API can be used fluently * @deprecated use {@link #rxSendFile} instead */ @Deprecated() public Observable sendFileObservable(String filename) { io.vertx.rx.java.ObservableFuture resultHandler = io.vertx.rx.java.RxHelper.observableFuture(); sendFile(filename, resultHandler.toHandler()); return resultHandler; } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#sendFile} but providing a handler which will be notified once the file has been completely * written to the wire. * @param filename path to the file to serve * @return a reference to this, so the API can be used fluently */ public Single rxSendFile(String filename) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { sendFile(filename, fut); })); } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#sendFile} but providing a handler which will be notified once the file has been completely * written to the wire. * @param filename path to the file to serve * @param offset the offset to serve from * @param resultHandler handler that will be called on completion * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpServerResponse sendFile(String filename, long offset, Handler> resultHandler) { delegate.sendFile(filename, offset, resultHandler); return this; } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#sendFile} but providing a handler which will be notified once the file has been completely * written to the wire. * @param filename path to the file to serve * @param offset the offset to serve from * @return a reference to this, so the API can be used fluently * @deprecated use {@link #rxSendFile} instead */ @Deprecated() public Observable sendFileObservable(String filename, long offset) { io.vertx.rx.java.ObservableFuture resultHandler = io.vertx.rx.java.RxHelper.observableFuture(); sendFile(filename, offset, resultHandler.toHandler()); return resultHandler; } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#sendFile} but providing a handler which will be notified once the file has been completely * written to the wire. * @param filename path to the file to serve * @param offset the offset to serve from * @return a reference to this, so the API can be used fluently */ public Single rxSendFile(String filename, long offset) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { sendFile(filename, offset, fut); })); } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#sendFile} but providing a handler which will be notified once the file has been * completely written to the wire. * @param filename path to the file to serve * @param offset the offset to serve from * @param length the length to serve to * @param resultHandler handler that will be called on completion * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpServerResponse sendFile(String filename, long offset, long length, Handler> resultHandler) { delegate.sendFile(filename, offset, length, resultHandler); return this; } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#sendFile} but providing a handler which will be notified once the file has been * completely written to the wire. * @param filename path to the file to serve * @param offset the offset to serve from * @param length the length to serve to * @return a reference to this, so the API can be used fluently * @deprecated use {@link #rxSendFile} instead */ @Deprecated() public Observable sendFileObservable(String filename, long offset, long length) { io.vertx.rx.java.ObservableFuture resultHandler = io.vertx.rx.java.RxHelper.observableFuture(); sendFile(filename, offset, length, resultHandler.toHandler()); return resultHandler; } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#sendFile} but providing a handler which will be notified once the file has been * completely written to the wire. * @param filename path to the file to serve * @param offset the offset to serve from * @param length the length to serve to * @return a reference to this, so the API can be used fluently */ public Single rxSendFile(String filename, long offset, long length) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { sendFile(filename, offset, length, fut); })); } /** * Close the underlying TCP connection corresponding to the request. */ public void close() { delegate.close(); } /** * @return has the response already ended? */ public boolean ended() { boolean ret = delegate.ended(); return ret; } /** * @return has the underlying TCP connection corresponding to the request already been closed? */ public boolean closed() { boolean ret = delegate.closed(); return ret; } /** * @return have the headers for the response already been written? */ public boolean headWritten() { boolean ret = delegate.headWritten(); return ret; } /** * Provide a handler that will be called just before the headers are written to the wire.

* This provides a hook allowing you to add any more headers or do any more operations before this occurs. * @param handler the handler * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpServerResponse headersEndHandler(Handler handler) { delegate.headersEndHandler(handler); return this; } /** * Provides a handler that will be called after the last part of the body is written to the wire. * The handler is called asynchronously of when the response has been received by the client. * This provides a hook allowing you to do more operations once the request has been sent over the wire * such as resource cleanup. * @param handler the handler * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpServerResponse bodyEndHandler(Handler handler) { delegate.bodyEndHandler(handler); return this; } /** * @return the total number of bytes written for the body of the response. */ public long bytesWritten() { long ret = delegate.bytesWritten(); return ret; } /** * @return the id of the stream of this response, for HTTP/1.x */ public int streamId() { int ret = delegate.streamId(); return ret; } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#push} with no headers. * @param method * @param host * @param path * @param handler * @return */ public io.vertx.rxjava.core.http.HttpServerResponse push(io.vertx.core.http.HttpMethod method, String host, String path, Handler> handler) { delegate.push(method, host, path, new Handler>() { public void handle(AsyncResult ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.http.HttpServerResponse.newInstance((io.vertx.core.http.HttpServerResponse)ar.result()))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#push} with no headers. * @param method * @param host * @param path * @return * @deprecated use {@link #rxPush} instead */ @Deprecated() public Observable pushObservable(io.vertx.core.http.HttpMethod method, String host, String path) { io.vertx.rx.java.ObservableFuture handler = io.vertx.rx.java.RxHelper.observableFuture(); push(method, host, path, handler.toHandler()); return handler; } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#push} with no headers. * @param method * @param host * @param path * @return */ public Single rxPush(io.vertx.core.http.HttpMethod method, String host, String path) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { push(method, host, path, fut); })); } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#push} with the host copied from the current request. * @param method * @param path * @param headers * @param handler * @return */ public io.vertx.rxjava.core.http.HttpServerResponse push(io.vertx.core.http.HttpMethod method, String path, io.vertx.rxjava.core.MultiMap headers, Handler> handler) { delegate.push(method, path, headers.getDelegate(), new Handler>() { public void handle(AsyncResult ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.http.HttpServerResponse.newInstance((io.vertx.core.http.HttpServerResponse)ar.result()))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#push} with the host copied from the current request. * @param method * @param path * @param headers * @return * @deprecated use {@link #rxPush} instead */ @Deprecated() public Observable pushObservable(io.vertx.core.http.HttpMethod method, String path, io.vertx.rxjava.core.MultiMap headers) { io.vertx.rx.java.ObservableFuture handler = io.vertx.rx.java.RxHelper.observableFuture(); push(method, path, headers, handler.toHandler()); return handler; } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#push} with the host copied from the current request. * @param method * @param path * @param headers * @return */ public Single rxPush(io.vertx.core.http.HttpMethod method, String path, io.vertx.rxjava.core.MultiMap headers) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { push(method, path, headers, fut); })); } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#push} with the host copied from the current request. * @param method * @param path * @param handler * @return */ public io.vertx.rxjava.core.http.HttpServerResponse push(io.vertx.core.http.HttpMethod method, String path, Handler> handler) { delegate.push(method, path, new Handler>() { public void handle(AsyncResult ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.http.HttpServerResponse.newInstance((io.vertx.core.http.HttpServerResponse)ar.result()))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#push} with the host copied from the current request. * @param method * @param path * @return * @deprecated use {@link #rxPush} instead */ @Deprecated() public Observable pushObservable(io.vertx.core.http.HttpMethod method, String path) { io.vertx.rx.java.ObservableFuture handler = io.vertx.rx.java.RxHelper.observableFuture(); push(method, path, handler.toHandler()); return handler; } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#push} with the host copied from the current request. * @param method * @param path * @return */ public Single rxPush(io.vertx.core.http.HttpMethod method, String path) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { push(method, path, fut); })); } /** * Push a response to the client.

* * The handler will be notified with a success when the push can be sent and with * a failure when the client has disabled push or reset the push before it has been sent.

* * The handler may be queued if the client has reduced the maximum number of streams the server can push * concurrently.

* * Push can be sent only for peer initiated streams and if the response is not ended. * @param method the method of the promised request * @param host the host of the promised request * @param path the path of the promised request * @param headers the headers of the promised request * @param handler the handler notified when the response can be written * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpServerResponse push(io.vertx.core.http.HttpMethod method, String host, String path, io.vertx.rxjava.core.MultiMap headers, Handler> handler) { delegate.push(method, host, path, headers.getDelegate(), new Handler>() { public void handle(AsyncResult ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.http.HttpServerResponse.newInstance((io.vertx.core.http.HttpServerResponse)ar.result()))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; } /** * Push a response to the client.

* * The handler will be notified with a success when the push can be sent and with * a failure when the client has disabled push or reset the push before it has been sent.

* * The handler may be queued if the client has reduced the maximum number of streams the server can push * concurrently.

* * Push can be sent only for peer initiated streams and if the response is not ended. * @param method the method of the promised request * @param host the host of the promised request * @param path the path of the promised request * @param headers the headers of the promised request * @return a reference to this, so the API can be used fluently * @deprecated use {@link #rxPush} instead */ @Deprecated() public Observable pushObservable(io.vertx.core.http.HttpMethod method, String host, String path, io.vertx.rxjava.core.MultiMap headers) { io.vertx.rx.java.ObservableFuture handler = io.vertx.rx.java.RxHelper.observableFuture(); push(method, host, path, headers, handler.toHandler()); return handler; } /** * Push a response to the client.

* * The handler will be notified with a success when the push can be sent and with * a failure when the client has disabled push or reset the push before it has been sent.

* * The handler may be queued if the client has reduced the maximum number of streams the server can push * concurrently.

* * Push can be sent only for peer initiated streams and if the response is not ended. * @param method the method of the promised request * @param host the host of the promised request * @param path the path of the promised request * @param headers the headers of the promised request * @return a reference to this, so the API can be used fluently */ public Single rxPush(io.vertx.core.http.HttpMethod method, String host, String path, io.vertx.rxjava.core.MultiMap headers) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { push(method, host, path, headers, fut); })); } /** * Reset this HTTP/2 stream with the error code 0. */ public void reset() { delegate.reset(); } /** * Reset this HTTP/2 stream with the error code. * @param code the error code */ public void reset(long code) { delegate.reset(code); } /** * Write an HTTP/2 frame to the response, allowing to extend the HTTP/2 protocol.

* * The frame is sent immediatly and is not subject to flow control. * @param type the 8-bit frame type * @param flags the 8-bit frame flags * @param payload the frame payload * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpServerResponse writeCustomFrame(int type, int flags, io.vertx.rxjava.core.buffer.Buffer payload) { delegate.writeCustomFrame(type, flags, payload.getDelegate()); return this; } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#writeCustomFrame} but with an {@link io.vertx.rxjava.core.http.HttpFrame}. * @param frame the frame to write * @return */ public io.vertx.rxjava.core.http.HttpServerResponse writeCustomFrame(io.vertx.rxjava.core.http.HttpFrame frame) { delegate.writeCustomFrame(frame.getDelegate()); return this; } /** * Sets the priority of the associated stream *

* This is not implemented for HTTP/1.x. * @param streamPriority the priority for this request's stream * @return */ public io.vertx.rxjava.core.http.HttpServerResponse setStreamPriority(io.vertx.core.http.StreamPriority streamPriority) { delegate.setStreamPriority(streamPriority); return this; } /** * Add a cookie. This will be sent back to the client in the response. * @param cookie the cookie * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpServerResponse addCookie(io.vertx.rxjava.core.http.Cookie cookie) { delegate.addCookie(cookie.getDelegate()); return this; } /** * Expire a cookie, notifying a User Agent to remove it from its cookie jar. * @param name the name of the cookie * @return the cookie, if it existed, or null */ public io.vertx.rxjava.core.http.Cookie removeCookie(String name) { io.vertx.rxjava.core.http.Cookie ret = io.vertx.rxjava.core.http.Cookie.newInstance((io.vertx.core.http.Cookie)delegate.removeCookie(name)); return ret; } /** * Remove a cookie from the cookie set. If invalidate is true then it will expire a cookie, notifying a User Agent to * remove it from its cookie jar. * @param name the name of the cookie * @param invalidate * @return the cookie, if it existed, or null */ public io.vertx.rxjava.core.http.Cookie removeCookie(String name, boolean invalidate) { io.vertx.rxjava.core.http.Cookie ret = io.vertx.rxjava.core.http.Cookie.newInstance((io.vertx.core.http.Cookie)delegate.removeCookie(name, invalidate)); return ret; } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#putHeader} but using CharSequence * @param name * @param value * @return */ public io.vertx.rxjava.core.http.HttpServerResponse putHeader(java.lang.CharSequence name, java.lang.CharSequence value) { delegate.putHeader(name, value); return this; } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#putHeader} but providing multiple values via a String Iterable * @param name * @param values * @return */ public io.vertx.rxjava.core.http.HttpServerResponse putHeader(String name, java.lang.Iterable values) { delegate.putHeader(name, values); return this; } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#putHeader} but with CharSequence Iterable * @param name * @param values * @return */ public io.vertx.rxjava.core.http.HttpServerResponse putHeader(java.lang.CharSequence name, java.lang.Iterable values) { delegate.putHeader(name, values); return this; } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#putTrailer} but using CharSequence * @param name * @param value * @return */ public io.vertx.rxjava.core.http.HttpServerResponse putTrailer(java.lang.CharSequence name, java.lang.CharSequence value) { delegate.putTrailer(name, value); return this; } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#putTrailer} but providing multiple values via a String Iterable * @param name * @param values * @return */ public io.vertx.rxjava.core.http.HttpServerResponse putTrailer(String name, java.lang.Iterable values) { delegate.putTrailer(name, values); return this; } /** * Like {@link io.vertx.rxjava.core.http.HttpServerResponse#putTrailer} but with CharSequence Iterable * @param name * @param value * @return */ public io.vertx.rxjava.core.http.HttpServerResponse putTrailer(java.lang.CharSequence name, java.lang.Iterable value) { delegate.putTrailer(name, value); return this; } private io.vertx.rxjava.core.MultiMap cached_0; private io.vertx.rxjava.core.MultiMap cached_1; public static HttpServerResponse newInstance(io.vertx.core.http.HttpServerResponse arg) { return arg != null ? new HttpServerResponse(arg) : null; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy