Server side X-Up-Target not working for redirects · Issue #213 · unpoly/unpoly · GitHub
Skip to content

Server side X-Up-Target not working for redirects #213

Closed

Description

@jwaschkau

Bug description

Unpoly seems to ignore the X-Up-Target-Header if it is sent with a redirect response. Probably response headers are only consumed for the destination of the redirect?

Expected behavior

When the X-Up-Target-Header is sent with a redirect response it should be used for the destination fragment updates.

Browser version

  • OS: Windows
  • Browser Chromium
  • Version 91.0.4472.124
  • Unpoly 2.0.1

Additional context

Unpoly correctly sends the original X-Up-Target-Header for the redirect and the following request. I think that the same behaviour would be consistent for the response behaviour.

Activity

  1. changed the title [-]X-Up-Target not working for redirects[/-] [+]Server side X-Up-Target not working for redirects[/+] on Jul 7, 2021
  2. triskweline commented on Jul 7, 2021

    @triskweline
    Contributor

    In your example:

    • Browser makes a request to /foo
    • Server responds with a redirect to /bar (response 1)
    • Browser sees the redirect and makes a second request to /bar
    • Server responds with HTML (response 2)

    Is the X-Up-Target header sent with response 1 or response 2?

  3. jwaschkau commented on Jul 7, 2021

    @jwaschkau
    Author

    Hey Henning,

    the X-Up-Target header is sent with response 1.

    I also tried to send the header with response 2, which alters the target fragment on the client side as expected.

  4. triskweline commented on Jul 8, 2021

    @triskweline
    Contributor

    This needs to be implemented on the server. It is technically impossible for browser JavaScript to see the headers of a redirecting response ("response 1" above). Redirects are followed automatically, JavaScript only ever sees the final response.

    While fetch() has a { redirect: 'manual' } option that allows JS to not follow redirects, it does not allow access to the headers of a redirecting response.

    I saw that you're maintaining the django-unpoly integration. The unpoly-rails gem actually persists X-Up headers over redirects. If you would like to do something similar, here's how I did it:

    • For Unpoly requests, override Rails' redirect_to method to append all X-Up request/response headers as query parameters to the destination URL
    • When the user asks for e.g. an X-Up-Target header we look either in the query parameters or in the request headers.
    • Send an X-Up-Location header without these query parameters so they don't ever appear in the browser's location bar

    Relevant sections in the Ruby code and tests:

    Closing this issue since there's nothing we can do in Unpoly itself.

  5. jwaschkau commented on Jul 8, 2021

    @jwaschkau
    Author

    Hey Henning,

    thanks for your helpful answer. I will have a look at the redirect implementation of the Ruby-Integration and add it to the django-unpoly library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions