Skip to content

Commit

Permalink
Merge pull request #198 from greatest-ape/fix-http-peer-addr
Browse files Browse the repository at this point in the history
http: don't require peer addr to have been set in send_response
  • Loading branch information
greatest-ape authored Apr 13, 2024
2 parents 39c763f + 3e7ad2a commit e0c0dd7
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions crates/http/src/workers/socket/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ struct Connection<S> {
request_senders: Rc<Senders<ChannelRequest>>,
valid_until: Rc<RefCell<ValidUntil>>,
server_start_instant: ServerStartInstant,
// If we're running behind a reverse proxy, gets set as soon as we get a
// valid requiest. Otherwise, must be set before calling `run`.
opt_peer_addr: Option<CanonicalSocketAddr>,
peer_port: u16,
request_buffer: Box<[u8; REQUEST_BUFFER_SIZE]>,
Expand Down Expand Up @@ -441,14 +443,20 @@ where
Response::Failure(_) => "error",
};

let peer_addr = self
// If we're behind a reverse proxy and we're sending an error
// response due to failing to parse a request, opt_peer_addr might
// not yet be set (and in that case, we don't know if the true peer
// connects over IPv4 or IPv6)
let ip_version_str = self
.opt_peer_addr
.expect("peer addr should already have been extracted by now");
.as_ref()
.map(peer_addr_to_ip_version_str)
.unwrap_or("?");

::metrics::counter!(
"aquatic_responses_total",
"type" => response_type,
"ip_version" => peer_addr_to_ip_version_str(&peer_addr),
"ip_version" => ip_version_str,
"worker_index" => self.worker_index_string.clone(),
)
.increment(1);
Expand Down

0 comments on commit e0c0dd7

Please sign in to comment.