pywebpush
pywebpush copied to clipboard
Feature: get the encoded data ready for sending (for async interop)
Hello, It would be nice to be able to just get the encoded push request so we could use another http library for sending the request. Our motivation is to do this in an async framework, but there could be others.
Now we do this by monkeypatching the library:
import pywebpush
pywebpush.WebPusher.as_curl = lambda self, endpoint, data, headers: {'endpoint': endpoint, 'data': data, 'headers': headers}
then we can just pass curl=True
to any function and get the data we want. But it would be nicer to do this in an official way.
I suppose? But not sure why you need to monkey patch as_curl
.
send
is a convenience function too, but it outlines what you need to do to send data though. Some of it is localized, some of it is not. If you're using something other than requests
, there can be all sorts of special cases.
It's a bit more effort, but it also would be a lot easier, since you wouldn't have to worry about the content_encoding or key sniffing shenanigans I have to, just encode the via WebPusher().encode()
, build out the headers using proper aes128gcm
(which skips the whole crypto_key
nonsense), presume that nobody uses GCM because it's been dead for years and the server handles it anyway, etc.