Skip to content

Commit

Permalink
Merge pull request #6 from aperim/5-use-_pre_dispatch-instead
Browse files Browse the repository at this point in the history
Using pre
  • Loading branch information
troykelly authored Mar 29, 2023
2 parents 1a54887 + acff8b1 commit 7c843e0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Odoo's support for proxying and/or load balancing is broken, this add-on is a te

Odoo is incorrectly configured to handle an instance behind a load balancer or proxy. This Odoo addon looks for the presence of a `X-Forwarded-For` header and sets both the `HTTP_X_FORWARDED_FOR` and `REMOTE_ADDR` environ variables to allow Odoo to correctly parse and store the users real remote IP address.

## Odoo 16 Only

Because of changes in how Odoo handles request - this module supports Version 16 only.

## Getting Started

### DANGER
Expand Down
4 changes: 2 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class IrHttp(models.AbstractModel):
_inherit = "ir.http"

@classmethod
def _dispatch(cls, endpoint):
def _pre_dispatch(cls, rule, args):
# This is a hack to fix real ip detection when multiple hops are added in XFF header (eg. Traefik)
if "X-Forwarded-For" in request.httprequest.headers:
real_ip = request.httprequest.headers["X-Forwarded-For"].split(',')[0]
Expand All @@ -26,4 +26,4 @@ def _dispatch(cls, endpoint):
"X-Forwarded-For header found, setting REMOTE_ADDR and HTTP_X_FORWARDED_FOR to %s",
real_ip,
)
return super()._dispatch(endpoint)
return super()._pre_dispatch(rule, args)

0 comments on commit 7c843e0

Please sign in to comment.