Last active
August 29, 2015 14:03
-
-
Save domenic/1bbec0f341ae3cfb3a8f to your computer and use it in GitHub Desktop.
ServiceWorker server vs. client request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.onfetch = ev => { | |
var serverReq = ev.request; | |
var clientReq = new Request(serverReq.url, { | |
method: serverReq.method, | |
headers: serverReq.headers, | |
mode: serverReq.mode, | |
credentials: serverReq.credentials | |
}); | |
serverReq.body.pipeTo(clientReq.body); | |
// Note: lol, this re-uses a *client response* from fetch as a *server response* | |
// out of the service worker. So all that work distinguishing between client vs. | |
// server *requests* also needs to happen for response?! | |
fetch(clientReq).then(clientRes => ev.respondWith(clientRes)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment