Media-type checking sometimes fails in changeserver
Closed this issue · 3 comments
If the client does not include an Accept header, changeserver should respond with JSON. However, it sometimes responds with protobuf. This happens despite tests for just this situation inside the goscaffold project, so clearly some tests are missing ;-)
I am able to replicate this issue too. However, only with curl. This is explained by the fact that curl, by default, sends all requests with the request header Accept: */*
. This is what appears to be confusing things for curl at least.
A simple way to test this is to issue curl requests and explicity set the value of the Accept
header to nothing:
curl -H "Accept:" --head -X GET http://127.0.0.1:9000/changes
A simple way to fix this is to add a simple conditional statement before we call goscaffold.SelectMediaType
which removes the Accept
request header if it's value is not one of the accepted types.
if (req.Header.Get("Accept") != "application/transicator+protobuf") && (req.Header.Get("Accept") != "application/json") {
req.Header.Del("Accept")
}
Of course the if statement could also just cater for curl with:
if req.Header.Get("Accept") == "*/*" {
However, if we are only accepting 1 of 2 possible Mime-Types we should probably validate input explicitly using logic similar to the first example.
Let me dig in to the goscaffold package so that we can fix this in an
elegant way.
On Tue, Nov 22, 2016 at 5:13 AM, davent notifications@github.com wrote:
I am able to replicate this issue too. However, only with curl. This is
explained by the fact that curl, by default, sends all requests with the
request header Accept: /. This is what appears to be confusing things
for curl at least.A simple way to fix this is to add a simple conditional statement before
we call goscaffold.SelectMediaType which removes the Accept request
header if it's value is not one of the accepted types.if (req.Header.Get("Accept") != "application/transicator+protobuf") && (req.Header.Get("Accept") != "application/json") {
req.Header.Del("Accept")
}Of course the if statement could also just cater for curl with:
if req.Header.Get("Accept") == "/" {
However, we are only accepting 1 of 2 possible Mime-types we should
probably validate input explicitly using logic similar to the first example.—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#14 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAf0azeL6nibaF3yB7iH1x57mTSQyCIiks5rAup7gaJpZM4Kp7QN
.
Thanks for shedding light on how to reproduce it. Fixed it in goscaffold.