简体   繁体   中英

How to modify incoming HTTPS and HTTP requests with python3

I am currently looking to create a python script that looks at incoming HTTP or HTTPS traffic and changes it. This needs to be 100% automatic. This will run on my local computer. I need something like this:

def Change(request):
    #Get all incoming HTTPS and HTTP traffic
    #Change the request


while true:
    #Get all incoming HTTPS and HTTP traffic
    Change(request)

This obviously would be more complicated than that. I need to change website html when a user is connecting to a page. For example change a incoming html file from this:

<form action="/example.php">
  First name:<br>
  <input type="text" name="firstname" value="Bob"><br>
  Last name:<br>
  <input type="text" name="lastname" value="Mc Bob"><br><br>
  <input type="submit" value="Submit">
</form>

To

<title>Hey</title>
<form action="/example.php">
  First name:<br>
  <input type="text" name="firstname" value="Bob"><br>
  Last name:<br>
  <input type="text" name="lastname" value="Mc Bob"><br><br>
  <input type="submit" value="Submit">
</form>

Thanks, sorry if I messed up the code a little bit I am still learning.

Are you looking for something like this?

from functools import wraps

def request_decorator(view_func):
    def _decorator(request, *args, **kwargs):
        # do something with request before the view_func call
        response = view_func(request, *args, **kwargs)
        return response
    return wraps(view_func)(_decorator)

# Use it like this
@request_decorator
def foo(request): 
    return HttpResponse('...')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM