Skip to content

Instantly share code, notes, and snippets.

View Lukasa's full-sized avatar

Cory Benfield Lukasa

View GitHub Profile
@Lukasa
Lukasa / README.md
Last active August 29, 2015 13:56
HTTP/1.1 and HTTP/2.0 test

The plan here is to investigate the network efficiency of HTTP/2.0 versus HTTP/1.1 by gently hitting Twitter's API. The above script does 5 HTTP requests to Twitter and gets the responses.

In my tests I'm showing an insane different, whereby HTTP/2.0 transfers 250 kB of data and HTTP/1.1 transfers 2.2 MB. This difference seems insane to me, so I'd like to work out why it's happening.

To run this, you'll need Python 3.3. Install the requirements listed in requirements.txt, and then go to Twitter's API page and set up an application. Get the values listed in the script for your application, fill them in, and run them, using Wireshark to check how much traffic was sent. Let me know what you find!

@Lukasa
Lukasa / keybase.md
Created March 7, 2014 20:18
Keybase proof

Keybase proof

I hereby claim:

  • I am Lukasa on github.
  • I am lukasa (https://keybase.io/lukasa) on keybase.
  • I have a public key whose fingerprint is 90DC AE40 FEA7 4B14 9B70 662D F25F 2144 EEC1 373D

To claim this, I am signing this object:

@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
@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 / 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 / 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 / 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 / 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 / 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 / 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)