Skip to content

Instantly share code, notes, and snippets.

View Lukasa's full-sized avatar

Cory Benfield Lukasa

View GitHub Profile
@Lukasa
Lukasa / requirements.txt
Created April 14, 2015 12:27
Twisted HTTP/2 spike
Twisted==15.1.0
hpack==1.0.0
hyperframe==1.0.0
@Lukasa
Lukasa / headerprofile.py
Created March 8, 2015 08:10
Profiles various header mappings.
import time
from hyper.common.headers import HTTPHeaderMap
from urllib3._collections import HTTPHeaderDict
def timeit(method):
def timed(*args, **kw):
ts = time.clock()
for _ in range(10000):
result = method(*args, **kw)
@Lukasa
Lukasa / headermap.py
Last active August 29, 2015 14:16
A prototype Python header mapping.
import collections
class HTTPHeaderMap(collections.MutableMapping):
"""
A structure that contains HTTP headers.
HTTP headers are a curious beast. At the surface level they look roughly
like a name-value set, but in practice they have many variations that
make them tricky:
@Lukasa
Lukasa / netlink_ifnew.py
Created March 4, 2015 09:26
Monitor for new links using Python and Netlink
@Lukasa
Lukasa / fingerprinting.py
Created March 3, 2015 20:48
Example of how to do certificate fingerprinting with cryptography
# Needed for boring connection logic
import ssl
import socket
# Needed for the cert work
from binascii import hexlify
from cryptography import x509
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
@Lukasa
Lukasa / explanation.md
Last active August 29, 2015 14:05
Example of hyper code demonstrating incorrect response from Google

Google's server is providing an incorrect pseudo-header field. Their response contains the pseudo-header field ':status' with the value '302 Found', in violation of the draft. The relevant section is Section 8.1.2.4 of the h2-14 draft, which reads:

A single ":status" header field is defined that carries the HTTP status code field (see [RFC7231], Section 6). This header field MUST be included in all responses, otherwise the response is malformed (Section 8.1.2.6).

HTTP/2 does not define a way to carry the version or reason phrase that is included in an HTTP/1.1 status line.

@Lukasa
Lukasa / history.log
Created June 20, 2014 13:41
Apt history
Start-Date: 2014-06-20 14:36:56
Commandline: apt-get install openssh-server
Install: ncurses-term:amd64 (5.9+20140118-1ubuntu1, automatic), python-urllib3:amd64 (1.7.1-1build1, automatic), openssh-server:amd64 (6.6p1-2ubuntu2), openssh-sftp-server:amd64 (6.6p1-2ubuntu2, automatic), ssh-import-id:amd64 (3.21-0ubuntu1, automatic), python-requests:amd64 (2.2.1-1, automatic), libck-connector0:amd64 (0.4.5-3.1ubuntu2, automatic), libwrap0:amd64 (7.6.q-25, automatic), tcpd:amd64 (7.6.q-25, automatic)
End-Date: 2014-06-20 14:37:01
@Lukasa
Lukasa / timeout.py
Created April 1, 2014 08:18
Example of setting global timeout in requests.
from requests.adapters import HTTPAdapter
class TimeoutAdapter(HTTPAdapter):
def send(self, *args, **kwargs):
kwargs.setdefault('timeout', 30)
super(TimeoutAdapter, self).send(*args, **kwargs)
@Lukasa
Lukasa / wtfgoogle.md
Created March 25, 2014 09:27
Hey Google, you know what this isn't? Valid JSON.

A Thankyou To Google

Dear Google,

I'd just like to thank you for disabusing me of the idea that JSON is under some requirement of well-formedness. I'd been labouring under the tyrannical misapprehension that some standards body had written down how JSON was supposed to work and that if I wanted to claim I was using JSON I would have to comply with that specification.

However, I today received a bug report indicating that a project to which I contribute was unable to make HTTP requests your Google Flights website could understand. I found this perplexing, but my eyes were opened when I saw your HTTP request. In particular, I enjoyed your freeform and inclusive definition of JSON. Allow me to show you what you've called JSON by showing you my SPDY request:

:host:www.google.fr
@Lukasa
Lukasa / tash.py
Last active August 29, 2015 13:57
import itertools
def blocks(size, total_sum):
def ascending(iterable):
last = 0
for elem in iterable:
if elem < last:
return False
last = elem
return True