Comments (4)
Still 2nd and 4th case remain unimplemented. Here is some thoughts:
We can make two new yieldables: Headers and Trailers. Then we make socket to wait initiating response until either object of type Headers or first message is yielded. Similarly, the connection is closed on either Trailers or only after handler exits. The problem is that RPC cardinality is no longer tied to the function type: it can either by async generator or async function in both cases (multiple streaming response messages or just a single message). That's when it comes to server responding with custom headers/trailers.
For client reading headers/trailers it's different. I am yet to discover a way that works with async generators and is optional in a way that all existing code that does not check headers/trailers continues to work as expected.
from purerpc.
Trying to address this in #8
from purerpc.
#8 got merged and addressed two simpler cases: 1st and 3rd. Clients can now send additional request headers with metadata
keyword only argument:
stub.SayHello(request, metadata=(("x-api-key", "QWERTY"), ("x-request-id", "some-id")))
RPC handlers can get access to request metadata via optional last request
argument:
async def SayHello(self, message, request):
print("Server received metadata", request.custom_metadata)
return HelloReply(message=base64.b64encode(pickle.dumps(request.custom_metadata)))
See more usage cases in unit tests
from purerpc.
Actually now that I think of it, it may be better to change optional argument name to something like context
or request_info
, to separate it from request message that arrived in handler (first argument in the example code above)
from purerpc.
Related Issues (20)
- [Discussion] Make integrations with asyncio projects more friendly HOT 7
- Benchmark purerpc under CPython/PyPy against other gRPC implementations
- Docs needed
- BREAKING CHANGE: Stable API for 1.0 release
- Crash when message is larger than max
- AttributeError: module 'socket' has no attribute 'SO_REUSEPORT' HOT 3
- Have support multi process? HOT 2
- Support creating channels on unix sockets HOT 1
- test_util requires forge dependency
- How do I have a long-lasting client?
- tests fail on Python 3.8 (macOS) HOT 1
- anyio dependency is too limited
- maintenance tasks HOT 3
- ClientStubStreamStream uses yield inside a task group HOT 5
- CI: macos target hangs during pytest HOT 5
- ExceptionGroup support
- Review TODOs
- Timeouts and deadlines
- TLS HOT 1
- dictConfig in misc/greeter is excessive HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from purerpc.