Coverage for hookee/plugins/request_headers.py: 100.00%

1 from hookee.pluginmanager import REQUEST_PLUGIN

2 from hookee.util import PrintUtil

3

4 __author__ = "Alex Laird"

5 __copyright__ = "Copyright 2023, Alex Laird"

6 __version__ = "1.2.2"

7

8 plugin_type = REQUEST_PLUGIN

9 description = "Print the `request`'s headers, if defined."

10

11 print_util = None # type: PrintUtil

12

13

14 def setup(hookee_manager):

15 global print_util

16

17 print_util = hookee_manager.print_util

18

19

20 def run(request):

21 if request.headers and "X-Forwarded-For" in request.headers:

22 print_util.print_basic("Client IP: {}".format(request.headers.get("X-Forwarded-For")),

23 color=print_util.request_color)

24 if request.headers:

25 print_util.print_dict("Headers", dict(request.headers), color=print_util.request_color)

26

27 return request