Guest User

Untitled

a guest
Jan 17th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. from flask import Flask
  2. from flask import request
  3.  
  4. application = Flask(__name__)
  5.  
  6. @application.route('/', methods=['PUT'])
  7. def hello():
  8. print(request.headers)
  9. print(request.environ.get('SERVER_PROTOCOL'))
  10. return "Hello World!"
  11.  
  12. if __name__ == "__main__":
  13. application.run(host='0.0.0.0')
  14.  
  15. import requests
  16.  
  17. def get_data():
  18. yield b'This is test file.'
  19. yield b'This is test file.'
  20.  
  21. r = requests.request(
  22. method='PUT',
  23. url = 'http://127.0.0.1:5000/',
  24. data=get_data(),
  25. headers={
  26. 'Content-type': 'text/plain',
  27. 'X-Accel-Buffering': 'no',
  28. }
  29. )
  30. print('Response: ', r.text)
  31.  
  32. * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
  33. Host: 127.0.0.1:5000
  34. User-Agent: python-requests/2.18.4
  35. Accept-Encoding: gzip, deflate
  36. Accept: */*
  37. Connection: keep-alive
  38. Content-Type: text/plain
  39. X-Accel-Buffering: no
  40. Transfer-Encoding: chunked
  41.  
  42. HTTP/1.1
  43. 127.0.0.1 - - [17/Jan/2018 08:19:59] "PUT / HTTP/1.1" 200 -
  44.  
  45. Response: Hello World!
  46.  
  47. from server import application
  48.  
  49. if __name__ == "__main__":
  50. application.run()
  51.  
  52. $ uwsgi --http-socket localhost:5000 -w wsgi
  53.  
  54. [uwsgi]
  55. module = wsgi
  56.  
  57. master = true
  58. processes = 5
  59.  
  60. socket = /tmp/flask.sock
  61. chmod-socket = 777
  62. vacuum = true
  63.  
  64. die-on-term = true
  65.  
  66. worker_processes 1;
  67. events {
  68. worker_connections 1024;
  69. }
  70. http {
  71. include mime.types;
  72. default_type application/octet-stream;
  73. sendfile on;
  74. keepalive_timeout 65;
  75.  
  76. server {
  77. listen 5000;
  78. server_name 127.0.0.1;
  79.  
  80. location / {
  81. include uwsgi_params;
  82. uwsgi_pass unix:/tmp/flask.sock;
  83. proxy_request_buffering off;
  84. proxy_buffering off;
  85. proxy_http_version 1.1;
  86. chunked_transfer_encoding on;
  87. }
  88. proxy_request_buffering off;
  89. proxy_buffering off;
  90. proxy_http_version 1.1;
  91. chunked_transfer_encoding on;
  92. }
  93. }
  94.  
  95. $ uwsgi --ini uwsgi.ini --wsgi-manage-chunked-input --http-raw-body --http-auto-chunked --http-chunked-input
  96.  
  97. Content-Type: text/plain
  98. Content-Length: 36
  99. Host: 127.0.0.1:5000
  100. User-Agent: python-requests/2.18.4
  101. Accept-Encoding: gzip, deflate
  102. Accept: */*
  103. Connection: keep-alive
  104. X-Accel-Buffering: no
  105. Transfer-Encoding: chunked
  106.  
  107. HTTP/1.1
  108. [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)
  109.  
  110. Flask==0.12.2
  111. uWSGI===2.1-dev-f74553db
  112. nginx 1.12.2-2
Add Comment
Please, Sign In to add comment