我想同时支持ws
和http
,但仍然坚持这个问题。
我尝试访问/
,但netty回复了带有消息的http 400。
不是WebSocket握手请求:缺少升级
这是来自Chrome浏览器的http://localhost:9001/
请求的日志。
GET / HTTP/1.1
Host: localhost:9001
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4
Cookie: csrftoken=G86EVdqbL8NUfqex8N8gZ9QzPc6dj6Jd
content-length: 0, 0B
15:56:07.998 DEBUG io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker[debug:81] - [id: 0xd2bd692e, L:/0:0:0:0:0:0:0:1:9001 - R:/0:0:0:0:0:0:0:1:53677] WebSocket version V00 server handshake
15:56:07.998 INFO io.netty.handler.logging.LoggingHandler[info:101] - [id: 0xd2bd692e, L:/0:0:0:0:0:0:0:1:9001 - R:/0:0:0:0:0:0:0:1:53677] WRITE: DefaultFullHttpResponse(decodeResult: success, version: HTTP/1.1, content: UnpooledHeapByteBuf(ridx: 0, widx: 50, cap: 50/50))
HTTP/1.1 400 Bad Request, 50B
和代码段。
p.addLast(new HttpServerCodec())
.addLast(new HttpObjectAggregator(65536))
.addLast( new LoggingHandler(LogLevel.INFO))
/**
* For websocket chatting
*/
.addLast(new WebSocketServerProtocolHandler("/chat"))
.addLast(new WsUserAcceptHandler())
.addLast(new WsChatServerHandler())
/**
* For accessing / or HTTP 404
*/
.addLast(new HttpStaticFileHandler("/", ChatServer.index))
.addLast(new HttpNotFoundHandler());
在这个日志行中,我不明白为什么netty试图进行websocket握手?
io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker[debug:81] - [id: 0xd2bd692e, L:/0:0:0:0:0:0:0:1:9001 - R:/0:0:0:0:0:0:0:1:53677] WebSocket version V00 server handshake