Created
March 8, 2016 05:58
-
-
Save davidfstr/0dca5a133fa397cadd92 to your computer and use it in GitHub Desktop.
requests: Request header ordering test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import OrderedDict | |
import requests | |
try: | |
requests.get( | |
'http://127.0.0.1:8765/', | |
headers=OrderedDict([ | |
('X-Header-1', 'ignoreme'), | |
('X-Header-2', 'ignoreme'), | |
('X-Header-3', 'ignoreme'), | |
('X-Header-4', 'ignoreme'), | |
]) | |
) | |
except requests.exceptions.ConnectionError: | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
HOST = '' | |
PORT = 8765 | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
try: | |
print('Socket created') | |
s.bind((HOST, PORT)) | |
print('Socket bind complete') | |
s.listen(10) | |
print('Socket now listening') | |
while True: | |
conn, addr = s.accept() | |
print('Client connected at %s' % (addr,)) | |
try: | |
data = conn.recv(1024 * 16) | |
print(data.decode('utf8')) | |
finally: | |
conn.close() | |
print('Client disconnected') | |
finally: | |
s.shutdown() | |
s.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment