Skip to content

Instantly share code, notes, and snippets.

@javierluraschi
Created January 24, 2020 00:13
Show Gist options
  • Save javierluraschi/d1dbd8a37a18bdd1fa26b0af91daa72a to your computer and use it in GitHub Desktop.
Save javierluraschi/d1dbd8a37a18bdd1fa26b0af91daa72a to your computer and use it in GitHub Desktop.
Simple Proxy Variations
import SimpleHTTPServer
import BaseHTTPServer
def main():
request_handler = SimpleHTTPServer.SimpleHTTPRequestHandler
request_handler.server_version = "Jetty(8.y.z-SNAPSHOT)"
request_handler.sys_version = ""
BaseHTTPServer.test(HandlerClass = request_handler, ServerClass = BaseHTTPServer.HTTPServer)
if __name__ == "__main__":
main()
import SocketServer
import SimpleHTTPServer
import urllib
class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_my_headers()
SimpleHTTPServer.SimpleHTTPRequestHandler.end_headers(self)
def send_my_headers(self):
self.send_header("Date", "Thu, 23 Jan 2020 23:57:57 GMT")
def do_GET(self):
print(self.path)
self.copyfile(urllib.urlopen("http://localhost:4042" + self.path), self.wfile)
httpd = SocketServer.ForkingTCPServer(('', 9002), Proxy)
httpd.serve_forever()
> browseURL(paste0("../", rstudioapi::translateLocalUrl("http://localhost:9002/jobs/")))
24 Jan 2020 00:07:48 [rsession-rstudio-admin] ERROR asio.misc error 2 (End of file); OCCURRED AT: void rstudio::core::http::AsyncClient<SocketService>::handleReadStatusLine(const rstudio_boost::system::error_code&) [with SocketService = rstudio_boost::asio::basic_stream_socket<rstudio_boost::asio::ip::tcp>] /var/lib/jenkins/workspace/IDE/pro-pipeline/v1.2-patch/src/cpp/core/include/core/http/AsyncClient.hpp:457; LOGGED FROM: void rstudio::session::session_proxy::{anonymous}::SessionProxy::handleLocalhostError(rstudio_boost::shared_ptr<rstudio::core::http::AsyncConnection>, const rstudio::core::Error&) /var/lib/jenkins/workspace/IDE/pro-pipeline/v1.2-patch/src/cpp/session/http/SessionProxy.cpp:121
browseURL(paste0("../", rstudioapi::translateLocalUrl("http://localhost:9002/jobs/")))
curl -I localhost:4042/jobs/

sudo python -m RedirectHTTPServer
sudo python -m SparkHTTPServer 9001
#!/usr/bin/env python
import SimpleHTTPServer
class MyHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_my_headers()
SimpleHTTPServer.SimpleHTTPRequestHandler.end_headers(self)
def send_my_headers(self):
self.send_header("Server", "Jetty(8.y.z-SNAPSHOT)")
if __name__ == '__main__':
SimpleHTTPServer.test(HandlerClass=MyHTTPRequestHandler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment