Skip to content

fixes req.URL.Path for unix: sockets - #699

Merged
mholt merged 1 commit into
caddyserver:masterfrom
eiszfuchs:socket-url
Mar 28, 2016
Merged

mholt merged 1 commit into
caddyserver:masterfrom
eiszfuchs:socket-url

Conversation

@eiszfuchs

Copy link
Copy Markdown

Please review my change like last time; I haven't been able to achieve master skills of Go yet.

What's currently going wrong

Given a Caddyfile like this:

127.0.0.1:2015
tls off

proxy / unix:/var/run/www.socket

And running an application similar to this one:

/* Using built-in modules only here, since extra dependencies
 * would compromise testing too much.
 */
var http = require('http');

var responder = function (request, response) {
  response.writeHead(200, {'Content-Type': 'text/plain'});
  response.end('socket response for ' + request.url);
};

var server = http.createServer(responder);

/* Since this folder most likely is owned by root,
 * use `sudo` to run this script.
 */
server.listen('/var/run/www.socket');

When calling http://127.0.0.1:2015/test now, server replies with socket response for /var/run/www.socket/test.

What should happen

When calling http://127.0.0.1:2015/test now, server should reply with socket response for /test.

What I did

I added another block that behaves just like without would do, trimming the path of the socket file.
I'm not sure at the moment whether to put it above or below without, but I guess I've got it the wrong way around? I couldn't sleep this night. I didn't succeed with my switch yesterday because of several problems, one of which was exactly this issue.

@mholt

mholt commented Mar 27, 2016

Copy link
Copy Markdown
Member

Hey, nice work! I didn't think about that, so I'm glad you're fixing it.

The PR looks good. As far as whether it should go before or after the 'without' logic, try writing a test. Once this PR has a test we can be confident it is working as expected. The test can try a couple different scenarios (e.g. with 'without' logic and without 'without' logic -- phew, that was weird!) and if it passes we can merge it in! 👍

Happy Easter, by the way. Hope you can sleep better tonight 😄

(Also, the failing test on travis is unrelated. There's a bug on Go tip.)

@eiszfuchs

Copy link
Copy Markdown
Author

Ahoy!

I've been able to make quite a mess, using parts of my previous attempts at writing a test for the socket functionality. This passes and covers my changes. 👍
I might add that for regular http proxies as well.

I see the build is failing at the linting of the markdown middleware. Is that my fault?
Oh no, it doesn't. Uhm. What's going on? Did I break it?

@mholt

mholt commented Mar 28, 2016

Copy link
Copy Markdown
Member

@eiszfuchs I added a new test to the CI script this weekend that checks gofmt -s, and this is the first time a push has failed on it; I didn't realize it wouldn't output anything useful! But it looks like proxy_test.go needs to be go fmt'ed:

<   name string
---
>   name    string

Line 368.

I'll work on getting more useful output for that test, sorry! Tests look great at a glance!

@eiszfuchs

Copy link
Copy Markdown
Author

This is really weird, but I appreciate clean code.
Didn't know it would fail on some missing spaces. Hah!

Will squash and add a HTTP proxy test as well later (even though this will double the test code added, which doesn't sound too bad actually).

Wait. It's still failing on go vet ./.... What the heck? caddy/config and server/server.go seem to be broken.

@mholt

mholt commented Mar 28, 2016

Copy link
Copy Markdown
Member

@eiszfuchs It's go vet that's failing, and I believe it's a bug in go vet on Go tip. Notice that it succeeds on Go 1.6.

Anyway, your PR is now passing, so I will merge in as soon as you add a HTTP proxy test and squash commits. Then we'll make you a collaborator. 👍

(Also, I've updated the CI tests on master so that more useful output is shown when gofmt check fails.)

@eiszfuchs

Copy link
Copy Markdown
Author

Yes, I noticed it wouldn't fail with 1.6 (since that's installed on my machine, too).
Additional test might take until the weekend. 💼

@mholt

mholt commented Mar 28, 2016

Copy link
Copy Markdown
Member

In that case, is it alright if I merge your PR now? Just squash your commits first.

@eiszfuchs

Copy link
Copy Markdown
Author

No, wait with that. That error has been in the code for a while and I'd feel more comfortable with that additional test before merging that into master. Safety first! :)
If I happen to find a clever solution to write the test efficiently without the whole lot of copy/paste insanity, I'll add it right away.

@mholt

mholt commented Mar 28, 2016

Copy link
Copy Markdown
Member

Okay, I'll wait. 😄 Just wanted to avoid possible merge conflicts. Thanks for being careful!

@eiszfuchs

Copy link
Copy Markdown
Author

I have been rebasing before, I think I'll be able to do that magic trick again. 👍

@eiszfuchs

Copy link
Copy Markdown
Author

Ahoy! I made it!
Well, the tests got a lot more complicated, but if you think they're looking fine, that's all I need.

And I goofed the rebase. Lemme check that!
All fixed!

Comment thread middleware/proxy/proxy_test.go Outdated
}

func TestUnixSocketProxyPaths(t *testing.T) {
if runtime.GOOS == "windows" {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait! This only needs to happen for the socket test in line 336, doesn't it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I think so!

@eiszfuchs

Copy link
Copy Markdown
Author

Uhm, yes, made changes according to comments. It's getting late and I'm getting nervous. 😥

Looks like I've got only lint messages left to fix, or am I to remove lints and improve code style later?

@mholt

mholt commented Mar 28, 2016

Copy link
Copy Markdown
Member

@eiszfuchs If you want to fix the lint warnings, that'd be superb. (Unfortunately there's nothing we can do about the first two.) Then I think we're good to go! (don't forget to squash)

PS. You're doing great. 😄

@eiszfuchs

Copy link
Copy Markdown
Author

Will eat something, then sure, I love* fixing lint warnings!

* That's some Javascript developer right here 

@eiszfuchs

Copy link
Copy Markdown
Author

Lint warnings are gone! 🎉

@mholt

mholt commented Mar 28, 2016

Copy link
Copy Markdown
Member

Woo hoo! Excellent, thank you so much!

Merging now.

@mholt
mholt merged commit 5989eb0 into caddyserver:master Mar 28, 2016
@mholt

mholt commented Mar 28, 2016

Copy link
Copy Markdown
Member

I've also added you as a collaborator, so feel free to participate in code reviews of other PRs, or submit others as you would like, you can even merge PRs if everything looks good (commits squashed, CI tests pass, etc)!

@eiszfuchs
eiszfuchs deleted the socket-url branch March 29, 2016 08:11
@eiszfuchs

Copy link
Copy Markdown
Author

Oh! Thanks! That's quite an honor!
Will see what I can do! 🍻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants