Skip to content

Commit

Permalink
⚡️ refactor: better parse address
Browse files Browse the repository at this point in the history
  • Loading branch information
balcieren committed Sep 6, 2022
1 parent 9b6d62d commit 871faf5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ctx.go
Expand Up @@ -618,12 +618,13 @@ func (c *Ctx) Host() string {
func (c *Ctx) Hostname() string {
if c.IsProxyTrusted() {
if host := c.Get(HeaderXForwardedHost); len(host) > 0 {
return strings.Split(host, ":")[0]
addr, _ := parseAddr(c.Host())
return addr
}
}

hn := utils.UnsafeString(c.fasthttp.Host())
return strings.Split(hn, ":")[0]
addr, _ := parseAddr(c.Host())
return addr
}

// Port returns the remote port of the request.
Expand Down

1 comment on commit 871faf5

@ReneWerner87
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 871faf5 Previous: e3282f6 Ratio
Benchmark_Ctx_Protocol 22.66 ns/op 0 B/op 0 allocs/op 2.47 ns/op 0 B/op 0 allocs/op 9.17

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.