Skip to content
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

Inconsistent source of status for ApplicationCall#respond variants #723

Open
DerkSchooltink opened this issue Nov 13, 2018 · 2 comments
Open

Comments

@DerkSchooltink
Copy link

Given the following code:

call.respond(HttpStatusCode.InternalServerError, "{}")
call.respondText("{}", ContentType.Application.Json, HttpStatusCode.InternalServerError)

I am intercepting the response in the 'after' of the 'sendPipeline':

pipeline.sendPipeline.intercept(ApplicationSendPipeline.After) {
           println("Respond: " + context.response.status())
           println("Respond TextContent: " + (this.subject as? TextContent)?.status)
}

The results for this interceptor are as following:

Usecase Code ApplicationResponse#status() TextContent#status
1 call.respond(HttpStatusCode.InternalServerError, "{}") 500 Internal Server Error null
2 call.respondText("{}", ContentType.Application.Json, HttpStatusCode.InternalServerError) null 500 Internal Server Error

Perhaps it is logical that usecase 1 has a null value for TextContent#status because it is not an actual TextContent. However, I would expect for usecase 2 that ApplicationResponse#status() would be set.

tl;dr: There is no single source of truth for getting the statuscode (which I would expect to be ApplicationResponse#status().

@cy6erGn0m cy6erGn0m self-assigned this Nov 14, 2018
@tajobe
Copy link

tajobe commented May 7, 2019

FWIW, if you wanted one place, it seems like it can always be retrieved from the subject as OutgoingContent after the Render phase:

        /**
         * Phase to render any current pipeline subject into [io.ktor.http.content.OutgoingContent]
         *
         * Beyond this phase only [io.ktor.http.content.OutgoingContent] should be produced by any interceptor
         */
        val Render = PipelinePhase("Render")

The caveat is that it can still be null if no status code was provided in a respond(...) (as in, doesn't get defaulted to 200).
That said, this information feels like it certainly should be available in the response API.

@oleg-larshin
Copy link

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

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

4 participants