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

Expect: 100-continue #267

Closed
tumb1er opened this issue Jan 30, 2015 · 10 comments
Closed

Expect: 100-continue #267

tumb1er opened this issue Jan 30, 2015 · 10 comments
Labels

Comments

@tumb1er
Copy link
Contributor

tumb1er commented Jan 30, 2015

Is it supported in aiohttp.web server?

$> curl -v -include --form data=@1.f4f http://192.168.70.104:8080/uploader/123/
*   Trying 192.168.70.104...
* Connected to 192.168.70.104 (192.168.70.104) port 8080 (#0)
> POST /uploader/123/ HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 192.168.70.104:8080
> Accept: */*
> Content-Length: 408460805
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------9fa6693db84f46b3
> 
* Done waiting for 100-continue
< HTTP/1.1 200 OK

Nginx + Django response looks like this:

> POST /accounts/login/ HTTP/1.1
> User-Agent: curl/7.35.0
> Host: ***
> Accept: */*
> Expect: 100-continue
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 96
> 
< HTTP/1.1 100 Continue
< HTTP/1.1 403 FORBIDDEN

Nginx responses with HTTP/1.1 100 Continue first.

@asvetlov
Copy link
Member

I don't understand your question clean, sorry.
aiohttp.web has no embedded support for 100 but you can make response with 100 Continue status code by hands if needed.

@tumb1er
Copy link
Contributor Author

tumb1er commented Jan 30, 2015

No, if I make a response:

return Response(status=100)

aiohttp just closes connection. Curl output:

* Done waiting for 100-continue
< HTTP/1.1 100 Continue
HTTP/1.1 100 Continue
< CONTENT-LENGTH: 0
CONTENT-LENGTH: 0
< CONNECTION: keep-alive
CONNECTION: keep-alive
< DATE: Fri, 30 Jan 2015 16:12:43 GMT
DATE: Fri, 30 Jan 2015 16:12:43 GMT
* Server Python/3.4 aiohttp/0.14.4 is not blacklisted
< SERVER: Python/3.4 aiohttp/0.14.4
SERVER: Python/3.4 aiohttp/0.14.4

* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer

Working code is:

 request.transport.write(b"HTTP/1.1 100 Continue\r\n")

It is possible to handle authomatically in Request?

@fafhrd91
Copy link
Member

@tumb1er what is your use case for 100-continue ?

@ludovic-gasc
Copy link
Contributor

If it's like SIP protocol, it's to notify the client that the request is received, response will arrive.

@tumb1er
Copy link
Contributor Author

tumb1er commented Jan 30, 2015

@fafhrd91 it's only an observation of how curl works with post requests.
From here:

Upon receiving a request which includes an Expect request-header
field with the "100-continue" expectation, an origin server MUST
either respond with 100 (Continue) status and continue to read
from the input stream, or respond with a final status code. The
origin server MUST NOT wait for the request body before sending
the 100 (Continue) response. If it responds with a final status
code, it MAY close the transport connection or it MAY continue
to read and discard the rest of the request. It MUST NOT
perform the requested method if it returns a final status code.

@fafhrd91
Copy link
Member

that is wrong reason for feature. by implementing this response you close ways to use this feature properly. i prefer no to have it rather have wrong implementation.

@tumb1er
Copy link
Contributor Author

tumb1er commented Jan 30, 2015

So every aiohttp user MUST now implement Expect: header processing by himself, to make aiohttp library HTTP/1.1 compatible?

I think, with Request.post() method behavior mentioned by RFC is clear enougth.

def handle(request):
  # First, check all request properties without reading a payload
  if check_headers_and_path(request) != "ok":
    # if not OK, send 417, or 403 or whatever else... (server MUST continue reading
    # or response with final status code)
    return Response(status=417)
  # if ok, request.post() sends 100-continue if necessary 
  # (without any other movements from aiohttp users)
  # and continue reading payload (that is what server 
  # MUST do if 100-continue is sent)
  yield from request.post()
  # do "perform request method" as in RFC
  result = do_usefull_stuff(request)
  return Response(text=result, status=200)

@fafhrd91
Copy link
Member

you can create middleware that for that.

@fafhrd91
Copy link
Member

well, you example already has different use case. so make pull request for your use case.

@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants