Skip to content

Unable to update/remove session data if no response content #5033

@shirozatou

Description

@shirozatou

This is due to BeforeSend hook is not called when

  1. No response content
  2. Scoped plugin

Sample

    routing {
        route("test") {
            install(Sessions) { // not global
                cookie<String>(name = "token")
            }
            post("clear") {
                call.sessions.clear("token")
                if (call.request.queryParameters["c"] == "1") { // flag to set empty content
                    call.respond("")
                }
                call.response.status(HttpStatusCode.OK) // or HttpStatusCode.NoContent
            }
        }
    }

curl

> POST /test/clear?c=1 HTTP/1.1
> Host: 127.0.0.1:8080
> Accept: */*
> Cookie: token=foo
> 
< HTTP/1.1 200 OK
< Set-Cookie: token=; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Path=/; HttpOnly; $x-enc=URI_ENCODING
< Content-Length: 0
< Content-Type: text/plain; charset=UTF-8
< 

> POST /test/clear HTTP/1.1
> Host: 127.0.0.1:8080
> Accept: */*
> Cookie: token=foo
> 
< HTTP/1.1 200 OK
< Content-Length: 0
< 

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