Skip to content

Commit

Permalink
Merge pull request #447 from danielgtaylor/ctx-remote-addr
Browse files Browse the repository at this point in the history
feat: add request remote address to context
  • Loading branch information
danielgtaylor committed May 20, 2024
2 parents 1b6a3e5 + 48c4d1a commit b318810
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions adapters/humabunrouter/humabunrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func (c *bunContext) Host() string {
return c.r.Host
}

func (c *bunContext) RemoteAddr() string {
return c.r.RemoteAddr
}

func (c *bunContext) URL() url.URL {
return *c.r.URL
}
Expand Down Expand Up @@ -131,6 +135,10 @@ func (c *bunCompatContext) Host() string {
return c.r.Host
}

func (c *bunCompatContext) RemoteAddr() string {
return c.r.RemoteAddr
}

func (c *bunCompatContext) URL() url.URL {
return *c.r.URL
}
Expand Down
4 changes: 4 additions & 0 deletions adapters/humachi/humachi.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func (c *chiContext) Host() string {
return c.r.Host
}

func (c *chiContext) RemoteAddr() string {
return c.r.RemoteAddr
}

func (c *chiContext) URL() url.URL {
return *c.r.URL
}
Expand Down
4 changes: 4 additions & 0 deletions adapters/humaecho/humaecho.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func (c *echoCtx) Host() string {
return c.orig.Request().Host
}

func (c *echoCtx) RemoteAddr() string {
return c.orig.Request().RemoteAddr
}

func (c *echoCtx) URL() url.URL {
return *c.orig.Request().URL
}
Expand Down
4 changes: 4 additions & 0 deletions adapters/humafiber/humafiber.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func (c *fiberCtx) Host() string {
return c.orig.Hostname()
}

func (c *fiberCtx) RemoteAddr() string {
return c.orig.Context().RemoteAddr().String()
}

func (c *fiberCtx) URL() url.URL {
u, _ := url.Parse(string(c.orig.Request().RequestURI()))
return *u
Expand Down
4 changes: 4 additions & 0 deletions adapters/humaflow/humaflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func (c *goContext) Host() string {
return c.r.Host
}

func (c *goContext) RemoteAddr() string {
return c.r.RemoteAddr
}

func (c *goContext) URL() url.URL {
return *c.r.URL
}
Expand Down
4 changes: 4 additions & 0 deletions adapters/humagin/humagin.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func (c *ginCtx) Host() string {
return c.orig.Request.Host
}

func (c *ginCtx) RemoteAddr() string {
return c.orig.Request.RemoteAddr
}

func (c *ginCtx) URL() url.URL {
return *c.orig.Request.URL
}
Expand Down
4 changes: 4 additions & 0 deletions adapters/humago/humago.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func (c *goContext) Host() string {
return c.r.Host
}

func (c *goContext) RemoteAddr() string {
return c.r.RemoteAddr
}

func (c *goContext) URL() url.URL {
return *c.r.URL
}
Expand Down
4 changes: 4 additions & 0 deletions adapters/humahttprouter/humahttprouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func (c *httprouterContext) Host() string {
return c.r.Host
}

func (c *httprouterContext) RemoteAddr() string {
return c.r.RemoteAddr
}

func (c *httprouterContext) URL() url.URL {
return *c.r.URL
}
Expand Down
4 changes: 4 additions & 0 deletions adapters/humamux/humamux.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func (c *gmuxContext) Host() string {
return c.r.Host
}

func (c *gmuxContext) RemoteAddr() string {
return c.r.RemoteAddr
}

func (c *gmuxContext) URL() url.URL {
return *c.r.URL
}
Expand Down
3 changes: 3 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ type Context interface {
// Host returns the HTTP host for the request.
Host() string

// RemoteAddr returns the remote address of the client.
RemoteAddr() string

// URL returns the full URL for the request.
URL() url.URL

Expand Down

0 comments on commit b318810

Please sign in to comment.