Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better documentation, allow callbacks, ignore all local networks. Fixes part of #10
- Loading branch information
Showing
8 changed files
with
708 additions
and
544 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# mitmproxy <https://mitmproxy.org> addon to serve count.js locally, instead of | ||
# the live version. It's the easiest way to test it manually for now (I need to | ||
# figure out how to unit test this stuff in a way that I like). | ||
# | ||
# Start with: ~/mitproxy -s ./proxy | ||
# | ||
# Can also use mitmweb with the same arguments for a web interface. | ||
# | ||
# TODO: looks like we can also use standard "replace" with "@path/to/file"? | ||
|
||
import mimetypes | ||
import mitmproxy.http | ||
import mitmproxy.ctx | ||
|
||
REPLACE = { | ||
'static.goatcounter.com/count.min.js': './public/count.js', | ||
'zgo.at/': '../zgo.at/index.html', | ||
} | ||
|
||
class InterceptCount: | ||
def request(self, flow): | ||
for remote, local in REPLACE.items(): | ||
if remote in flow.request.pretty_url: | ||
with open(local) as fp: | ||
data = fp.read() | ||
ct = mimetypes.MimeTypes().guess_type(local)[0] | ||
flow.response = mitmproxy.http.HTTPResponse.make(200, data, { | ||
'Content-Type': ct, | ||
}) | ||
mitmproxy.ctx.log.info('Replaced {} with {} ({})'.format(remote, local, ct)) | ||
break | ||
|
||
|
||
addons = [InterceptCount()] |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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