Skip to content

Commit 4eb372f

Browse files
authored
Merge branch 'master' into setuptools-long-description
2 parents 6d382e3 + d99d4e3 commit 4eb372f

10 files changed

+371
-67
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Dockerfile

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ dist/
77
.tox
88
*.egg-info
99
*.swp
10+
.vscode/

Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
FROM ubuntu:18.04
22

3+
LABEL name="httpbin"
4+
LABEL version="0.9.0"
5+
LABEL description="A simple HTTP service."
6+
LABEL org.kennethreitz.vendor="Kenneth Reitz"
7+
38
RUN apt update -y && apt install python3-pip -y
49

510
EXPOSE 80

MANIFEST.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
include README.rst LICENSE AUTHORS requirements.txt test_httpbin.py
1+
include httpbin/VERSION README.md LICENSE AUTHORS test_httpbin.py
22
recursive-include httpbin/templates *
33
recursive-include httpbin/static *

httpbin/VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.9.0

httpbin/core.py

+84-14
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
from .utils import weighted_choice
3131
from .structures import CaseInsensitiveDict
3232

33+
with open(os.path.join(os.path.realpath(os.path.dirname(__file__)), 'VERSION')) as version_file:
34+
version = version_file.read().strip()
35+
3336
ENV_COOKIES = (
3437
'_gauges_unique',
3538
'_gauges_unique_year',
@@ -55,6 +58,7 @@ def jsonify(*args, **kwargs):
5558

5659
app = Flask(__name__, template_folder=tmpl_dir)
5760
app.debug = bool(os.environ.get('DEBUG'))
61+
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True
5862

5963
app.add_template_global('HTTPBIN_TRACKING' in os.environ, name='tracking_enabled')
6064

@@ -78,13 +82,12 @@ def jsonify(*args, **kwargs):
7882
"url": "https://kennethreitz.org",
7983
},
8084
# "termsOfService": "http://me.com/terms",
81-
"version": "0.9.0"
85+
"version": version
8286
},
8387
"host": "httpbin.org", # overrides localhost:5000
8488
"basePath": "/", # base bash for blueprint registration
8589
"schemes": [
86-
"https",
87-
"http"
90+
"https"
8891
],
8992
'protocol': 'https',
9093
'tags': [
@@ -510,17 +513,58 @@ def redirect_to():
510513
- Redirects
511514
produces:
512515
- 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
518561
responses:
519562
302:
520563
description: A redirection.
521564
"""
522565

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)
524568

525569
# We need to build the response manually and convert to UTF-8 to prevent
526570
# werkzeug from "fixing" the URL. This endpoint should set the Location
@@ -907,13 +951,14 @@ def bearer_auth():
907951
401:
908952
description: Unsuccessful authentication.
909953
"""
910-
if 'Authorization' not in request.headers:
954+
authorization = request.headers.get('Authorization')
955+
if not (authorization and authorization.startswith('Bearer ')):
911956
response = app.make_response('')
912957
response.headers['WWW-Authenticate'] = 'Bearer'
913958
response.status_code = 401
914959
return response
915-
authorization = request.headers.get('Authorization')
916-
token = authorization.lstrip('Bearer ')
960+
slice_start = len('Bearer ')
961+
token = authorization[slice_start:]
917962

918963
return jsonify(authenticated=True, token=token)
919964

@@ -1072,7 +1117,7 @@ def digest_auth(qop=None, user='user', passwd='passwd', algorithm='MD5', stale_a
10721117
return response
10731118

10741119

1075-
@app.route('/delay/<delay>')
1120+
@app.route('/delay/<delay>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'TRACE'])
10761121
def delay_response(delay):
10771122
""""Returns a delayed response (max of 10 seconds).
10781123
---
@@ -1102,6 +1147,31 @@ def drip():
11021147
---
11031148
tags:
11041149
- 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
11051175
produces:
11061176
- application/octet-stream
11071177
responses:
@@ -1124,7 +1194,7 @@ def drip():
11241194
pause = duration / numbytes
11251195
def generate_bytes():
11261196
for i in xrange(numbytes):
1127-
yield u"*".encode('utf-8')
1197+
yield b"*"
11281198
time.sleep(pause)
11291199

11301200
response = Response(generate_bytes(), headers={

0 commit comments

Comments
 (0)