disconnect / apache-websocket

Apache WebSocket module
Apache License 2.0
196 stars 46 forks source link

HTTP 404 #5

Closed jamesshuriff closed 12 years ago

jamesshuriff commented 12 years ago

Hello,

My server is responding with HTTP 404 when WebSocket requests are made. I'm running Apache HTTPD 2.2.17 on FreeBSD amd64. I am going off of the examples until this problem is solved so the relative sections of my httpd.conf file are as follows:

<IfModule websocket_module> <Location /echo> SetHandler websocket-handler WebSocketHandler libexec/apache22/mod_websocket_echo.so echo_init </Location> <Location /dumb-increment> SetHandler websocket-handler WebSocketHandler libexec/apache22/mod_websocket_dumb_increment.so dumb_increment_init </Location> </IfModule>

I am also using a vhost on a non-standard port. Any advice would be appreciated.

Thank you.

disconnect commented 12 years ago

I installed FreeBSD 8.1 amd64 with Apache HTTPD 2.2.17. I built this module using:

sudo apxs -i -a -c mod_websocket.c

I didn't bother building the old draft76 module. Next, I cut-and-pasted the configuration that you provided into my httpd.conf file. I went into the examples subdirectory and modified the SConstruct file (I also installed scons on that machine), replacing lines 40-42 with these lines:

    env.Append(CPPPATH = ["/usr/local/include/apache22", "/usr/local/include/apr-1"])
    modulesdir = "/usr/local/libexec/apache22"

I ran "scons" to build the mod_websocket_echo.so and mod_websocket_dumb_increment.so files. Keep in mind that these are just examples to verify that things are working. You don't even need the "dumb increment" plugin if you are just testing the server echo. I installed them using "sudo scons install". I copied the client.html file into the /usr/local/www/apache22/data/ (if you moved the document root, then this will differ). Finally, I restarted the apache server and connected to http://localhost/client.html. The page came up and connected to the WebSocket server. I was able to enter a message and have the server echo it back.

The only difference between what I did and you should be doing is related to the vhost on a non-standard port.

Are you using a web browser that supports WebSockets? Did you perhaps try to connect directly to /echo instead of running the client using client.html?

jamesshuriff commented 12 years ago

Hi disconnect,

Thank you for responding to my issue. I actually am not very familiar with scons so I wrote my own build script for the examples. Here is the Makefile I made:

echo:
    clang -fpic -DSHARED_MODULE -I/usr/local/include/apr-1 -I/usr/local/include/apache22 -I.. -c mod_websocket_echo.c
    ld -Bshareable -o mod_websocket_echo.so mod_websocket_echo.o
    chmod 755 mod_websocket_echo.so
    cp mod_websocket_echo.so /usr/local/libexec/apache22/

I just tested client.html using Google Chrome 15.0.874.121, and it seems to work now. I think the problem is that mod_websocket has a problem with my regular browser's (Safari 5.1.1's) request headers. Here are the headers from Chrome:

Request URL:ws://hq.opentech.cc:1337/echo
Request Method:GET
Status Code:101 Switching Protocols

Request Headers

Connection:Upgrade
Host:hq.opentech.cc:1337
Sec-WebSocket-Key:iX3xHsyv3b16zlFwWhQOug==
Sec-WebSocket-Origin:http://hq.opentech.cc:1337
Sec-WebSocket-Version:8
Upgrade:websocket
(Key3):00:00:00:00:00:00:00:00

Response Headers

Connection:Upgrade
Sec-WebSocket-Accept:9bMqiqUNKoFgQ/O2arnRyL1sbpQ=
Upgrade:websocket
(Challenge Response):00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00

and Safari:

Request URL:ws://hq.opentech.cc:1337/echo

Request Headers

Connection:Upgrade
Host:hq.opentech.cc:1337
Origin:http://hq.opentech.cc:1337
Sec-WebSocket-Key1:275\JY25538J#1 Z8
Sec-WebSocket-Key2:Lt U3?Y 5$7w6~8_.0128
Upgrade:WebSocket
(Key3):77:EF:26:38:22:11:75:CA

I think this was just me mistakingly not enabling draft 76 for Safari, right?

disconnect commented 12 years ago

Right, Safari is still using the old protocol. If you want to use Safari, you will need to also build and install mod_websocket_draft76.so. That should resolve your issue.