Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of HTTP 304 #159

Merged
merged 1 commit into from
May 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
.
lihaoyi committed May 30, 2024
commit 1ec703640d5e4711bbbcaf4c438ecb437f69cca5
6 changes: 4 additions & 2 deletions requests/src/requests/Requester.scala
Original file line number Diff line number Diff line change
@@ -291,7 +291,9 @@ case class Requester(verb: String,
}
}

if (responseCode.toString.startsWith("3") && maxRedirects > 0){
if (responseCode.toString.startsWith("3") &&
responseCode.toString != "304" &&
maxRedirects > 0){
val out = new ByteArrayOutputStream()
Util.transferTo(connection.getInputStream, out)
val bytes = out.toByteArray
@@ -344,7 +346,7 @@ case class Requester(verb: String,
}
}

if (streamHeaders.is2xx || !check) processWrappedStream(f)
if (streamHeaders.statusCode == 304 || streamHeaders.is2xx || !check) processWrappedStream(f)
else {
val errorOutput = new ByteArrayOutputStream()
processWrappedStream(geny.Internal.transfer(_, errorOutput))
4 changes: 4 additions & 0 deletions requests/test/src/requests/RequestTests.scala
Original file line number Diff line number Diff line change
@@ -125,6 +125,10 @@ object RequestTests extends TestSuite{
}
}

test("test_reproduction"){
requests.get("http://httpbin.org/status/304").text()

}
test("streaming"){
val res1 = requests.get("http://httpbin.org/stream/5").text()
assert(res1.linesIterator.length == 5)