From abb84eb055c259323ece64fcf4ee08f9741829e9 Mon Sep 17 00:00:00 2001 From: pbsds Date: Fri, 8 Apr 2016 01:27:33 +0200 Subject: [PATCH] quick n' dirty fix for a Twisted update which broke the proxy hack --- hatenadir/ds/v2-xx/help/info.htm | 2 +- server.py | 32 ++++++++++++++++++++------------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/hatenadir/ds/v2-xx/help/info.htm b/hatenadir/ds/v2-xx/help/info.htm index d5baee7..5cded24 100644 --- a/hatenadir/ds/v2-xx/help/info.htm +++ b/hatenadir/ds/v2-xx/help/info.htm @@ -1 +1 @@ - Info
pbsds's Hatena Server

This is a work in progress! There's not much functionality yet because it's still in early stages. Please enjoy your stay.

\ No newline at end of file + Info
pbsds's Hatena Server

This server is a proof of concept server. There's not much functionality yet because it's in early stages. Please enjoy your stay.

\ No newline at end of file diff --git a/server.py b/server.py index 1c5c88f..a2bc1ab 100644 --- a/server.py +++ b/server.py @@ -113,22 +113,30 @@ print "Done!" #make the hatena server accept proxy connections: print "Setting up proxy hack...", silent = True -old_lineReceived = site.protocol.lineReceived -def lineReceived(self, line): - if not silent: print line - if line[:31] == "GET http://flipnote.hatena.com/": - line = "GET " + line[30:] - if not silent: print line - elif line[:32] == "POST http://flipnote.hatena.com/": - line = "POST " + line[31:] - if not silent: print line - old_lineReceived(self, line) -site.protocol.lineReceived = lineReceived +old_buildProtocol = site.buildProtocol +def buildProtocol(self, addr): + protocol = old_buildProtocol(addr) + + protocol.new_recv_buffer= [] + + old_dataReceived = protocol.dataReceived + def dataReceived(self, data): + #i'll assume the GET request doesn't get fragmented, which should be safe with a mtu at 1500, a crash doesn't matter really anyway. too much work for a simple twisted upgrade on a dropped project + for check, repl in (("GET http://flipnote.hatena.com", "GET "), ("POST http://flipnote.hatena.com", "POST ")): + if check in data: + data = data.replace(check, repl) + old_dataReceived(data) + funcType = type(protocol.dataReceived) + protocol.dataReceived = funcType(dataReceived, protocol, protocol.__class__) + return protocol +funcType = type(site.buildProtocol) +site.buildProtocol = funcType(buildProtocol, site, server.Site) print "Done!" #run! print "Server start!\n" if useWSGI: + #probably doesn't work application = service.Application('web') sc = service.IServiceCollection(application) internet.TCPServer(port, site).setServiceParent(sc) @@ -139,4 +147,4 @@ else: reactor.run() #dunn - Log.write("Server shutdown", True) \ No newline at end of file + Log.write("Server shutdown", True)