Skip to content

Commit

Permalink
Work around #3663 - allow response.response() to work for failed HTTP…
Browse files Browse the repository at this point in the history
… connections
  • Loading branch information
asiekierka committed Apr 13, 2024
1 parent 53efb9c commit 3ceac70
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* [#3664] Fixed client-side errors when using third-party mod energy integration on an integrated server.
* [#3677] Fixed crash when showing error containing a percent sign with the Analyzer item.
* [#3698] Fixed documentation for the Screen's "turnOn" and "turnOff" functions. (Hawk777, DCNick3)
* [#3663] Fixed response code/message information not being preserved for unsuccessful HTTP responses.
* [#3691] Improved documentation for software bundled with the "network" floppy. (Computerdores)
* [#3644] Improved forged packet protection with regards to configuring server racks. (Glease)
* Updated GNU Unifont to 15.1.05.
Expand Down
8 changes: 6 additions & 2 deletions src/main/scala/li/cil/oc/server/component/InternetCard.scala
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,15 @@ object InternetCard {
out.close()
}

val input = http.getInputStream
HTTPRequest.this.synchronized {
response = Some((http.getResponseCode, http.getResponseMessage, http.getHeaderFields))
}
input

// Calling getInputStream() can cause an exception to be thrown for unsuccessful HTTP responses,
// so call it only after the response code/message are set to allow retrieving them.
// TODO: This should allow accessing getErrorStream() for reading unsuccessful HTTP responses' output,
// but this would be a breaking change for existing OC code.
http.getInputStream
}
catch {
case t: Throwable =>
Expand Down

0 comments on commit 3ceac70

Please sign in to comment.