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

Improve documentation around customizing handling of handshake #197

Closed
cjerdonek opened this issue Jul 8, 2017 · 6 comments
Closed

Improve documentation around customizing handling of handshake #197

cjerdonek opened this issue Jul 8, 2017 · 6 comments

Comments

@cjerdonek
Copy link
Collaborator

cjerdonek commented Jul 8, 2017

I was trying to figure out how to return a 404 on a bad path. Two things occur to me that would have made this a bit easier to figure out.

First, the end of the docstring of the server's handshake() method could be expanded to say, "Return the URI of the request, or None if the handshake was aborted."

Second, the docstring of the server's get_response_status() method could be expanded to say that the request path (e.g. to decide whether to return a 404) is available at self.path when that method is called. Currently, you have to notice that read_http_request() is called at the beginning of handshake() and then see that read_http_request() sets self.path. But even then, it's not clear if you'd be relying on implementation details.

@aaugustin
Copy link
Member

Go for it and make a PR!

@cjerdonek
Copy link
Collaborator Author

Okay, great. Though if you're open to my comment here (which I wrote later), this issue would probably be subsumed.

@aaugustin
Copy link
Member

Since #248 was merged, it's time to reopen the discussion here!

@aaugustin
Copy link
Member

The section about "Port sharing" in deployment.rst should be updated, since it is now possible to implement basic HTTP responses.

cjerdonek added a commit to cjerdonek/websockets that referenced this issue Oct 26, 2017
aaugustin pushed a commit that referenced this issue Nov 1, 2017
* Eliminate the need to wrap serve().

See issue #197 for related discussion.

* Fix Python 3.4.

* Choose better names per @aaugustin's comment.

* Update client.py.

* Fix flake8.

* Fix test for Python 3.4.
@aaugustin
Copy link
Member

Since I restructured the docs, the best place to put this information would be in its own page, linked from the "howto" section in index.rst.

@aaugustin
Copy link
Member

aaugustin commented May 5, 2018

By now, I believe this issue has become a duplicate of #354 for which I submitted PR #387.

The original issue is "I was trying to figure out how to return a 404 on a bad path."

The modern API for doing that is process_request, like this:

    async def process_request(self, path, request_headers):
        if path != '/':
            return http.HTTPStatus.NOT_FOUND, [], b'sorry not found\n'

This is close enough to the example in #387.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants