Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 359174

Summary: RedirectListener sends wrong Host header for cross-host redirect
Product: [RT] Jetty Reporter: David Kellum <dek94>
Component: clientAssignee: Jesse McConnell <jesse.mcconnell>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jetty-inbox
Version: unspecified   
Target Milestone: 7.5.x   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
patch jesse.mcconnell: iplog+

Description David Kellum CLA 2011-09-28 00:23:22 EDT
Build Identifier: 7.4.5-7.5.1

For example, with RedirectListener enabled:

request 1 to: http://foo.com/index
GET /index
Host: foo.com

response with redirect:
HTTP 1.1 OK 301
Location: http://bar.com/foo

request 2 to: http://bar.com/foo (via RedirectListener):
GET /foo
Host: foo.com

This is wrong. The following Host should be sent on the 2nd request:

Host: bar.com

This causes a good number of sites to fail with 404 Not Found (i.e. virtual host configs) or 30x (another redirect with the same Location).

I was able to fix this by adding the following to RedirectListener.checkExchangeComplete, in the destination not equal condition branch:

    // Fixup the Host header
    Address adr = _exchange.getAddress();
    int port = adr.getPort();
    StringBuilder hh = new StringBuilder( 64 );
    hh.append( adr.getHost() );
    if( !( ( port == 80  && !isHttps ) ||
           ( port == 443 &&  isHttps ) ) ) {
        hh.append( ':' );
        hh.append( port );
    }
    _exchange.setRequestHeader( HttpHeaders.HOST, hh.toString() );

This is copied from


Reproducible: Always
Comment 1 David Kellum CLA 2011-09-28 00:25:17 EDT
Created attachment 204140 [details]
patch
Comment 2 David Kellum CLA 2011-09-28 00:26:02 EDT
This is a mirror of https://jira.codehaus.org/browse/JETTY-1420
Comment 3 Jesse McConnell CLA 2011-09-28 11:37:20 EDT
applied, thanks for going through the hassle