Patch: Add X-Reproxy-Host

Logan Bowers logan.bowers at gmail.com
Thu May 29 01:56:44 UTC 2008


(sorry if ya'll receive this message twice, I'm having trouble sending  
to the list)

I have run into a limitation with Perlbal's handling of handling of  
the Host header during a reproxy.  On reproxy, Perlbal sends the host  
header from the original request, not the host specified in the  
reproxy URL.  This makes it impossible to redirect to a vhost other  
than the one the targeted by the original request.  To work around  
this problem, I've attached a patch that adds support for a new  
header: X-Reproxy-Host.  If it exists in the reproxy response, the  
value overrides the host header of the client request.


Logan Bowers

Index: lib/Perlbal/ClientProxy.pm
===================================================================
--- lib/Perlbal/ClientProxy.pm	(revision 771)
+++ lib/Perlbal/ClientProxy.pm	(working copy)
@@ -29,6 +29,8 @@
                                   # and the headers we get back  
aren't necessarily
                                   # the ones we want.  instead, get  
most headers
                                   # from the provided res headers  
object here.
+            'reproxy_host_hdr',  #if defined, we are doing a  
transparent reproxy and the
+                                   #reproxy response included an X- 
REPROXY-HOST header
              'is_buffering',        # bool; if we're buffering some/ 
all of a request to memory/disk
              'is_writing',          # bool; if on, we currently have  
an aio_write out
              'start_time',          # hi-res time when we started  
getting data to upload
@@ -140,6 +142,7 @@
      my Perlbal::ClientProxy $self = $_[0];
      my Perlbal::HTTPHeaders $primary_res_hdrs = $_[1];
      my $urls = $_[2];
+    my $host_hdr = $_[3];

      # at this point we need to disconnect from our backend
      $self->{backend} = undef;
@@ -157,6 +160,7 @@
              push @{$self->{reproxy_uris}}, [ $1, $2 || 80, $3 ||  
'/' ];
          }
      }
+    $self->{reproxy_host_hdr} ||= $host_hdr;

      # if we get in here and we have currently_reproxying defined,  
then something
      # happened and we want to retry that one
@@ -230,7 +234,7 @@
      if (my $range = $self->{req_headers}->header("Range")) {
          $extra_hdr .= "Range: $range\r\n";
      }
-    if (my $host = $self->{req_headers}->header("Host")) {
+    if (my $host = ($self->{reproxy_host_hdr} || $self->{req_headers}- 
 >header("Host"))) {
          $extra_hdr .= "Host: $host\r\n";
      }

@@ -465,6 +469,7 @@
      $self->{currently_reproxying} = undef;
      $self->{content_length_remain} = undef;
      $self->{primary_res_hdrs} = undef;
+    $self->{reproxy_host_hdr} = undef;
      $self->{responded} = 0;
      $self->{is_buffering} = 0;
      $self->{is_writing} = 0;
Index: lib/Perlbal/BackendHTTP.pm
===================================================================
--- lib/Perlbal/BackendHTTP.pm	(revision 771)
+++ lib/Perlbal/BackendHTTP.pm	(working copy)
@@ -466,7 +466,7 @@
      } elsif ((my $urls = $hd->header('X-REPROXY-URL')) && $self- 
 >may_reproxy) {
          $self->{service}->add_to_reproxy_url_cache($rqhd, $hd)
              if $reproxy_cache_for;
-        $client->start_reproxy_uri($self->{res_headers}, $urls);
+        $client->start_reproxy_uri($self->{res_headers}, $urls,$hd- 
 >header('X-REPROXY-HOST'));
          $self->next_request;
          return;
      } elsif ((my $svcname = $hd->header('X-REPROXY-SERVICE')) &&  
$self->may_reproxy) {



More information about the perlbal mailing list