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

What does make_service_fn and service_fn mean? #2554

Closed
kingluo opened this issue May 18, 2021 · 3 comments
Closed

What does make_service_fn and service_fn mean? #2554

kingluo opened this issue May 18, 2021 · 3 comments

Comments

@kingluo
Copy link

kingluo commented May 18, 2021

I found each HTTP request incoming, make_service_fn gets called once, and server_fn also gets called once.
What's the definition of make_service_fn and service_fn? Why not just one service function instead of two nested functions?

I am very confused, please help!

@seanmonstar
Copy link
Member

Does looking at the service docs help?

@kingluo
Copy link
Author

kingluo commented May 18, 2021

MakeService accepts connections, while Service handles requests of one connection.

My understanding is correct?

@davidpdrsn
Copy link
Member

Yes that sounds correct.

Said with a few more words: MakeService receives the address of the incoming connection and produces a service that will handle requests from that connection. If your request handling code only cares about the request and not the connection then MakeService might seem a bit redundant. However some use cases requires the address as well for example to set the Forwarded header on responses.

I have a PR that adds a utility to bypass make_service_fn if you don't need it #2541

@kingluo kingluo closed this as completed May 20, 2021
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

3 participants