Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask
- from flask import request
- application = Flask(__name__)
- @application.route('/', methods=['PUT'])
- def hello():
- print(request.headers)
- print(request.environ.get('SERVER_PROTOCOL'))
- return "Hello World!"
- if __name__ == "__main__":
- application.run(host='0.0.0.0')
- import requests
- def get_data():
- yield b'This is test file.'
- yield b'This is test file.'
- r = requests.request(
- method='PUT',
- url = 'http://127.0.0.1:5000/',
- data=get_data(),
- headers={
- 'Content-type': 'text/plain',
- 'X-Accel-Buffering': 'no',
- }
- )
- print('Response: ', r.text)
- * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
- Host: 127.0.0.1:5000
- User-Agent: python-requests/2.18.4
- Accept-Encoding: gzip, deflate
- Accept: */*
- Connection: keep-alive
- Content-Type: text/plain
- X-Accel-Buffering: no
- Transfer-Encoding: chunked
- HTTP/1.1
- 127.0.0.1 - - [17/Jan/2018 08:19:59] "PUT / HTTP/1.1" 200 -
- Response: Hello World!
- from server import application
- if __name__ == "__main__":
- application.run()
- $ uwsgi --http-socket localhost:5000 -w wsgi
- [uwsgi]
- module = wsgi
- master = true
- processes = 5
- socket = /tmp/flask.sock
- chmod-socket = 777
- vacuum = true
- die-on-term = true
- worker_processes 1;
- events {
- worker_connections 1024;
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- sendfile on;
- keepalive_timeout 65;
- server {
- listen 5000;
- server_name 127.0.0.1;
- location / {
- include uwsgi_params;
- uwsgi_pass unix:/tmp/flask.sock;
- proxy_request_buffering off;
- proxy_buffering off;
- proxy_http_version 1.1;
- chunked_transfer_encoding on;
- }
- proxy_request_buffering off;
- proxy_buffering off;
- proxy_http_version 1.1;
- chunked_transfer_encoding on;
- }
- }
- $ uwsgi --ini uwsgi.ini --wsgi-manage-chunked-input --http-raw-body --http-auto-chunked --http-chunked-input
- Content-Type: text/plain
- Content-Length: 36
- Host: 127.0.0.1:5000
- User-Agent: python-requests/2.18.4
- Accept-Encoding: gzip, deflate
- Accept: */*
- Connection: keep-alive
- X-Accel-Buffering: no
- Transfer-Encoding: chunked
- HTTP/1.1
- [pid: 20220|app: 0|req: 1/1] 127.0.0.1 () {42 vars in 525 bytes} [Wed Jan 17 08:31:39 2018] PUT / => generated 12 bytes in 1 msecs (HTTP/1.1 200) 2 headers in 79 bytes (1 switches on core 0)
- Flask==0.12.2
- uWSGI===2.1-dev-f74553db
- nginx 1.12.2-2
Add Comment
Please, Sign In to add comment