Here is the method for the Jenkins CLI that causes all the sadness.
The major section is this:
con.getOutputStream().close();
input = con.getInputStream();
// make sure we hit the right URL
if(con.getHeaderField("Hudson-Duplex")==null)
throw new IOException(target+" doesn't look like Jenkins");
// client->server uses chunked encoded POST for unlimited capacity.
con = (HttpURLConnection) target.openConnection();
con.setDoOutput(true); // request POST
con.setRequestMethod("POST");
con.setChunkedStreamingMode(0);
con.setRequestProperty("Content-type","application/octet-stream");
con.addRequestProperty("Session", uuid.toString());
con.addRequestProperty("Side","upload");
It is this second POST which causes the 400 error and the prefetch
to bail out...
public FullDuplexHttpStream(URL target) throws IOException {
this.target = target;
String authorization = null;
if (target.getUserInfo() != null) {
authorization = new String(new
Base64().encodeBase64(target.getUserInfo().getBytes()));
}
CrumbData crumbData = new CrumbData();
UUID uuid = UUID.randomUUID(); // so that the server can correlate
those two connections
// server->client
HttpURLConnection con = (HttpURLConnection) target.openConnection();
con.setDoOutput(true); // request POST to avoid caching
con.setRequestMethod("POST");
con.addRequestProperty("Session", uuid.toString());
con.addRequestProperty("Side","download");
if (authorization != null) {
con.addRequestProperty("Authorization", "Basic " + authorization);
}
if(crumbData.isValid) {
con.addRequestProperty(crumbData.crumbName, crumbData.crumb);
}
con.getOutputStream().close();
input = con.getInputStream();
// make sure we hit the right URL
if(con.getHeaderField("Hudson-Duplex")==null)
throw new IOException(target+" doesn't look like Jenkins");
// client->server uses chunked encoded POST for unlimited capacity.
con = (HttpURLConnection) target.openConnection();
con.setDoOutput(true); // request POST
con.setRequestMethod("POST");
con.setChunkedStreamingMode(0);
con.setRequestProperty("Content-type","application/octet-stream");
con.addRequestProperty("Session", uuid.toString());
con.addRequestProperty("Side","upload");
if (authorization != null) {
con.addRequestProperty ("Authorization", "Basic " +
authorization);
}
if(crumbData.isValid) {
con.addRequestProperty(crumbData.crumbName, crumbData.crumb);
}
output = con.getOutputStream();
}