Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook for internal response #8

Open
GoogleCodeExporter opened this issue Sep 27, 2015 · 0 comments
Open

Hook for internal response #8

GoogleCodeExporter opened this issue Sep 27, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

I want to trigger a response in my proxy_mangle_request, this is what I came up 
with to support it. I'm used to working with F5 iRules, so far this seems to be 
the most light weight yet powerful open source alternative for that sort of 
thing.

I don't want to clutter up your beautiful code with my hacks, just looking for 
some advice. Is there any side effect that I may be missing? I'm a python 
newbie. Literally, zero exposure to python until now. This library is so tidy, 
even I (think) I can understand how it works though.

So in "class HTTPRequest", "def __init__" block, I added...

         self.response_hook = False

In "class ProxyHandler", end of "def handle" block...

        if req.response_hook == False:
          # if you need a persistent connection set the flag in order to save the status
          if req.isKeepAlive():
              self.keepalive = True
          else:
              self.keepalive = False

          # Target server host and port
          host, port = ProxyState.getTargetHost(req)

          if req.getMethod() == HTTPRequest.METHOD_GET:
              res = self.doGET(host, port, req)
              self.sendResponse(res)
          elif req.getMethod() == HTTPRequest.METHOD_POST:
              res = self.doPOST(host, port, req)
              self.sendResponse(res)
          elif req.getMethod() == HTTPRequest.METHOD_CONNECT:
              res = self.doCONNECT(host, port, req)
        else:
          self.sendResponse(req.response_hook)


This allows me to do stuff like this in my proxy_mangle_request function, which 
seems to work well...

        hdr = ["Content-Type: text/html", "Server: ProxPy"]
        res = HTTPResponse("HTTP/1.1", 200, "OK", hdr,"<h1>HELLOWORLD</h1>")
        req.response_hook = res.serialize()

I probably need to stick some more headers in there, but other than that have I 
missed anything?

Original issue reported on code.google.com by Krustov...@gmail.com on 10 Jun 2014 at 1:00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant