armeria icon indicating copy to clipboard operation
armeria copied to clipboard

Risk of having duplicated `content-type` in response headers

Open Lincong opened this issue 4 months ago • 2 comments

We are on Armeria 1.16.3 and we noticed that the below code pattern can yield a HTTP response with 2 entries keyed by content-type:

import com.linecorp.armeria.common.HttpResponse

val responseMsg = "Hi"
val responseBuilder = HttpResponse.builder()
responseBuilder.status(200)
responseBuilder.content(responseMsg) // This adds a response header `content-type: text/plain; charset=utf-8`
responseBuilder.header("content-type", "application/json")
responseBuilder.build()

One the client side, the received HTTP response headers contain:

... 
content-type: text/plain; charset=utf-8
content-type: application/json

It may confuse the client and lead to failures. I wonder if it is worth changing the semantics of HttpResponseBuilder API to reduce the risk of having duplicated content-type entries. For example, we can make the last specified content-type win. I hope to learn what you think, thanks :)

Lincong avatar Oct 18 '24 00:10 Lincong