Skip to content

Need a way to add response headers to service worker responses #31330

Closed

Description

@vinay-akkipet

🚀 feature request

Relevant Package

This feature request is for @angular/pwa

Description

Need a way to add response headers to responses cached and returned by service worker responses. While using service workers with a CSP, we can run into issues like the one described here whose solution is to add a different CSP header for responses returned by service workers as described here.

I am facing a similar issue as described in the first link above and if can add a header like 'Content-Security-Policy: connect-src *;' to the cached responses returned by the service worker it should solve the problem.

Describe the solution you'd like

A way to add response headers for responses returned by a service worker

Describe alternatives you've considered

  1. Tried using angular HttpInterceptors to see if I could intercept the service worker response and add the appropriate header.
  2. Using plain JS instead of the angular package to have more control over the service worker responses.

Activity

  1. gkalpak commented on Jun 28, 2019

    @gkalpak
    Member

    If I understand the linked resources correctly, the solution is not to set special headers to responses from inside the SW script (that wouldn't help, since the request would have failed in the first place).

    The solution is to set special CSP headers on the server to the response for the SW script. I.e., when the browsers requests ngsw-worker.js (the default name for the Angular SW script), the server should attach special CSP headers (e.g. Content-Security-Policy: connect-src *) to the response.

    I am going to close this, since there is nothing to fix inside the Angular SW script, but feel free to continue the discussion below (or point out any mistakes in my understanding of the issue).

  2. vinay-akkipet commented on Jun 29, 2019

    @vinay-akkipet
    Author

    @gkalpak Thanks a ton for adding that comment before closing!! My bad I misconstrued the issue.

  3. angular-automatic-lock-bot commented on Sep 15, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  4. locked and limited conversation to collaborators on Sep 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions