Skip to content

Instantly share code, notes, and snippets.

@mhils
Created June 2, 2015 12:31
Show Gist options
  • Select an option

  • Save mhils/571888c72daa4fc2fc38 to your computer and use it in GitHub Desktop.

Select an option

Save mhils/571888c72daa4fc2fc38 to your computer and use it in GitHub Desktop.
import socket
from libmproxy.script import concurrent
from libmproxy.protocol.http import decoded
cache = dict()
def has_ssl(host):
if not host in cache:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((host, 443))
cache[host] = True
except socket.error:
cache[host] = False
finally:
s.close()
print "ssl for {}: {}".format(host, cache[host])
return cache[host]
@concurrent
def request(context, flow):
if has_ssl(flow.request.host) and flow.request.scheme == "http":
print "rewriting"
flow.request.scheme = "https"
flow.request.port = 443
def response(context, flow):
del flow.response.headers["Strict-Transport-Security"]
with decoded(flow.response):
flow.response.content = flow.response.content.replace("https", "http")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment