Skip to content

Commit

Permalink
Reorder conn.disconnect, to support keepalives when bodyStream read
Browse files Browse the repository at this point in the history
Fixes jhy#1232
  • Loading branch information
jhy committed Jul 5, 2019
1 parent b61a3e6 commit fb58877
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ jsoup changelog
* Improvement: added Element chaining methods for various overridden methods on Node.
<https://github.com/jhy/jsoup/issues/1193>

* Improvement: ensure HTTP keepalives work when fetching content via body() and bodyAsBytes().
<https://github.com/jhy/jsoup/issues/1232>

* Bugfix: if duplicate attributes in an element exist, retain the first vs the last attribute with the same name. Case
aware (HTML case-insensitive names, XML are case-sensitive).
<https://github.com/jhy/jsoup/issues/1219>
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/org/jsoup/helper/HttpConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -915,13 +915,10 @@ private static HttpURLConnection createConnection(Connection.Request req) throws
}

/**
* Call on completion of stream read, to close the body (or error) stream
* Call on completion of stream read, to close the body (or error) stream. The connection.disconnect allows
* keep-alives to work (as the underlying connection is actually held open, despite the name).
*/
private void safeClose() {
if (conn != null) {
conn.disconnect();
conn = null;
}
if (bodyStream != null) {
try {
bodyStream.close();
Expand All @@ -931,6 +928,10 @@ private void safeClose() {
bodyStream = null;
}
}
if (conn != null) {
conn.disconnect();
conn = null;
}
}

// set up url, method, header, cookies
Expand Down

0 comments on commit fb58877

Please sign in to comment.