You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Of course, the HTTP specification doesn't allow me to set multiple Content-Type headers, but both Node.js and Koa allow me to do so. When I set more than one Content-Type response header, I find that Chrome, Edge, Firefox, and Postman all automatically recognize the last one.
How should koa, as a framework, position itself?
Validate parameters against the HTTP specification (which Node.js doesn't do)? Something like this:
// koa/lib/response.jsset(field,val){if(this.headerSent)returnif(field.toLowerCase()==='content-type'){assert(!Array.isArray(val),'Multiple content types are not allowed')}// Other code...}
Or, depending on the situation? Such as:
// koa/lib/response.jsgettype(){// can be a string or an arrayconsttype=this.get("Content-Type");if(!type)return"";// When there are more than one type, get the last onereturnArray.isArray(type) ?
type[type.length-1].split(";",1)[0] :
type.split(";",1)[0];},
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Running the following code and then requesting
127.0.0.1:3000
throws an error: "TypeError: type.split is not a function".Because the
Content-Type
header value is an array, not a string:koa/lib/response.js
Lines 388 to 392 in 0c81a73
Of course, the HTTP specification doesn't allow me to set multiple
Content-Type
headers, but both Node.js and Koa allow me to do so. When I set more than oneContent-Type
response header, I find that Chrome, Edge, Firefox, and Postman all automatically recognize the last one.How should koa, as a framework, position itself?
Validate parameters against the HTTP specification (which Node.js doesn't do)? Something like this:
Or, depending on the situation? Such as:
Beta Was this translation helpful? Give feedback.
All reactions