Skip to content

Commit aa20322

Browse files
committed
Document Java request lifecycle hooks
1 parent 0bce3c6 commit aa20322

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

src/main/java/io/tus/java/client/TusClient.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,9 @@ public void prepareConnection(@NotNull HttpURLConnection connection) {
402402
}
403403
}
404404

405-
void runBeforeRequest(@NotNull String method, @NotNull HttpURLConnection connection) throws IOException {
405+
final void runBeforeRequest(
406+
@NotNull String method, @NotNull HttpURLConnection connection
407+
) throws IOException {
406408
if (requestLifecycleHooks == null || requestLifecycleHooks.getBeforeRequest() == null) {
407409
return;
408410
}
@@ -412,7 +414,9 @@ void runBeforeRequest(@NotNull String method, @NotNull HttpURLConnection connect
412414
);
413415
}
414416

415-
void runAfterResponse(@NotNull String method, @NotNull HttpURLConnection connection) throws IOException {
417+
final void runAfterResponse(
418+
@NotNull String method, @NotNull HttpURLConnection connection
419+
) throws IOException {
416420
if (requestLifecycleHooks == null || requestLifecycleHooks.getAfterResponse() == null) {
417421
return;
418422
}

src/main/java/io/tus/java/client/TusRequestLifecycleHooks.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,20 @@ public static final class RequestContext {
1919
this.connection = connection;
2020
}
2121

22+
/**
23+
* Get the logical TUS request method for this request.
24+
*
25+
* @return The request method.
26+
*/
2227
public String getMethod() {
2328
return method;
2429
}
2530

31+
/**
32+
* Get the HTTP connection for this request.
33+
*
34+
* @return The mutable HTTP connection.
35+
*/
2636
public HttpURLConnection getConnection() {
2737
return connection;
2838
}
@@ -32,19 +42,37 @@ public HttpURLConnection getConnection() {
3242
* Callback invoked before transport sends the request.
3343
*/
3444
public interface BeforeRequest {
45+
/**
46+
* Handle a request before it is sent.
47+
*
48+
* @param context The request context.
49+
* @throws IOException when the request should fail.
50+
*/
3551
void beforeRequest(RequestContext context) throws IOException;
3652
}
3753

3854
/**
3955
* Callback invoked after transport receives the response.
4056
*/
4157
public interface AfterResponse {
58+
/**
59+
* Handle a response after it has been received.
60+
*
61+
* @param context The request context.
62+
* @throws IOException when the response should fail.
63+
*/
4264
void afterResponse(RequestContext context) throws IOException;
4365
}
4466

4567
private final BeforeRequest beforeRequest;
4668
private final AfterResponse afterResponse;
4769

70+
/**
71+
* Create request lifecycle hooks.
72+
*
73+
* @param beforeRequest Callback invoked before a request is sent.
74+
* @param afterResponse Callback invoked after a response is received.
75+
*/
4876
public TusRequestLifecycleHooks(BeforeRequest beforeRequest, AfterResponse afterResponse) {
4977
this.beforeRequest = beforeRequest;
5078
this.afterResponse = afterResponse;

0 commit comments

Comments
 (0)