Top Description Fields Constructors Methods
io.vertx.core.http.impl

public Class Http1xServerResponse

extends Object
implements HttpServerResponse, HttpResponse
Class Inheritance
All Implemented Interfaces
io.vertx.core.spi.observability.HttpResponse, io.vertx.core.http.HttpServerResponse, io.vertx.core.streams.WriteStream, io.vertx.core.streams.StreamBase
Imports
io.netty.buffer.ByteBuf, .Unpooled, io.netty.channel.ChannelFuture, .ChannelPromise, io.netty.handler.codec.http.DefaultHttpContent, .EmptyHttpHeaders, .HttpObject, .HttpRequest, .HttpResponseStatus, .HttpVersion, .LastHttpContent, io.netty.util.internal.ObjectUtil, io.vertx.codegen.annotations.Nullable, io.vertx.core.AsyncResult, .Future, .Handler, .MultiMap, .Promise, io.vertx.core.buffer.Buffer, io.vertx.core.http.Cookie, .HttpClosedException, .HttpHeaders, .HttpMethod, .HttpServerResponse, io.vertx.core.http.impl.headers.HeadersMultiMap, io.vertx.core.impl.ContextInternal, .VertxInternal, io.vertx.core.impl.future.PromiseInternal, io.vertx.core.impl.logging.Logger, .LoggerFactory, io.vertx.core.net.HostAndPort, .NetSocket, io.vertx.core.spi.metrics.Metrics, io.vertx.core.spi.observability.HttpResponse, java.io.File, .FileNotFoundException, .IOException, .RandomAccessFile, java.util.Set

This class is optimised for performance when used on the same event loop that is was passed to the handler with. However it can be used safely from other threads. The internal state is protected using the synchronized keyword. If always used on the same event loop, then we benefit from biased locking which makes the overhead of synchronized near zero. It's important we don't have different locks for connection and request/response to avoid deadlock conditions
Author
Tim Fox

Field Summary

Modifier and TypeField and Description
private Handler<Void>
private long
private boolean
private Handler<Void>
private final Http1xServerConnection
private final ContextInternal
private CookieJar
private Handler<Void>
private static final Buffer
EMPTY_BUFFER

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.
private Handler<Void>
private Handler<Throwable>
private final boolean
private final HeadersMultiMap
private Handler<Void>
private boolean
private final boolean
private static final Logger
private Future<NetSocket>
private final HttpRequest
private final Object
private static final String
private HttpResponseStatus
private String
private MultiMap
private HttpHeaders
private final HttpVersion
private final VertxInternal
private boolean
private boolean

Constructor Summary

AccessConstructor and Description
pack-priv
Http1xServerResponse(VertxInternal vertx, ContextInternal context, Http1xServerConnection conn, HttpRequest request, Object requestMetric, boolean writable, boolean keepAlive)

Method Summary

Modifier and TypeMethod and Description
public HttpServerResponse
addCookie(Cookie
the cookie
cookie
)

Implements io.vertx.core.http.HttpServerResponse.addCookie.

Add a cookie.

public HttpServerResponse
public long
private void
private void
public void
close()

Implements io.vertx.core.http.HttpServerResponse.close.

Close the underlying TCP connection corresponding to the request.

private void
public boolean
public HttpServerResponse
pack-priv void
pack-priv CookieJar
private void
doSendFile(String filename, long offset, long length, Handler<AsyncResult<Void>> resultHandler)

public HttpServerResponse
public Future<Void>
end(String
the string to write before ending the response
chunk
)

Implements io.vertx.core.http.HttpServerResponse.end.

Same as end(Buffer) but writes a String in UTF-8 encoding before ending the response.

public void
end(String chunk, Handler<AsyncResult<Void>> handler)

Implements io.vertx.core.http.HttpServerResponse.end.

Same as end(String) but with an handler called when the operation completes

public Future<Void>
end(String
the string to write before ending the response
chunk
,
String
the encoding to use
enc
)

Implements io.vertx.core.http.HttpServerResponse.end.

Same as end(Buffer) but writes a String with the specified encoding before ending the response.

public void
end(String chunk, String enc, Handler<AsyncResult<Void>> handler)

Implements io.vertx.core.http.HttpServerResponse.end.

Same as end(String, String) but with an handler called when the operation completes

public Future<Void>
end(Buffer
the buffer to write before ending the response
chunk
)

Implements io.vertx.core.http.HttpServerResponse.end.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Same as end() but writes some data to the response body before ending.

public void
end(Buffer chunk, Handler<AsyncResult<Void>> handler)

Implements io.vertx.core.http.HttpServerResponse.end.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Same as end(Buffer) but with an handler called when the operation completes

private void
end(Buffer chunk, PromiseInternal<Void> listener)
References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

public Future<Void>
end()

Implements io.vertx.core.http.HttpServerResponse.end.

Ends the response.

public void
end(Handler<AsyncResult<Void>> handler)

Overrides default io.vertx.core.streams.WriteStream.end.

Implements io.vertx.core.streams.WriteStream.end.

Same as end() but with an handler called when the operation completes

public boolean
public HttpServerResponse
public HttpServerResponse
public int
public String
private void
pack-priv void
pack-priv void
handleWritabilityChanged(boolean writable)

public MultiMap
public HttpServerResponse
public boolean
public boolean
pack-priv Future<NetSocket>
netSocket(HttpMethod requestMethod, MultiMap requestHeaders)

private void
prepareHeaders(long contentLength)

public Future<HttpServerResponse>
push(HttpMethod method, HostAndPort authority, String path, MultiMap headers)

Implements io.vertx.core.http.HttpServerResponse.push.

Same as push(HttpMethod, String, String, MultiMap, Handler) but with an handler called when the operation completes

public Future<HttpServerResponse>
push(HttpMethod
the method of the promised request
method
,
String
the host of the promised request
host
,
String
the path of the promised request
path
,
MultiMap
the headers of the promised request
headers
)

Implements io.vertx.core.http.HttpServerResponse.push.

Push a response to the client.

public Http1xServerResponse
putHeader(String
the header name
key
,
String
the header value.
value
)

Implements io.vertx.core.http.HttpServerResponse.putHeader.

Put an HTTP header

public Http1xServerResponse
putHeader(String key, Iterable<String> values)

Implements io.vertx.core.http.HttpServerResponse.putHeader.

Like putHeader(String, String) but providing multiple values via a String Iterable

public HttpServerResponse
public HttpServerResponse
public Http1xServerResponse
putTrailer(String
the trailer name
key
,
String
the trailer value
value
)

Implements io.vertx.core.http.HttpServerResponse.putTrailer.

Put an HTTP trailer

public Http1xServerResponse
putTrailer(String key, Iterable<String> values)

Implements io.vertx.core.http.HttpServerResponse.putTrailer.

Like putTrailer(String, String) but providing multiple values via a String Iterable

public HttpServerResponse
public HttpServerResponse
public @Nullable Cookie
removeCookie(String
the name of the cookie
name
,
boolean invalidate)

Implements io.vertx.core.http.HttpServerResponse.removeCookie.

Remove a cookie from the cookie set.

public @Nullable Cookie
removeCookie(String
the name of the cookie
name
,
String
the domain of the cookie
domain
,
String
the path of the cookie
path
,
boolean invalidate)

Implements io.vertx.core.http.HttpServerResponse.removeCookie.

Remove a cookie from the cookie set.

public @Nullable Set<Cookie>
removeCookies(String
the name of the cookie
name
,
boolean
invalidate from the user agent
invalidate
)

Implements io.vertx.core.http.HttpServerResponse.removeCookies.

Remove all cookies from the cookie set.

private void
public boolean
reset(long
the error code
code
)

Implements io.vertx.core.http.HttpServerResponse.reset.

Reset this response:

  • for HTTP/2, send an HTTP/2 reset frame with the specified error code
  • for HTTP/1.x, close the connection when the current response has not yet been sent
public Future<Void>
sendFile(String
path to the file to serve
filename
,
long
offset to start serving from
offset
,
long
the number of bytes to send
length
)

Implements io.vertx.core.http.HttpServerResponse.sendFile.

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.

public HttpServerResponse
sendFile(String
path to the file to serve
filename
,
long
the offset to serve from
start
,
long
length the number of bytes to send
end
,
Handler<AsyncResult<Void>>
handler that will be called on completion
resultHandler
)

Implements io.vertx.core.http.HttpServerResponse.sendFile.

Like sendFile(String, long, long) but providing a handler which will be notified once the file has been completely written to the wire.

public Http1xServerResponse
setChunked(boolean chunked)

Implements io.vertx.core.http.HttpServerResponse.setChunked.

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.

private void
public HttpServerResponse
setStatusCode(int statusCode)

Implements io.vertx.core.http.HttpServerResponse.setStatusCode.

Set the status code.

public HttpServerResponse
setStatusMessage(String statusMessage)

Implements io.vertx.core.http.HttpServerResponse.setStatusMessage.

Set the status message

public HttpServerResponse
setWriteQueueMaxSize(int
the max size of the write stream
size
)

Implements io.vertx.core.http.HttpServerResponse.setWriteQueueMaxSize.

Set the maximum size of the write queue to maxSize.

public int
public int
public MultiMap
public Future<Void>
write(Buffer
the data to write
chunk
)

Implements io.vertx.core.streams.WriteStream.write.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Write some data to the stream.

public void
write(Buffer chunk, Handler<AsyncResult<Void>> handler)

Implements io.vertx.core.streams.WriteStream.write.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Same as write(T) but with an handler called when the operation completes

public Future<Void>
write(String
the string to write
chunk
,
String
the encoding to use
enc
)

Implements io.vertx.core.http.HttpServerResponse.write.

Write a String to the response body, encoded using the encoding enc.

public void
write(String chunk, String enc, Handler<AsyncResult<Void>> handler)

Implements io.vertx.core.http.HttpServerResponse.write.

Same as write(String, String) but with an handler called when the operation completes

public Future<Void>
write(String
the string to write
chunk
)

Implements io.vertx.core.http.HttpServerResponse.write.

Write a String to the response body, encoded in UTF-8.

public void
write(String chunk, Handler<AsyncResult<Void>> handler)

Implements io.vertx.core.http.HttpServerResponse.write.

Same as write(String) but with an handler called when the operation completes

private Http1xServerResponse
write(ByteBuf chunk, PromiseInternal<Void> promise)

public HttpServerResponse
writeContinue()

Implements io.vertx.core.http.HttpServerResponse.writeContinue.

Used to write an interim 100 Continue response to signify that the client should send the rest of the request.

public HttpServerResponse
writeCustomFrame(int
the 8-bit frame type
type
,
int
the 8-bit frame flags
flags
,
Buffer
the frame payload
payload
)

Implements io.vertx.core.http.HttpServerResponse.writeCustomFrame.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Write an HTTP/2 frame to the response, allowing to extend the HTTP/2 protocol.

public Future<Void>
writeEarlyHints(MultiMap
headers to write
headers
)

Implements io.vertx.core.http.HttpServerResponse.writeEarlyHints.

Used to write an interim 103 Early Hints response to return some HTTP headers before the final HTTP message.

public void
writeEarlyHints(MultiMap
headers to write
headers
,
Handler<AsyncResult<Void>> handler)

Implements io.vertx.core.http.HttpServerResponse.writeEarlyHints.

Same as writeEarlyHints(MultiMap) but with an handler called when the operation completes

public boolean
writeQueueFull()

Implements io.vertx.core.streams.WriteStream.writeQueueFull.

This will return true if there are more bytes in the write queue than the value set using setWriteQueueMaxSize

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait