Skip to content

Exception in Requester.stream when response is 304, where response-header doesn't include "location" #105

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

Closed
andreak opened this issue May 1, 2022 · 0 comments

Comments

@andreak
Copy link

andreak commented May 1, 2022

Using version 0.7.0
When receiving 304 "not modified" this code throws NoSuchElementException:

        if (responseCode.toString.startsWith("3") && maxRedirects > 0){
          val out = new ByteArrayOutputStream()
          Util.transferTo(connection.getInputStream, out)
          val bytes = out.toByteArray

          val current = Response(
            url,
            responseCode,
            responseMsg,
            new geny.Bytes(bytes),
            headerFields,
            redirectedFrom
          )
          persistCookies()
          val newUrl = current.headers("location").head

On line 309 val newUrl = current.headers("location").head
Sending location in 304 response is not required.

lihaoyi added a commit that referenced this issue May 30, 2024
#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
@lihaoyi lihaoyi closed this as completed Jun 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants