Created
June 2, 2015 12:31
-
-
Save mhils/571888c72daa4fc2fc38 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| 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