Coder Social home page Coder Social logo

Comments (4)

standy66 avatar standy66 commented on August 11, 2024 1

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.

standy66 avatar standy66 commented on August 11, 2024

Trying to address this in #8

from purerpc.

standy66 avatar standy66 commented on August 11, 2024

#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.

standy66 avatar standy66 commented on August 11, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.