30
30
from .utils import weighted_choice
31
31
from .structures import CaseInsensitiveDict
32
32
33
+ with open (os .path .join (os .path .realpath (os .path .dirname (__file__ )), 'VERSION' )) as version_file :
34
+ version = version_file .read ().strip ()
35
+
33
36
ENV_COOKIES = (
34
37
'_gauges_unique' ,
35
38
'_gauges_unique_year' ,
@@ -55,6 +58,7 @@ def jsonify(*args, **kwargs):
55
58
56
59
app = Flask (__name__ , template_folder = tmpl_dir )
57
60
app .debug = bool (os .environ .get ('DEBUG' ))
61
+ app .config ['JSONIFY_PRETTYPRINT_REGULAR' ] = True
58
62
59
63
app .add_template_global ('HTTPBIN_TRACKING' in os .environ , name = 'tracking_enabled' )
60
64
@@ -78,13 +82,12 @@ def jsonify(*args, **kwargs):
78
82
"url" : "https://kennethreitz.org" ,
79
83
},
80
84
# "termsOfService": "http://me.com/terms",
81
- "version" : "0.9.0"
85
+ "version" : version
82
86
},
83
87
"host" : "httpbin.org" , # overrides localhost:5000
84
88
"basePath" : "/" , # base bash for blueprint registration
85
89
"schemes" : [
86
- "https" ,
87
- "http"
90
+ "https"
88
91
],
89
92
'protocol' : 'https' ,
90
93
'tags' : [
@@ -510,17 +513,58 @@ def redirect_to():
510
513
- Redirects
511
514
produces:
512
515
- text/html
513
- parameters:
514
- - name: url
515
- type: string
516
- - name: status_code
517
- type: int
516
+ get:
517
+ parameters:
518
+ - in: query
519
+ name: url
520
+ type: string
521
+ required: true
522
+ - in: query
523
+ name: status_code
524
+ type: int
525
+ post:
526
+ consumes:
527
+ - application/x-www-form-urlencoded
528
+ parameters:
529
+ - in: formData
530
+ name: url
531
+ type: string
532
+ required: true
533
+ - in: formData
534
+ name: status_code
535
+ type: int
536
+ required: false
537
+ patch:
538
+ consumes:
539
+ - application/x-www-form-urlencoded
540
+ parameters:
541
+ - in: formData
542
+ name: url
543
+ type: string
544
+ required: true
545
+ - in: formData
546
+ name: status_code
547
+ type: int
548
+ required: false
549
+ put:
550
+ consumes:
551
+ - application/x-www-form-urlencoded
552
+ parameters:
553
+ - in: formData
554
+ name: url
555
+ type: string
556
+ required: true
557
+ - in: formData
558
+ name: status_code
559
+ type: int
560
+ required: false
518
561
responses:
519
562
302:
520
563
description: A redirection.
521
564
"""
522
565
523
- args = CaseInsensitiveDict (request .args .items ())
566
+ argsDict = request .form .to_dict (flat = True ) if request .method in ('POST' , 'PATCH' , 'PUT' ) else request .args .items ()
567
+ args = CaseInsensitiveDict (argsDict )
524
568
525
569
# We need to build the response manually and convert to UTF-8 to prevent
526
570
# werkzeug from "fixing" the URL. This endpoint should set the Location
@@ -907,13 +951,14 @@ def bearer_auth():
907
951
401:
908
952
description: Unsuccessful authentication.
909
953
"""
910
- if 'Authorization' not in request .headers :
954
+ authorization = request .headers .get ('Authorization' )
955
+ if not (authorization and authorization .startswith ('Bearer ' )):
911
956
response = app .make_response ('' )
912
957
response .headers ['WWW-Authenticate' ] = 'Bearer'
913
958
response .status_code = 401
914
959
return response
915
- authorization = request . headers . get ( 'Authorization ' )
916
- token = authorization . lstrip ( 'Bearer ' )
960
+ slice_start = len ( 'Bearer ' )
961
+ token = authorization [ slice_start :]
917
962
918
963
return jsonify (authenticated = True , token = token )
919
964
@@ -1072,7 +1117,7 @@ def digest_auth(qop=None, user='user', passwd='passwd', algorithm='MD5', stale_a
1072
1117
return response
1073
1118
1074
1119
1075
- @app .route ('/delay/<delay>' )
1120
+ @app .route ('/delay/<delay>' , methods = [ 'GET' , 'POST' , 'PUT' , 'DELETE' , 'PATCH' , 'TRACE' ] )
1076
1121
def delay_response (delay ):
1077
1122
""""Returns a delayed response (max of 10 seconds).
1078
1123
---
@@ -1102,6 +1147,31 @@ def drip():
1102
1147
---
1103
1148
tags:
1104
1149
- Dynamic data
1150
+ parameters:
1151
+ - in: query
1152
+ name: duration
1153
+ type: number
1154
+ description: The amount of time (in seconds) over which to drip each byte
1155
+ default: 2
1156
+ required: false
1157
+ - in: query
1158
+ name: numbytes
1159
+ type: integer
1160
+ description: The number of bytes to respond with
1161
+ default: 10
1162
+ required: false
1163
+ - in: query
1164
+ name: code
1165
+ type: integer
1166
+ description: The response code that will be returned
1167
+ default: 200
1168
+ required: false
1169
+ - in: query
1170
+ name: delay
1171
+ type: number
1172
+ description: The amount of time (in seconds) to delay before responding
1173
+ default: 2
1174
+ required: false
1105
1175
produces:
1106
1176
- application/octet-stream
1107
1177
responses:
@@ -1124,7 +1194,7 @@ def drip():
1124
1194
pause = duration / numbytes
1125
1195
def generate_bytes ():
1126
1196
for i in xrange (numbytes ):
1127
- yield u "*". encode ( 'utf-8' )
1197
+ yield b "*"
1128
1198
time .sleep (pause )
1129
1199
1130
1200
response = Response (generate_bytes (), headers = {
0 commit comments