Repository navigation
Proxy to unix: socket - #467
Conversation
There was a problem hiding this comment.
Below, you're checking for a "unix:" prefix - I suppose that a url parse somewhere converts it so the prefix is "unix://" ?
There was a problem hiding this comment.
Yes, it does. That line could use a comment. I discovered that by accident.
|
Cool, looks like a great start. :) |
|
How's this coming, @eiszfuchs ? Once there are some tests we can get this into the next release. |
|
Oh! Hey! Sorry, I needed some days of rest over the holidays. I might be able to write tests this or next week, but regarding Windows support, I'd be completely lost. |
|
That sounds good to me! I wouldn't expect Windows to support them. |
|
Hm. I've had a look at the existing tests as of now, and since my changes mostly affected |
|
With these changes so far, code coverage is: So all that really needs to be tested is that creating a proxy with a unix socket works. I just realized we don't have a test case for a proxy on a regular socket (other than testing the WebSocket proxying in proxy_test.go), so this will knock out two birds with one stone. 😄 Basically, create a new |
|
Hello again. func TestUnixSocketProxy(t *testing.T) {
var proxySuccess bool
ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
proxySuccess = true
}))
ln, err := net.Listen("unix", "/Users/eiszfuchs/socket_test")
if err != nil {
t.Fatalf("Unable to listen: %v", err)
}
ts.Listener = ln
ts.Start()
defer ts.Close()
// TODO: Create client/connection and check response
if !proxySuccess {
t.Fatal("Expected request to be proxied, but it wasn't")
}
}I think I still don't quite get what I am actually checking. |
|
@eiszfuchs Good work! You don't need to use an absolute path for the unix socket, right? Will a relative path work? If so, just put it in the cwd or something and delete it when done. All that's left otherwise is to use CreateSingleHostReverseProxy to run the test. |
|
Ahoy! func TestUnixSocketProxy(t *testing.T) {
trialMsg := "Is it working?"
var proxySuccess bool
ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
proxySuccess = true
fmt.Fprint(w, trialMsg)
}))
socketPath, err := filepath.Abs("./test_socket")
if err != nil {
t.Fatalf("Unable to get absolute path: %v", err)
}
ln, err := net.Listen("unix", socketPath)
if err != nil {
t.Fatalf("Unable to listen: %v", err)
}
ts.Listener = ln
ts.Start()
defer ts.Close()
url := strings.Replace(ts.URL, "http://", "unix:", 1)
p := newWebSocketTestProxy(url)
echoProxy := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
p.ServeHTTP(w, r)
}))
defer echoProxy.Close()
res, err := http.Get(echoProxy.URL)
if err != nil {
t.Fatalf("Unable to GET: %v", err)
}
greeting, err := ioutil.ReadAll(res.Body)
res.Body.Close()
if err != nil {
t.Fatalf("Unable to GET: %v", err)
}
if !proxySuccess {
t.Fatal("Expected request to be proxied, but it wasn't")
}
actualMsg := fmt.Sprintf("%s", greeting)
if actualMsg != trialMsg {
t.Errorf("Expected '%s' but got '%s' instead", trialMsg, actualMsg)
}
}And the best part is: It covers the right code now! |
|
That looks good! Last things to do:
And I'll merge it in. |
|
Yuk. I'm making a mess. Will rebase my branch. |
b4f405e to
99fa101
Compare
|
Oh man, that was a lot of work. I start to figure out how to rebase, though. |
|
Awesome, almost done! Just gotta get those tests passing in Windows. Since users won't be using Unix sockets on Windows we can just run the test if the OS isn't Windows. At the top of the test: if runtime.GOOS == "windows" {
return
} |
99fa101 to
8005154
Compare
|
Okay, added it! Hit return too early, though, so I pushed it before I was able to squash. |
|
Yeah, if you could squash it one more time that'd be perfect! Great work. |
8005154 to
7091a20
Compare
|
Alright! That should be it! 🍻 |
|
Woo! Nicely done. Cheers. |
|
Crazy stuff! Thanks for your time! |
|
Thank you. Hopefully this will not be the last contribution we see from you 😄 |

These are the changes so far as discussed in #406.
Open tasks: