Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions core/src/main/java/org/kohsuke/stapler/RequestImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public RenderOnDemandParameters createJavaScriptProxyParameters(Object toBeExpor
return new RenderOnDemandParameters(
"makeStaplerProxy",
bound.getURL(),
bound.getReleaseURL(),
getWebApp().getCrumbIssuer().issueCrumb(),
bound.getBoundJavaScriptUrlNames());
}
Expand Down
11 changes: 8 additions & 3 deletions core/src/main/java/org/kohsuke/stapler/StaplerRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -571,12 +571,15 @@ public interface StaplerRequest extends HttpServletRequest {
final class RenderOnDemandParameters {
public final String proxyMethod;
public final String url;
public final String releaseUrl;
public final String crumb;
public final Set<String> urlNames;

public RenderOnDemandParameters(String proxyMethod, String url, String crumb, Set<String> urlNames) {
public RenderOnDemandParameters(
String proxyMethod, String url, String releaseUrl, String crumb, Set<String> urlNames) {
this.proxyMethod = proxyMethod;
this.url = url;
this.releaseUrl = releaseUrl;
this.crumb = crumb;
this.urlNames = urlNames;
}
Expand Down Expand Up @@ -998,7 +1001,8 @@ public String createJavaScriptProxy(Object toBeExported) {
@Override
public RenderOnDemandParameters createJavaScriptProxyParameters(Object toBeExported) {
StaplerRequest.RenderOnDemandParameters result = from.createJavaScriptProxyParameters(toBeExported);
return new RenderOnDemandParameters(result.proxyMethod, result.url, result.crumb, result.urlNames);
return new RenderOnDemandParameters(
result.proxyMethod, result.url, result.releaseUrl, result.crumb, result.urlNames);
}

@Override
Expand Down Expand Up @@ -1654,7 +1658,8 @@ public String createJavaScriptProxy(Object toBeExported) {
@Override
public RenderOnDemandParameters createJavaScriptProxyParameters(Object toBeExported) {
StaplerRequest2.RenderOnDemandParameters result = from.createJavaScriptProxyParameters(toBeExported);
return new RenderOnDemandParameters(result.proxyMethod, result.crumb, result.url, result.urlNames);
return new RenderOnDemandParameters(
result.proxyMethod, result.crumb, result.url, result.releaseUrl, result.urlNames);
}

@Override
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/java/org/kohsuke/stapler/StaplerRequest2.java
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,15 @@ public interface StaplerRequest2 extends HttpServletRequest {
final class RenderOnDemandParameters {
public final String proxyMethod;
public final String url;
public final String releaseUrl;
public final String crumb;
public final Set<String> urlNames;

public RenderOnDemandParameters(String proxyMethod, String url, String crumb, Set<String> urlNames) {
public RenderOnDemandParameters(
String proxyMethod, String url, String releaseUrl, String crumb, Set<String> urlNames) {
this.proxyMethod = proxyMethod;
this.url = url;
this.releaseUrl = releaseUrl;
this.crumb = crumb;
this.urlNames = urlNames;
}
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/java/org/kohsuke/stapler/bind/Bound.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ public abstract class Bound implements HttpResponse {
*/
public abstract String getURL();

/**
* The URL where the object can be released, or {@code null} if not applicable.
*/
public String getReleaseURL() {
return null;
}

/**
* Gets the bound object.
*/
Expand Down
30 changes: 30 additions & 0 deletions core/src/main/java/org/kohsuke/stapler/bind/BoundObjectTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,30 @@ public static boolean isValidJavaIdentifier(String name) {
.allMatch(it -> Character.isJavaIdentifierPart(it) && !Character.isIdentifierIgnorable(it) && it < 256);
}

/**
* Explicitly unbind this object via HTTP.
*
* @throws HttpResponses.HttpResponseException expected outcome returning 200 OK
*/
public void doRelease(StaplerRequest2 req, StaplerResponse2 rsp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@POST?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, although I expect this would be replaced anyway due to

The current implementation sends one request per proxy, could be collapsed to just one if this approach is deemed preferable.

throws HttpResponses.HttpResponseException, IOException {
final Table table = resolve(false);
if (table == null) {
rsp.sendError(404);
return;
}

String id = req.getRestOfPath().replace("/", "");

Object object = table.resolve(id);
if (object == null) {
rsp.sendError(200);
return;
}
table.release(id);
rsp.sendError(200);
}

/**
* This serves the script content for a bound object. Support CSP-compatible st:bind and similar methods of making
* objects accessible to JS.
Expand Down Expand Up @@ -238,6 +262,11 @@ public void release() {
Table.this.release(id);
}

@Override
public String getReleaseURL() {
return Stapler.getCurrentRequest2().getContextPath() + RELEASE_PREFIX + id;
}

@Override
public String getURL() {
return Stapler.getCurrentRequest2().getContextPath() + PREFIX + id;
Expand Down Expand Up @@ -374,6 +403,7 @@ private Object writeReplace() {
}

public static final String PREFIX = "/$stapler/bound/";
public static final String RELEASE_PREFIX = "/$stapler/bound/release/";
static final String SCRIPT_PREFIX = "/$stapler/bound/script";

/**
Expand Down
Loading