Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ Changes log
transfers and HTTP/2 trailing headers.
- HTTP/2 clients receive a response as soon as its headers arrive, while the request entity
continues to be written on a virtual thread.
- Active client requests can be aborted; HTTP stream failures surface as I/O errors and a
communication-error response callback.
- Bugs fixed
- Slf4j bridge reports wrong line number and caller class in log4j. Issue #233.
- When GET is an allowed method of a server resource, HEAD is now also listed (e.g. in the Allow header of a 405 response). Issue #266.
Expand Down
22 changes: 20 additions & 2 deletions org.restlet/src/main/java/org/restlet/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.function.BooleanSupplier;
import org.restlet.data.CacheDirective;
import org.restlet.data.ChallengeResponse;
import org.restlet.data.CharacterSet;
Expand Down Expand Up @@ -81,6 +82,9 @@ public static Request getCurrent() {
/** The cookies provided by the client. */
private volatile Series<Cookie> cookies;

/** Action used by an active client connector to abort this request. */
private volatile BooleanSupplier abortAction;

/** The trailing headers received with the request entity. */
private volatile Series<Header> trailers;

Expand Down Expand Up @@ -192,6 +196,7 @@ public Request(Method method, String resourceUri, Representation entity) {
*/
public Request(Request request) {
this(request.getMethod(), new Reference(request.getResourceRef()), request.getEntity());
this.abortAction = null;
challengeResponse = request.getChallengeResponse();

copyClientInfo(request);
Expand Down Expand Up @@ -311,7 +316,18 @@ private void copyClientInfo(final Request request) {
* @return True if the request was aborted.
*/
public boolean abort() {
return false;
BooleanSupplier action = abortAction;
return action != null && action.getAsBoolean();
}

/**
* Sets the action used to abort an active client request. Connector implementations configure
* this while a request is in flight and clear it when the exchange ends.
*
* @param action The abort action, or null when no exchange is active.
*/
public void setAbortAction(BooleanSupplier action) {
this.abortAction = action;
}

/**
Expand Down Expand Up @@ -485,7 +501,9 @@ public Method getMethod() {

/**
* Returns the callback invoked on response reception. If the value is not null, then the
* associated request will be executed asynchronously.
* associated request will be executed asynchronously. For a streaming response, the callback
* can be invoked again if the exchange fails after the initial response has been received; the
* response then has a connector-error status and reading its entity fails.
*
* @return The callback invoked on response reception.
*/
Expand Down
Loading
Loading