{"action":"created","issue":{"url":"https://api.github.com/repos/fgallaire/wsgiserver/issues/4","repository_url":"https://api.github.com/repos/fgallaire/wsgiserver","labels_url":"https://api.github.com/repos/fgallaire/wsgiserver/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/fgallaire/wsgiserver/issues/4/comments","events_url":"https://api.github.com/repos/fgallaire/wsgiserver/issues/4/events","html_url":"https://github.com/fgallaire/wsgiserver/issues/4","id":193787055,"number":4,"title":"100-continue and PUT request - they hang on env['wsgi.input'].read() call","user":{"login":"jn0","id":407437,"avatar_url":"https://avatars.githubusercontent.com/u/407437?v=3","gravatar_id":"","url":"https://api.github.com/users/jn0","html_url":"https://github.com/jn0","followers_url":"https://api.github.com/users/jn0/followers","following_url":"https://api.github.com/users/jn0/following{/other_user}","gists_url":"https://api.github.com/users/jn0/gists{/gist_id}","starred_url":"https://api.github.com/users/jn0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jn0/subscriptions","organizations_url":"https://api.github.com/users/jn0/orgs","repos_url":"https://api.github.com/users/jn0/repos","events_url":"https://api.github.com/users/jn0/events{/privacy}","received_events_url":"https://api.github.com/users/jn0/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-12-06T14:33:17Z","updated_at":"2016-12-06T14:50:03Z","closed_at":null,"body":"wsgiserver **1.3** in Python **2.7**.12 under Ubuntu **16.04**\r\n\r\nCreate the script\r\n```python\r\n#!/usr/bin/python\r\n\r\nimport sys\r\nimport wsgiserver\r\nimport pprint\r\nimport signal\r\n\r\nsample_text = [\r\n\t'Hello world\\n',\r\n\t'\\n',\r\n]\r\n\r\ndef The_Application(env, proc):\r\n\tstatus, response_headers, result = \\\r\n\t\t'200 OK', [('Content-Type', 'text/plain; charset=utf-8'),], []\r\n\r\n\t# cardinal workaround: don't allow the thread to hang the node forever\r\n\tsignal.alarm(15)\r\n\r\n\tpprint.pprint(env)\r\n\tpprint.pprint(server)\r\n\r\n\tdata = env['wsgi.input'].read() # XXX this will block forever XXX\r\n\tpprint.pprint(data)\r\n\t\r\n\r\n\t# poor attempt to work it around\r\n#\tif env.get('HTTP_EXPECT', '-') == '100-continue':\r\n#\t\tproc('100 Continue', [])\r\n\r\n\tfor x in sample_text:\r\n\t\tresult.append(x)\r\n\r\n\tproc(status, response_headers)\r\n\treturn result and result or ['ERROR']\r\n\r\nwsgi_pathes = {\r\n\t'/': The_Application,\r\n}\r\n\r\ndispatcher = wsgiserver.WSGIPathInfoDispatcher(wsgi_pathes)\r\n\r\nserver = wsgiserver.WSGIServer(dispatcher, host = '0.0.0.0', port = 8080)\r\n\r\ntry:\r\n\tserver.start()\r\nexcept e:\r\n\tserver.interrupt = e\r\n\tserver.stop()\r\n\tsys.stderr.write('Killed\\n')\r\n\r\n# EOF #\r\n```\r\nrun it and call with `curl`.\r\nYou'll see that \r\n```bash\r\ncurl -vv -F a=b http://127.0.0.1:8080/some/path/to\r\n```\r\nperforms just fine with **POST** method, but\r\n```bash\r\ncurl -vv -F a=b -T some.small.file http://127.0.0.1:8080/some/path/to\r\n```\r\nwill cause the app (and the whole box!) to hang until `alarm` just after sending `HTTP/1.1 100 Continue` response.\r\n\r\nIf one comment out the `.read()` call, then normal operation resumes:\r\n```\r\n> POST /some/path/to HTTP/1.1\r\n> Host: 127.0.0.1:8080\r\n> User-Agent: curl/7.47.0\r\n> Accept: */*\r\n> Content-Length: 137\r\n> Expect: 100-continue\r\n> Content-Type: multipart/form-data; boundary=------------------------7e27b831733e273c\r\n> \r\n< HTTP/1.1 100 Continue\r\n< HTTP/1.1 200 OK\r\n< Content-Type: text/plain; charset=utf-8\r\n< Transfer-Encoding: chunked\r\n< Date: Tue, 06 Dec 2016 14:26:04 GMT\r\n< Server: jno-intra\r\n< \r\nHello world\r\n\r\n```\r\nHere we are."},"comment":{"url":"https://api.github.com/repos/fgallaire/wsgiserver/issues/comments/265168590","html_url":"https://github.com/fgallaire/wsgiserver/issues/4#issuecomment-265168590","issue_url":"https://api.github.com/repos/fgallaire/wsgiserver/issues/4","id":265168590,"user":{"login":"jn0","id":407437,"avatar_url":"https://avatars.githubusercontent.com/u/407437?v=3","gravatar_id":"","url":"https://api.github.com/users/jn0","html_url":"https://github.com/jn0","followers_url":"https://api.github.com/users/jn0/followers","following_url":"https://api.github.com/users/jn0/following{/other_user}","gists_url":"https://api.github.com/users/jn0/gists{/gist_id}","starred_url":"https://api.github.com/users/jn0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jn0/subscriptions","organizations_url":"https://api.github.com/users/jn0/orgs","repos_url":"https://api.github.com/users/jn0/repos","events_url":"https://api.github.com/users/jn0/events{/privacy}","received_events_url":"https://api.github.com/users/jn0/received_events","type":"User","site_admin":false},"created_at":"2016-12-06T14:50:03Z","updated_at":"2016-12-06T14:50:03Z","body":"I.e. it's the `.read()` method of `ChunkedRFile` class from `wsgiserver.py` module.\r\n\r\nIf the `size` parameter is not set, then it could set **once** the `self.buffer` to something and loop forever eating all the RAM available (in `data += self.buffer`).\r\n\r\nI think, the line\r\n```python\r\n                data += self.buffer\r\n```\r\nshould read somehow as\r\n```python\r\n                data += self.buffer; self.buffer = None\r\n```"}}
{"actor":{"display_login":"jn0"}}