Skip to content

Commit

Permalink
Adds support of sessionId for External-Job-Monitor (#8825)
Browse files Browse the repository at this point in the history
adds support of sessionId and minor bug fix
  • Loading branch information
Abhishekkr3003 authored Mar 5, 2024
1 parent 9f68c18 commit b5c5caa
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/src/main/java/hudson/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,18 @@ public static int remotePost(String[] args) throws Exception {
}

// get a crumb to pass the csrf check
String crumbField = null, crumbValue = null;
String crumbField = null, crumbValue = null, sessionCookies = null;
try {
HttpURLConnection con = open(new URL(home +
"crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)'"));
"crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)"));
if (auth != null) con.setRequestProperty("Authorization", auth);
String line = IOUtils.readFirstLine(con.getInputStream(), "UTF-8");
String[] components = line.split(":");
if (components.length == 2) {
crumbField = components[0];
crumbValue = components[1];
}
sessionCookies = con.getHeaderField("Set-Cookie");
} catch (IOException e) {
// presumably this Hudson doesn't use CSRF protection
}
Expand Down Expand Up @@ -173,10 +174,12 @@ public static int remotePost(String[] args) throws Exception {
if (auth != null) con.setRequestProperty("Authorization", auth);
if (crumbField != null && crumbValue != null) {
con.setRequestProperty(crumbField, crumbValue);
con.setRequestProperty("Cookie", sessionCookies);
}
con.setDoOutput(true);
// this tells HttpURLConnection not to buffer the whole thing
con.setFixedLengthStreamingMode((int) tmpFile.length());
con.setRequestProperty("Content-Type", "application/xml");

Check warning on line 182 in core/src/main/java/hudson/Main.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 129-182 are not covered by tests
con.connect();
// send the data
try (InputStream in = Files.newInputStream(tmpFile.toPath())) {
Expand Down

0 comments on commit b5c5caa

Please sign in to comment.