Bug 17050: (QA followup) Use Mojo::Transaction to get the remote address
authorTomas Cohen Arazi <tomascohen@theke.io>
Fri, 19 Aug 2016 17:59:04 +0000 (14:59 -0300)
committerKyle M Hall <kyle@bywatersolutions.com>
Tue, 23 Aug 2016 13:45:07 +0000 (13:45 +0000)
commitadbcaa99f4f1a0dc3c739cb15b4d3039d2a79c9e
treef02650f8d48be04c61b85cc7c8b2ea0e9c3055fa
parentb5fc3d29373d2b6eecd9f3d26c798d603dae7d84
Bug 17050: (QA followup) Use Mojo::Transaction to get the remote address

While the original patch fixes the issue, reading at Mojolicious source code, revealed
that Mojo::Transaction already has proper processing for detecting the remote address:

sub remote_address {
  my $self = shift;

  return $self->original_remote_address(@_) if @_;
  return $self->original_remote_address unless $self->req->reverse_proxy;

  # Reverse proxy
  return ($self->req->headers->header('X-Forwarded-For') // '') =~ /([^,\s]+)$/
    ? $1
    : $self->original_remote_address;
}

Without this patch, if there's a request without HTTP_X_FORWARDED_FOR, then the remote
address would be empty. Such would be the case of a dev/standard setup without Plack.

This patch makes Koha::REST::V1::startup use tx->remote_address instead of dealing with the
headers on its own.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Benjamin Rokseth <benjamin.rokseth@kul.oslo.kommune.no>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Koha/REST/V1.pm