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

Feature: get the encoded data ready for sending (for async interop) #142

Open
kervel opened this issue Oct 14, 2021 · 1 comment
Open

Feature: get the encoded data ready for sending (for async interop) #142

kervel opened this issue Oct 14, 2021 · 1 comment

Comments

@kervel
Copy link

kervel commented Oct 14, 2021

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.

@jrconlin
Copy link
Member

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.

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

No branches or pull requests

2 participants