koding / tunnel

Tunnel proxy package in Go
BSD 3-Clause "New" or "Revised" License
314 stars 70 forks source link

Http host and port provisioning with X-Forwarded headers #17

Closed mmatczuk closed 8 years ago

mmatczuk commented 8 years ago

A server modification that allows http tunneling to any port using X-Forwarded-Port http header. X-Forwarded-Host is also supported for host overwriting.

mmatczuk commented 8 years ago

1.5 race check failure is not related to the submitted code, what should I do?

cihangir commented 8 years ago

cc @rjeczalik

rjeczalik commented 8 years ago

@mmatczuk The races are going to be fixed with #19. You caught us having red master, not good.

Regarding this feature, could we have instead what Go stdlib is doing for httputil.ReverseProxy, that is to add Director field:

// ServerConfig ...
type ServerConfig struct {
    ...

    // Director ...
    Director func(*http.Request)

    ...
}

And then call it here, if non-nil.

Then you can pass your custom Director function that overwrites r.Host with X-Forwarded-Host:X-Forwarded-Port. I think this would be more flexible than hardcoding this logic.

What do you think?

mmatczuk commented 8 years ago

This would make code more flexible indeed. I'll update PR soon.

mmatczuk commented 8 years ago

I removed X-Forwarded logic from this commit to keep tunnel simple. It's now available as a director here.

rjeczalik commented 8 years ago

@mmatczuk :+1: