Skip to content

Partial URI for Location HTTP-header is missing context-path #11673

@andersaaberg

Description

@andersaaberg

#10879 made it possible to create a partial URL in the Location HTTP-header for redirects. This yields a correct Location HTTP-header as long as server.servlet.context-path is not set. However, if server.servlet.context-path is set, then the context-path is not included in the Location HTTP-header which is incorrect and prevents the clients from following the redirect.

Task List

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Steps to Reproduce

  1. Create a new Grails app
  2. Set server.servlet.context-path to e.g. "app" in application.yml
  3. Create TestController and OtherController
  4. Let TestController redirect to OtherController: redirect(absolute: false, controller: 'other') and let OtherController render some text.
  5. Start the app and call TestController with curl: curl -iL http://localhost:8080/app/test

Expected Behaviour

Expected text response from OtherController after redirect. Location HTTP-header should be: http://localhost:8080/app/other

Actual Behaviour

Gets HTTP-status 404, because Grails does not add context path to the partial Location HTTP-header. Location HTTP-header was: http://localhost:8080/other

Environment Information

  • Operating System: Ubuntu 20.04
  • Grails Version: 4.0.6
  • JDK Version: openjdk version "1.8.0_275"

Example Application

https://github.com/andersaaberg/partial-location-uri-servlet-context-path

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions