Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_request_header clobbers 'Host' header setting #19

Closed
meuserj opened this issue Nov 9, 2009 · 1 comment
Closed

set_request_header clobbers 'Host' header setting #19

meuserj opened this issue Nov 9, 2009 · 1 comment
Labels

Comments

@meuserj
Copy link

meuserj commented Nov 9, 2009

If you provide a Host header entry, set_request_header will ignore it and assume that the hostname in the URI is the correct one. This is normally a good assumption, except when you are accessing a virtualhost without going through DNS.

This simple change fixes it:

def set_request_header
  return if @dumped
  @dumped = true
  keep_alive = Message.keep_alive_enabled?(@http_version)
  if !keep_alive and @request_method != 'CONNECT'
    set('Connection', 'close')
  end
  if @chunked
    set('Transfer-Encoding', 'chunked')
  elsif @body_size and (keep_alive or @body_size != 0)
    set('Content-Length', @body_size.to_s)
  end
  if @http_version >= 1.1
    if (h = get('Host')).length > 0
      host = h.flatten.last
    else
      host = @request_uri.host
    end
    if @request_uri.port == @request_uri.default_port
      # GFE/1.3 dislikes default port number (returns 404)
      set('Host', "#{host}")
    else
      set('Host', "#{host}:#{@request_uri.port}")
    end
  end
end
@nahi
Copy link
Owner

nahi commented Dec 2, 2009

Do not override given Host header. closed by 58bde3a.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants