caddy: Caddy doesn't pass the "Connection" header to websockets?

(Are you asking for help with using Caddy? Please use our forum instead: https://forum.caddyserver.com. If you are filing a bug report, please answer the following questions. If your issue is not a bug report, you do not need to use this template. Either way, please consider donating if we’ve helped you. Thanks!)

1. What version of Caddy are you running (caddy -version)?

Caddy (untracked dev build) (master)

2. What are you trying to do?

Proxy to a websocket

3. What is your entire Caddyfile?

stream.6f.io {
  gzip {
    not /stream
  }
  proxy / 127.0.0.1:1339 {
    websocket
    max_fails 0
  }
}

4. How did you run Caddy (give the full command and describe the execution environment)?

./caddy

5. What did you expect to see?

Websockets being proxied correctly.

6. What did you see instead (give full error messages and/or log)?

The backend which is being proxied doesn’t receive the header and therefore spits out

websocket: could not find connection header with token 'upgrade'

7. How can someone who is starting from scratch reproduce this behavior as minimally as possible?

Read the “Connection” header from a proxied backend, ensuring the request was a valid websocket one.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 19 (8 by maintainers)

Most upvoted comments

Yes, 0.9.1 will include this fix. And thank you!

Hi @schollz , your problem is fixed in the latest build with this commit https://github.com/mholt/caddy/commit/6490ff6224a949ac4c63ef184d2c10377889c3b1 Just to confirm, I tried your example with the https://github.com/mholt/caddy/commit/7157bdc79d38e203386d7e12d7065d884166c431, it works well, but it doesn’t work with v0.9.0 and the issue is just what you described.

@evermax Thanks. Your test works for me on both 0.8.3 and 0.9.

I followed your example to make a self contained test (though not as elegant). I went and forked Gorilla’s websocket chat example which is the essence of what I’m using in my code. This example works fine for me on 0.8.3, but again it does not work for 0.9 (or current master). Gorilla gives me an error: websocket: could not find connection header with token 'upgrade'.

If you’d like to try, you can try this: https://github.com/schollz/websocket-test. The Caddyfile I used is in there so you just need to do go run *.go and startup a version of caddy and open a browser to 127.0.0.1.

Hi, I created docker containers to reproduce the issue: https://github.com/evermax/caddy-websocket-test

But it works for me. Can you give me some feedback as to how to get it closer to your own configuration?