-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Build info:
"appgen": "@encapsule/holistic v0.0.47 alexandrite Jvp9FcdjQNuiXkE2zcUjJA 4854c0117a5fa5e257006b334d52368e1997cfc0 2020-11-01T16:38:28.000Z",
Suppose I have a service filter that serves content of type "application/json" as shown below:
let factoryResponse = httpServiceFilterFactory.create({
id: "TxTaBMnjRAGUkRuf7rwUlg",
name: "Demo JSON service filter",
description: "A sample of a service filter that returns JSON as content.",
constraints: {
request: {
content: { encoding: "utf8", type: "text/plain" },
query_spec: { ____opaque: true },
request_spec: { ____opaque: true },
options_spec: { ____opaque: true }
},
response: {
content: { encoding: "utf8", type: "application/json" },
error_context_spec: { ____opaque: true },
result_spec: { ____opaque: true }
}
},
handlers: {
request_handler: (request_) => {
request_.response_filters.result.request({
streams: request_.streams,
integrations: request_.integrations,
request_descriptor: request_.request_descriptor,
response_descriptor: {
http: { code: 200 },
content: { encoding: "utf8", type: "application/json" },
data: {foo: "bar"}
}
});
return {result: undefined};
}
}
});
if (factoryResponse.error) throw new Error(factoryResponse.error);
const demoJSONServiceFilter = factoryResponse.result;
The value of what will be the "content-type" header in the response is clearly "application/json"
When binding that service filter to a route in the config.services object used when constructing the holism server, I am also required to specify the "contentType"
{
authentication: { required: false },
filter: demoAsyncServiceFilter,
request_bindings: { method: "GET", uris: [ "/demoasync" ] },
response_properties: { contentEncoding: "utf8", contentType: "application/json" },
}
So I have now specified the "content-type" in 2 places, so which value is actually used?
If I change the "contentType" in the binding to something else e.g. "text/html" then the value I actually see when making the request remains "application/json", so clearly the value in the binding is not being used. If I remove, the contentType from "response_properties" then an exception from a filter error for the missing contentType member is thrown and server start fails.
The conclusion is that the "contentType" in the binding is not actually used for the "content-type" header in the response, yet I am still required to provide it.