jenkinsci / jenkinsci/http-request-plugin

[JENKINS-63547] Write response to file before checking response status code

Open
#296 0 comments 0 reactions 0 assignees View on GitHub
component:http-request-plugin imported-jira-issue priority:minor resolution:unresolved
Dominant language
Java
Stars
176
Forks
158
Avg merge
1d 16h
Merged PRs (30d)
3

Description

Currently, the order of execution when processing an HTTP response is:


  • Log the body, if configured.

  • Check the response code and fail if it isn't in the expected range.

  • Write the response to a file.

The result of this is that consoleLogResponseBody and outputFile aren't equivalent: the former happens regardless of response status but the latter only happens if the status is in the expected range.

This is the code in question:

HttpRequestExecution.java

	private void processResponse(ResponseContentSupplier response) throws IOException, InterruptedException {

//logs
if (consoleLogResponseBody) {
logger().println("Response: \n" + response.getContent());
}

//validate status code
responseCodeIsValid(response);

//validate content
if (!validResponseContent.isEmpty()) {
if (!response.getContent().contains(validResponseContent)) {
throw new AbortException("Fail: Response doesn't contain expected content '" + validResponseContent + "'");
}
}

//save file
...


This ticket proposes changing this so that the response content is always written to a file, if configured, regardless of the response status.

My use case is uploading a large amount of data to Elasticsearch. The response is correspondingly large so I don't want to log it to the console, plus it's JSON so I'd prefer to write it to a file for easier querying in any case. So I set outputFile and archive that file, but if my request fails the file isn't written and I can't diagnose the issue. Instead I'm going to have to change my plugin call to allow any HTTP status and then write the response body to a file before manually checking the status.

---
Originally reported by allanlewis, imported from: Write response to file before checking response status code


  • assignee: janario
  • status: Open
  • priority: Minor
  • component(s): http-request-plugin
  • resolution: Unresolved
  • votes: 0
  • watchers: 0
  • imported: 20260702-081740

Raw content of original issue

Currently, the order of execution when processing an HTTP response is:


  • Log the body, if configured.

  • Check the response code and fail if it isn't in the expected range.

  • Write the response to a file.

The result of this is that consoleLogResponseBody and outputFile aren't equivalent: the former happens regardless of response status but the latter only happens if the status is in the expected range.

This is the code in question:

HttpRequestExecution.java

	private void processResponse(ResponseContentSupplier response) throws IOException, InterruptedException {

//logs
if (consoleLogResponseBody) {
logger().println("Response: \n" + response.getContent());
}

//validate status code
responseCodeIsValid(response);

//validate content
if (!validResponseContent.isEmpty()) {
if (!response.getContent().contains(validResponseContent)) {
throw new AbortException("Fail: Response doesn't contain expected content '" + validResponseContent + "'");
}
}

//save file
...


This ticket proposes changing this so that the response content is always written to a file, if configured, regardless of the response status.

My use case is uploading a large amount of data to Elasticsearch. The response is correspondingly large so I don't want to log it to the console, plus it's JSON so I'd prefer to write it to a file for easier querying in any case. So I set outputFile and archive that file, but if my request fails the file isn't written and I can't diagnose the issue. Instead I'm going to have to change my plugin call to allow any HTTP status and then write the response body to a file before manually checking the status.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.