admin管理员组

文章数量:1180512

We have a web application that calls REST APIs which are behind an API Gateway. We use WSO2 APIM as the gateway. One of the APIs we call is a simple GET that downloads a file and we would like to put a progress bar on the download but we can't get the Content-Length header in the response.

The API in question is not actually implemented programmatically (most are, but not this one). We have an ordinary Apache HTTPD web server on an internal server, not accessible from outside, that just serves the file. We create an API definition in the gateway with a GET endpoint and use the internal server as a back-end. Thus you can call it as an API from outside (and are required to authenticate in order to do so). If I make the call internally, directly to the back-end then there is a Content-Length header on the response.

Since it needs to be an authenticated call, the application makes the call and downloads the file before showing it to the user. We want to put a progress bar up while this is happening. We can see how much we have downloaded so far, but we need the total size to put it in context.

I have edited the deployment.toml for the gateway. In the [apim.cors] section I added Content-Length to the expose_headers list. This now reads

expose_headers = ["Content-Disposition", "Content-Type", "Content-Language", "WWW-Authenticate", "Content-Length"]

When we make the call, we now see Content-Length listed among the values of the Access-Control-Expose-Headers header, but we still don't get a Content-Length header itself

Question: How can we get the Content-Length header on the response?

本文标签: Not Getting ContentLength Header for CORS Request via WSO2 APIM gatewayStack Overflow