Skip to content

Commit

Permalink
[FIXED JENKINS-18425]
Browse files Browse the repository at this point in the history
"201 Created" response doesn't work well with a browser as the user agent.
  • Loading branch information
kohsuke committed Jun 25, 2013
1 parent c7c05f6 commit 5696982
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -55,6 +55,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=bug>
Build with parameters returns empty web page
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-18425">issue 18425</a>)
<li class=bug>
Access denied error results in ERR_CONTENT_DECODING_FAILED on most browsers, masking the root cause.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-15437">issue 15437</a>)
Expand Down
Expand Up @@ -34,6 +34,7 @@

import javax.servlet.ServletException;

import hudson.Util;
import hudson.model.Queue.WaitingItem;
import jenkins.model.Jenkins;
import jenkins.util.TimeDuration;
Expand Down Expand Up @@ -140,9 +141,12 @@ public void _doBuild(StaplerRequest req, StaplerResponse rsp, @QueryParameter Ti

WaitingItem item = Jenkins.getInstance().getQueue().schedule(
owner, delay.getTime(), new ParametersAction(values), new CauseAction(new Cause.UserIdCause()));
if (item!=null)
rsp.sendRedirect(SC_CREATED,req.getContextPath()+'/'+item.getUrl());
else
if (item!=null) {
String url = formData.optString("redirectTo");
if (url==null || Util.isAbsoluteUri(url)) // avoid open redirect
url = req.getContextPath()+'/'+item.getUrl();
rsp.sendRedirect(formData.optInt("statusCode",SC_CREATED), url);
} else
// send the user back to the job top page.
rsp.sendRedirect(".");
}
Expand Down
Expand Up @@ -51,6 +51,17 @@ THE SOFTWARE.
</tbody>
</j:forEach>
<f:block>
<!--
When used from the UI, use 303 redirect and send back to the job top page.
When neither of those options are given, we'll report "201 Created".
We can't use XHR for submitting this as there might be file parameters,
and submitting to IFRAME won't work either because 201 can't have HTML response.
So I think all we can do is this somewhat clunky workaround.
-->
<input type="hidden" name="statusCode" value="303" />
<input type="hidden" name="redirectTo" value="." />
<f:submit value="${%Build}" />
</f:block>
</f:form>
Expand Down

0 comments on commit 5696982

Please sign in to comment.