Skip to content

Commit

Permalink
fix #3735
Browse files Browse the repository at this point in the history
  • Loading branch information
asiekierka committed Sep 21, 2024
1 parent 49ae4fe commit a8ca37c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 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,12 +524,18 @@ object InternetCard {
out.close()
}

// Finish the connection. Call getInputStream a second time below to re-throw any exception.
// This avoids getResponseCode() waiting for the connection to end in the synchronized block.
try {
http.getInputStream
} catch {
case _: Exception =>
}

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

// 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
Expand Down

0 comments on commit a8ca37c

Please sign in to comment.