Skip to content

Commit b6ade99

Browse files
authored
Fix handling of HTTP 304 (#159)
#105 304 is not a redirect, so it does not have a `location` header like other 3xx return codes, and is not a failure Added a unit test to confirm the fix
1 parent 335eb4c commit b6ade99

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

requests/src/requests/Requester.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ case class Requester(verb: String,
291291
}
292292
}
293293

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

347-
if (streamHeaders.is2xx || !check) processWrappedStream(f)
349+
if (streamHeaders.statusCode == 304 || streamHeaders.is2xx || !check) processWrappedStream(f)
348350
else {
349351
val errorOutput = new ByteArrayOutputStream()
350352
processWrappedStream(geny.Internal.transfer(_, errorOutput))

requests/test/src/requests/RequestTests.scala

+4
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ object RequestTests extends TestSuite{
125125
}
126126
}
127127

128+
test("test_reproduction"){
129+
requests.get("http://httpbin.org/status/304").text()
130+
131+
}
128132
test("streaming"){
129133
val res1 = requests.get("http://httpbin.org/stream/5").text()
130134
assert(res1.linesIterator.length == 5)

0 commit comments

Comments
 (0)