Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpHeaders are not handled #95

Closed
muuvmuuv opened this issue Jan 1, 2024 · 1 comment · Fixed by #96
Closed

HttpHeaders are not handled #95

muuvmuuv opened this issue Jan 1, 2024 · 1 comment · Fixed by #96

Comments

@muuvmuuv
Copy link
Contributor

muuvmuuv commented Jan 1, 2024

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

I am not seeing HttpHeaders beeing saved or received in cache.

Expected behavior

HttpHeaders should be serialized as HttpHeaders otherwise a .get() wont longer work in interceptors.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

We have request and correlation ids set in backend in response headers that I put into the response body for better access in templates. This is done in an interceptor.

Environment


Angular version: 17


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: 20  
- Platform:  Mac 

Others:

@muuvmuuv
Copy link
Contributor Author

muuvmuuv commented Jan 1, 2024

Tested, and it works by modifing HttpCacheLocalStorage.

    get(key) {
        const cacheValue = super.get(createKey$2(key));
        if (cacheValue) {
            return cacheValue;
        }
        const value = storage.getItem(createKey$2(key));
        if (value) {
						const response = new HttpResponse(value)
						response.headers = new HttpHeaders(value.headers);
            super.set(createKey$2(key), response);
        }
        return super.get(createKey$2(key));
    }
    set(key, response) {
			const httpResponse = {...response, headers: {} }
			if (response.headers instanceof HttpHeaders) {
				response.headers.keys().forEach(key => {
					httpResponse.headers[key] = response.headers.get(key);
				});
			}
        storage.setItem(createKey$2(key), httpResponse);
        return super.set(createKey$2(key), httpResponse);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant