Last active
August 14, 2019 04:01
-
-
Save willfarrell/db47fd0c85d80ca61822d82f8a1a4ee7 to your computer and use it in GitHub Desktop.
Revisions
-
willfarrell revised this gist
Aug 14, 2019 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -21,6 +21,10 @@ from twisted.python import log class WebServer(File): def getChild(self, path, request): request.responseHeaders.setRawHeaders('Cache-Control', ['max-age=31557600']) request.responseHeaders.setRawHeaders('server', ['']) child = File.getChild(self, path, request) return EncodingResourceWrapper(child, [GzipEncoderFactory()]) -
willfarrell created this gist
Aug 14, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ # localhost.py # # brew install mkcert python3 # mkcert -install # > Add cert to trusted keychain # mkcert localhost 127.0.0.1 ::1 # # pip3 install service_identity pyopenssl twisted[http2] # # DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" # python3 localhost.py 8080 $DIR import sys from twisted.web.server import Site, GzipEncoderFactory from twisted.web.resource import Resource, EncodingResourceWrapper from twisted.web.static import File from twisted.internet import reactor from twisted.internet import endpoints from twisted.python import log class WebServer(File): def getChild(self, path, request): child = File.getChild(self, path, request) return EncodingResourceWrapper(child, [GzipEncoderFactory()]) if __name__ == "__main__": log.startLogging(sys.stdout) resource = WebServer('./') site = Site(resource) endpoint_spec = 'ssl:port={0}:privateKey={1}/localhost+1.pem:certKey={1}/localhost+1-key.pem'.format(sys.argv[1], sys.argv[2]) server = endpoints.serverFromString(reactor, endpoint_spec) server.listen(site) reactor.run()