wsrepl icon indicating copy to clipboard operation
wsrepl copied to clipboard

Add method for plugin to set HTTP headers

Open chovanecadam opened this issue 1 year ago • 1 comments

Hi. This MR adds a method for plugins to set HTTP headers on connection.

Proposed changes

The function generate_headers is called every time a new websocket connection is initialized and the headers are added after headers set on the command line. The plugin can keep state and change the headers for every new connection (e.g. set X-Forwarded-For to a new value, or update some token), which wasn't possible until now.

What remains to be done

The diagram in the repository should be updated. It would be great if the source of the diagram was in the repository too with instructions on how to generate it. Could you share the source of the diagram please?

Before writing more docs I would like to hear your thoughts on the change. Thanks for the tool, it's great.

chovanecadam avatar Jul 24 '24 11:07 chovanecadam

An example use-case:

class MyPlugin(Plugin):
    def init(self):
        self.random_ips = iter(ipaddress.IPv4Network("10.0.0.0/8"))

    def headers_callback(self):
        return [f"X-Forwarded-For: {next(self.random_ips)}"]

chovanecadam avatar Jul 24 '24 11:07 chovanecadam