goaccess: WebSocket error 400

I’ve got the following error when using web socket:

WebSocket connection to ‘ws://site.com:9879’ failed: Unexpected response code: 400

I run go access with the following parameters:

goaccess -f /var/log/nginx/access.log --log-format COMMON -o /var/www/stats/index.html --real-time-html --port=9879 --ws-url=site.com --origin=site.com

About this issue

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

Commits related to this issue

Most upvoted comments

I’m running into the same issue

Debugging revealed the funny thing with parsing Host: header

(gdb) s
ws_set_header_fields (line=0x7fdc34002b40 "Host: cp2-apache.goaccess.beget:7890", headers=0x7fdc34000a70) at src/websocket.c:1091
1091    {
4: method = 0x7fdc3c12add0 " \256\022<\334\177"
5: proto = 0x433b40 <xmalloc+24> "H\211E\370H\203}\370"
6: path = 0x7fdc3c12ae20 "P\256\022<\334\177"
7: list = (int *) 0x0
8: line = 0x7fdc34002b40 "Host: cp2-apache.goaccess.beget:7890"
(gdb) n
1092      char *path = NULL, *method = NULL, *proto = NULL, *p, *value;
4: method = 0x7fdc3c12add0 " \256\022<\334\177"
5: proto = 0x433b40 <xmalloc+24> "H\211E\370H\203}\370"
6: path = 0x7fdc3c12ae20 "P\256\022<\334\177"
7: list = (int *) 0x0
8: line = 0x7fdc34002b40 "Host: cp2-apache.goaccess.beget:7890"
(gdb) 
1094      if (line[0] == '\n' || line[0] == '\r')
4: method = 0x0
5: proto = 0x0
6: path = 0x0
7: list = (int *) 0x0
8: line = 0x7fdc34002b40 "Host: cp2-apache.goaccess.beget:7890"
(gdb) 
1097      if ((strstr (line, "GET")) || (strstr (line, "get"))) {
4: method = 0x0
5: proto = 0x0
6: path = 0x0
7: list = (int *) 0x0
8: line = 0x7fdc34002b40 "Host: cp2-apache.goaccess.beget:7890"
(gdb) 
1098        if ((path = ws_parse_request (line, &method, &proto)) == NULL)
4: method = 0x0
5: proto = 0x0
6: path = 0x0
7: list = (int *) 0x0
8: line = 0x7fdc34002b40 "Host: cp2-apache.goaccess.beget:7890"
(gdb) 
1099          return 1;

if we got get substring in Host: header - then parser thinks it contains request and tries to parse it once again

maybe we should check only GET substing in line to decide whether it is request or not

@allinurl thanks for merging. I was testing this patch yesterday and it worked like a charm 😉

Real-time html report is great, thank you for developing this!