Skip to content

Commit 3483039

Browse files
FroMagetsegismont
authored andcommitted
Clarify how to terminate an http response in the javadoc (#5737)
1 parent 66293ec commit 3483039

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

vertx-core/src/main/java/io/vertx/core/http/HttpServerResponse.java

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
* <p>
4646
* It implements {@link io.vertx.core.streams.WriteStream} so it can be used with
4747
* {@link io.vertx.core.streams.Pipe} to pipe data with flow control.
48+
* <p>
49+
* Any response should end with a terminal action, which are {@link #end()} or {@link #sendFile(String)} for successful
50+
* completion of the request, or {@link #reset()} for erroneous completion of the request, so you can only call one of
51+
* the three methods as the last step in dealing with your response, but you must call one of the three methods.
52+
* </p>
4853
*
4954
* @author <a href="http://tfox.org">Tim Fox</a>
5055
*/
@@ -281,6 +286,11 @@ public interface HttpServerResponse extends WriteStream<Buffer> {
281286
* the actual response won't get written until this method gets called.
282287
* <p>
283288
* Once the response has ended, it cannot be used any more.
289+
* </p>
290+
* <p>
291+
* This is a terminal action, like {@link #sendFile(String)} and {@link #reset()}, so you can only call one of the
292+
* three methods as the last step in dealing with your response.
293+
* </p>
284294
*
285295
* @return a future completed with the body result
286296
*/
@@ -335,7 +345,11 @@ default Future<Void> send(ReadStream<Buffer> body) {
335345
*
336346
* <p> If the {@link HttpHeaders#CONTENT_LENGTH} is set then the request assumes this is the
337347
* length of the {stream}, otherwise the request will set a chunked {@link HttpHeaders#CONTENT_ENCODING}.
338-
*
348+
* </p>
349+
* <p>
350+
* This is a terminal action, like {@link #end()} and {@link #reset()}, so you can only call one of the
351+
* three methods as the last step in dealing with your response.
352+
* </p>
339353
* @return a future notified when the response has been written
340354
*/
341355
default Future<Void> sendFile(String filename) {
@@ -345,6 +359,10 @@ default Future<Void> sendFile(String filename) {
345359
/**
346360
* Same as {@link #sendFile(String, long, long)} using length @code{Long.MAX_VALUE} which means until the end of the
347361
* file.
362+
* <p>
363+
* This is a terminal action, like {@link #end()} and {@link #reset()}, so you can only call one of the
364+
* three methods as the last step in dealing with your response.
365+
* </p>
348366
*
349367
* @param filename path to the file to serve
350368
* @param offset offset to start serving from
@@ -360,6 +378,10 @@ default Future<Void> sendFile(String filename, long offset) {
360378
* (where supported by the underlying operating system.
361379
* This is a very efficient way to serve files.<p>
362380
* The actual serve is asynchronous and may not complete until some time after this method has returned.
381+
* <p>
382+
* This is a terminal action, like {@link #end()} and {@link #reset()}, so you can only call one of the
383+
* three methods as the last step in dealing with your response.
384+
* </p>
363385
*
364386
* @param filename path to the file to serve
365387
* @param offset offset to start serving from
@@ -371,6 +393,10 @@ default Future<Void> sendFile(String filename, long offset) {
371393
/**
372394
* Same as {@link #sendFile(FileChannel, long)} using length @code{Long.MAX_VALUE} which means until the end of the
373395
* file.
396+
* <p>
397+
* This is a terminal action, like {@link #end()} and {@link #reset()}, so you can only call one of the
398+
* three methods as the last step in dealing with your response.
399+
* </p>
374400
*
375401
* @param channel the file channel to the file to serve
376402
* @return a future completed with the body result
@@ -384,6 +410,10 @@ default Future<Void> sendFile(FileChannel channel) {
384410
/**
385411
* Same as {@link #sendFile(FileChannel, long, long)} using length @code{Long.MAX_VALUE} which means until the end of the
386412
* file.
413+
* <p>
414+
* This is a terminal action, like {@link #end()} and {@link #reset()}, so you can only call one of the
415+
* three methods as the last step in dealing with your response.
416+
* </p>
387417
*
388418
* @param channel the file channel to the file to serve
389419
* @param offset offset to start serving from
@@ -404,6 +434,10 @@ default Future<Void> sendFile(FileChannel channel, long offset) {
404434
* The actual serve is asynchronous and may not complete until some time after this method has returned.
405435
* The developer is responsible to set the adequate Content-Type with {@link #putHeader(String, String)}. If not
406436
* application/octet-stream will be set as default Content-Type.
437+
* <p>
438+
* This is a terminal action, like {@link #end()} and {@link #reset()}, so you can only call one of the
439+
* three methods as the last step in dealing with your response.
440+
* </p>
407441
*
408442
* @param channel the file channel to the file to serve
409443
* @param offset offset to start serving from
@@ -416,6 +450,10 @@ default Future<Void> sendFile(FileChannel channel, long offset) {
416450

417451
/**
418452
* Same as {@link #sendFile(FileChannel)} with {@link RandomAccessFile}
453+
* <p>
454+
* This is a terminal action, like {@link #end()} and {@link #reset()}, so you can only call one of the
455+
* three methods as the last step in dealing with your response.
456+
* </p>
419457
*
420458
* @param file the file to serve
421459
* @return a future completed with the body result
@@ -429,6 +467,10 @@ default Future<Void> sendFile(RandomAccessFile file) {
429467
/**
430468
*
431469
* Same as {@link #sendFile(FileChannel, long)} with {@link RandomAccessFile}
470+
* <p>
471+
* This is a terminal action, like {@link #end()} and {@link #reset()}, so you can only call one of the
472+
* three methods as the last step in dealing with your response.
473+
* </p>
432474
*
433475
* @param file the file to serve
434476
* @param offset offset to start serving from
@@ -442,6 +484,10 @@ default Future<Void> sendFile(RandomAccessFile file, long offset) {
442484

443485
/**
444486
* Same as {@link #sendFile(FileChannel, long, long)} with {@link RandomAccessFile}
487+
* <p>
488+
* This is a terminal action, like {@link #end()} and {@link #reset()}, so you can only call one of the
489+
* three methods as the last step in dealing with your response.
490+
* </p>
445491
*
446492
* @param file the file to serve
447493
* @param offset offset to start serving from
@@ -540,7 +586,8 @@ default Future<HttpServerResponse> push(HttpMethod method, String path) {
540586
Future<HttpServerResponse> push(HttpMethod method, HostAndPort authority, String path, MultiMap headers);
541587

542588
/**
543-
* Reset this HTTP/2 stream with the error code {@code 0}.
589+
* Equivalent to calling {@link #reset(long)} with {@code 0}.
590+
* @see #reset(long)
544591
*/
545592
default Future<Void> reset() {
546593
return reset(0L);
@@ -555,6 +602,10 @@ default Future<Void> reset() {
555602
* </ul>
556603
* <p/>
557604
* When the response has already been sent nothing happens and {@code false} is returned as indicator.
605+
* <p>
606+
* This is a terminal action, like {@link #end()} and {@link #sendFile(String)}, so you can only call one of the three
607+
* methods as the last step in dealing with your response.
608+
* </p>
558609
*
559610
* @param code the error code
560611
* @return {@code true} when reset has been performed

0 commit comments

Comments
 (0)