ngx-restangular icon indicating copy to clipboard operation
ngx-restangular copied to clipboard

Custom headers emptying the headers map

Open Malex opened this issue 6 years ago • 1 comments

I need to use in my application a custom header in response to a getList (header is totalElements). It is correctly set by the backend, but of course in restangular the headers map only cointained the "default allowed" ones. For that reason I added Access-Control-Exposed-Headers. It is correctly returned, as per the following response, but after this change restangular does not populate the headers map entries


Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://localhost:4200
Access-Control-Expose-Headers: total-elements
Cache-Control: no-cache
Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/json; charset=utf-8
Date: Wed, 10 Jul 2019 09:22:29 GMT
ETag: W/"d94-6ITA2YnKbkbSYtyM0pSSIrU0koc"
Expires: -1
Pragma: no-cache
total-elements: 13
Transfer-Encoding: chunked
Vary: Origin, Accept-Encoding
X-Powered-By: Express

Malex avatar Jul 10 '19 09:07 Malex

Turns out (response.headers as any).lazyInit(); was needed at the start of the ResponseInterceptor. Which kinda makes sense, being a lazy initializer, but I wonder why in the default case (if the Expose-Headers was not set) they were initialized by default. This behavior I think should be documented

Malex avatar Jul 10 '19 11:07 Malex