Skip to content

Commit

Permalink
Merge branch 'master' into setuptools-long-description
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethreitz authored Jul 4, 2018
2 parents 6d382e3 + d99d4e3 commit 4eb372f
Show file tree
Hide file tree
Showing 10 changed files with 371 additions and 67 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dockerfile
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dist/
.tox
*.egg-info
*.swp
.vscode/
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
FROM ubuntu:18.04

LABEL name="httpbin"
LABEL version="0.9.0"
LABEL description="A simple HTTP service."
LABEL org.kennethreitz.vendor="Kenneth Reitz"

RUN apt update -y && apt install python3-pip -y

EXPOSE 80
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include README.rst LICENSE AUTHORS requirements.txt test_httpbin.py
include httpbin/VERSION README.md LICENSE AUTHORS test_httpbin.py
recursive-include httpbin/templates *
recursive-include httpbin/static *
1 change: 1 addition & 0 deletions httpbin/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.9.0
98 changes: 84 additions & 14 deletions httpbin/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
from .utils import weighted_choice
from .structures import CaseInsensitiveDict

with open(os.path.join(os.path.realpath(os.path.dirname(__file__)), 'VERSION')) as version_file:
version = version_file.read().strip()

ENV_COOKIES = (
'_gauges_unique',
'_gauges_unique_year',
Expand All @@ -55,6 +58,7 @@ def jsonify(*args, **kwargs):

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

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

Expand All @@ -78,13 +82,12 @@ def jsonify(*args, **kwargs):
"url": "https://kennethreitz.org",
},
# "termsOfService": "http://me.com/terms",
"version": "0.9.0"
"version": version
},
"host": "httpbin.org", # overrides localhost:5000
"basePath": "/", # base bash for blueprint registration
"schemes": [
"https",
"http"
"https"
],
'protocol': 'https',
'tags': [
Expand Down Expand Up @@ -510,17 +513,58 @@ def redirect_to():
- Redirects
produces:
- text/html
parameters:
- name: url
type: string
- name: status_code
type: int
get:
parameters:
- in: query
name: url
type: string
required: true
- in: query
name: status_code
type: int
post:
consumes:
- application/x-www-form-urlencoded
parameters:
- in: formData
name: url
type: string
required: true
- in: formData
name: status_code
type: int
required: false
patch:
consumes:
- application/x-www-form-urlencoded
parameters:
- in: formData
name: url
type: string
required: true
- in: formData
name: status_code
type: int
required: false
put:
consumes:
- application/x-www-form-urlencoded
parameters:
- in: formData
name: url
type: string
required: true
- in: formData
name: status_code
type: int
required: false
responses:
302:
description: A redirection.
"""

args = CaseInsensitiveDict(request.args.items())
argsDict = request.form.to_dict(flat=True) if request.method in ('POST', 'PATCH', 'PUT') else request.args.items()
args = CaseInsensitiveDict(argsDict)

# We need to build the response manually and convert to UTF-8 to prevent
# werkzeug from "fixing" the URL. This endpoint should set the Location
Expand Down Expand Up @@ -907,13 +951,14 @@ def bearer_auth():
401:
description: Unsuccessful authentication.
"""
if 'Authorization' not in request.headers:
authorization = request.headers.get('Authorization')
if not (authorization and authorization.startswith('Bearer ')):
response = app.make_response('')
response.headers['WWW-Authenticate'] = 'Bearer'
response.status_code = 401
return response
authorization = request.headers.get('Authorization')
token = authorization.lstrip('Bearer ')
slice_start = len('Bearer ')
token = authorization[slice_start:]

return jsonify(authenticated=True, token=token)

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


@app.route('/delay/<delay>')
@app.route('/delay/<delay>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'TRACE'])
def delay_response(delay):
""""Returns a delayed response (max of 10 seconds).
---
Expand Down Expand Up @@ -1102,6 +1147,31 @@ def drip():
---
tags:
- Dynamic data
parameters:
- in: query
name: duration
type: number
description: The amount of time (in seconds) over which to drip each byte
default: 2
required: false
- in: query
name: numbytes
type: integer
description: The number of bytes to respond with
default: 10
required: false
- in: query
name: code
type: integer
description: The response code that will be returned
default: 200
required: false
- in: query
name: delay
type: number
description: The amount of time (in seconds) to delay before responding
default: 2
required: false
produces:
- application/octet-stream
responses:
Expand All @@ -1124,7 +1194,7 @@ def drip():
pause = duration / numbytes
def generate_bytes():
for i in xrange(numbytes):
yield u"*".encode('utf-8')
yield b"*"
time.sleep(pause)

response = Response(generate_bytes(), headers={
Expand Down
Loading

0 comments on commit 4eb372f

Please sign in to comment.