Skip to content

Instantly share code, notes, and snippets.

@BigBlueHat
Created July 15, 2016 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BigBlueHat/0161b4cdad76a439b43d6c82c594191f to your computer and use it in GitHub Desktop.
Save BigBlueHat/0161b4cdad76a439b43d6c82c594191f to your computer and use it in GitHub Desktop.
Test Multiple Inbound Header Handling in wptserve (for Python)

Test Multiple Inbound Header Handling in wptserve (for Python)

Wirking on exploring this issue: w3c/wptserve#84

Usage

$ pip install wptserve
$ python test.py
http://localhost:8080/

Elsewhere...

$ curl -v http://localhost:8080/ -H 'Prefer: respond-async, wait=100' -H 'Prefer: handling=l
enient'
*   Trying ::1...
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.41.0
> Host: localhost:8080
> Accept: */*
> Prefer: respond-async, wait=100
> Prefer: handling=lenient
>
< HTTP/1.1 200 OK
< Server: BaseHTTP/0.3 Python/2.7.10
< Date: Fri, 15 Jul 2016 18:10:01 GMT
< Content-Length: 187
<
{
    "accept": [
        "*/*"
    ],
    "host": [
        "localhost:8080"
    ],
    "prefer": [
        "handling=lenient"
    ],
    "user-agent": [
        "curl/7.41.0"
    ]
}* Connection #0 to host localhost left intact

Example usage from RFC 7240.

import json
import wptserve
port = 8080
doc_root = './files/'
def dump_json(obj):
return json.dumps(obj, indent=4, sort_keys=True)
@wptserve.handlers.handler
def test_headers(request, response):
print request.headers
response.content = dump_json(request.headers)
routes = [
("GET", "/", test_headers)
]
print 'http://localhost:{0}/'.format(port)
httpd = wptserve.server.WebTestHttpd(port=port, doc_root=doc_root,
routes=routes)
httpd.start(block=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment