wandenberg / nginx-push-stream-module

A pure stream http push technology for your Nginx setup. Comet made easy and really scalable.
Other
2.22k stars 295 forks source link

Forever iframe case: mismatch Transfer-encoding header and sending data format #147

Closed Sherbin closed 10 years ago

Sherbin commented 10 years ago

Hello!

I use nginx 1.4.2 with nginx-push-stream-module to realize "Forever Iframe" case. When messages comes from server to browser (Chrome) sometimes I get error in console: net::ERR_INVALID_CHUNKED_ENCODING, pushstream.js recreates iframe and browser loose some pushstream messages Or if I test server with curl, I get message * Received problem 2 in the chunky parser.

Looks like mismatch Transfer-Encoding header ('chunked') and sending data format (no number of chunks or CRLF in response body)

part of nginx.conf:

location ~ /message-pipe-ws/(.*) {
    push_stream_websocket;
    set $push_stream_channels_path              $1;
    push_stream_message_template                "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":~text~}";
    push_stream_websocket_allow_publish         on;
    push_stream_ping_message_interval           10s;
}

location ~ /message-pipe-es/(.*) {
    push_stream_subscriber;
    push_stream_eventsource_support on;
    set $push_stream_channels_path           $1;
    push_stream_message_template            "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":~text~}";
    push_stream_ping_message_interval           10s;
    add_header Access-Control-Allow-Origin *;
}

location ~ /message-pipe-stream(.*) {
    push_stream_subscriber;
    set $push_stream_channels_path           $1;
    push_stream_header_template             "<!DOCTYPE html>\r\n<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-store\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-cache\">\r\n<meta http-equiv=\"Pragma\" content=\"no-cache\">\r\n<meta http-equiv=\"Expires\" content=\"Thu, 1 Jan 1970 00:00:00 GMT\">\r\n<script type=\"text/javascript\">\r\nwindow.onError = null;\r\ntry{ document.domain = (window.location.hostname.match(/^(\d{1,3}\.){3}\d{1,3}$/)) ? window.location.hostname : window.location.hostname.split('.').slice(-1 * Math.max(window.location.hostname.split('.').length - 1, (window.location.hostname.match(/(\w{4,}\.\w{2}|\.\w{3,})$/) ? 2 : 3))).join('.');}catch(e){}\r\nparent.PushStream.register(this);\r\nparent.console.log('---> Pushstream header template (remove this message from nginx.conf)')</script>\r\n</head>\r\n<body>";
    push_stream_message_template            "<script>parent.console.log('---> get pushsream data (remove this message from nginx.conf)');p(~id~,'~channel~',~text~);</script>";
    push_stream_footer_template             "</body></html>";
    push_stream_ping_message_interval        10s;
    add_header Access-Control-Allow-Origin   *;
    add_header Content-Type text/html;
    default_type                            "text/html; charset=utf-8";
}

curl test:

> GET /message-pipe-stream/public/private_QI635HkxQwZ9bdYISNYEHk3383U3rqvT?_=1403505013999&streamid=0 HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: webcharts4
> Accept: */*
> 
< HTTP/1.1 200 OK
< Server: nginx
< Date: Mon, 23 Jun 2014 13:10:19 GMT
< Content-Type: text/plain
< Connection: close
< Expires: Thu, 01 Jan 1970 00:00:01 GMT
< Cache-Control: no-cache, no-store, must-revalidate
< Transfer-Encoding: chunked
< Access-Control-Allow-Origin: *
< Content-Type: text/html
< 
<!DOCTYPE html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Cache-Control" content="no-store">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="Thu, 1 Jan 1970 00:00:00 GMT">
<script type="text/javascript">
window.onError = null;
try{ document.domain = (window.location.hostname.match(/^(\d{1,3}\.){3}\d{1,3}$/)) ? window.location.hostname : window.location.hostname.split('.').slice(-1 * Math.max(window.location.hostname.split('.').length - 1, (window.location.hostname.match(/(\w{4,}\.\w{2}|\.\w{3,})$/) ? 2 : 3))).join('.');}catch(e){}
parent.PushStream.register(this);
parent.console.log('---> Pushstream header template (remove this message from nginx.conf)')</script>
</head>
<body>
* Received problem 2 in the chunky parser
* Closing connection #0
wandenberg commented 10 years ago

Which module version (commit) are you using?

Sherbin commented 10 years ago

Version 0.3.5

wandenberg commented 10 years ago

Can you test the last commit on master branch? This is the same code as 0.4.0 but with small bug fixes. May be your problem was already fixed, since 0.3.5 is an old version.

Sherbin commented 10 years ago

Yes, the last commit fix this problem. Thanks a lot!