{"action":"created","issue":{"url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/112","repository_url":"https://api.github.com/repos/chimurai/http-proxy-middleware","labels_url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/112/labels{/name}","comments_url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/112/comments","events_url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/112/events","html_url":"https://github.com/chimurai/http-proxy-middleware/issues/112","id":178565727,"number":112,"title":"websocket proxy cannot upgrade websocket connection","user":{"login":"desy83","id":11294106,"avatar_url":"https://avatars.githubusercontent.com/u/11294106?v=3","gravatar_id":"","url":"https://api.github.com/users/desy83","html_url":"https://github.com/desy83","followers_url":"https://api.github.com/users/desy83/followers","following_url":"https://api.github.com/users/desy83/following{/other_user}","gists_url":"https://api.github.com/users/desy83/gists{/gist_id}","starred_url":"https://api.github.com/users/desy83/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/desy83/subscriptions","organizations_url":"https://api.github.com/users/desy83/orgs","repos_url":"https://api.github.com/users/desy83/repos","events_url":"https://api.github.com/users/desy83/events{/privacy}","received_events_url":"https://api.github.com/users/desy83/received_events","type":"User","site_admin":false},"labels":[{"id":302656758,"url":"https://api.github.com/repos/chimurai/http-proxy-middleware/labels/awaiting%20response","name":"awaiting response","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2016-09-22T09:48:52Z","updated_at":"2016-11-23T02:56:28Z","closed_at":null,"body":"### Expected behavior\n\nHPM should upgrade websocket requests always\n### Actual behavior\n\nHPM websocket proxy cannot upgrade websocket connections sporadically\n### Setup\n- http-proxy-middleware: 0.17.1\n- server: tornado 4.4.1 - [Tornado Github](https://github.com/tornadoweb/tornado)\n- webpack: 1.13.2 \n- webpack-dev-server: 1.16.1\n#### proxy middleware configuration\n\n```\n devServer: {\n      proxy: {\n        '/hyperguard/websocket/*': {\n          target: 'ws://localhost:8082',\n        ws: true\n        }\n      }\n    }\n```\n#### server mounting\n\n``` python\ndef serve_forever(self):\n    app = self.__make_app()\n    self.__http_server = HTTPServer(app)\n    self.__http_server._handle_connection = self._handle_connection\n    self.__http_server.listen(self.__port, self.__host)\n    app.ssl_enabled = self.__ssl_options is not None\n    self.__ioloop.start()\n```\n### Howto Reproduce\n\n**http stream request**\n\n```\nGET /hyperguard/websocket HTTP/1.1\nHost: localhost:8079\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\nAccept-Language: en-US,en;q=0.5\nAccept-Encoding: gzip, deflate\nSec-WebSocket-Version: 13\norigin: http://localhost:8079\nSec-WebSocket-Extensions: permessage-deflate\nSec-WebSocket-Key: yrOcNHCvvVuGgttYgv9nzA==\nConnection: keep-alive, Upgrade\nPragma: no-cache\nCache-Control: no-cache\nUpgrade: websocket\n```\n\n**http stream response**\ngetting this response only sometimes, if not the websocket connection never be established\n\n```\nHTTP/1.1 101 Switching Protocols\nupgrade: websocket\nconnection: Upgrade\nsec-websocket-accept: I3u4B7iakSJWk4yLd02hfn+enus=\n```\n- that issue also occurs on different platforms (fedora 22, ubuntu 14.04, centos7)\n- restarting webpack-dev-server doesnt change anything\n"},"comment":{"url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/comments/262424705","html_url":"https://github.com/chimurai/http-proxy-middleware/issues/112#issuecomment-262424705","issue_url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/112","id":262424705,"user":{"login":"dceddia","id":505704,"avatar_url":"https://avatars.githubusercontent.com/u/505704?v=3","gravatar_id":"","url":"https://api.github.com/users/dceddia","html_url":"https://github.com/dceddia","followers_url":"https://api.github.com/users/dceddia/followers","following_url":"https://api.github.com/users/dceddia/following{/other_user}","gists_url":"https://api.github.com/users/dceddia/gists{/gist_id}","starred_url":"https://api.github.com/users/dceddia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dceddia/subscriptions","organizations_url":"https://api.github.com/users/dceddia/orgs","repos_url":"https://api.github.com/users/dceddia/repos","events_url":"https://api.github.com/users/dceddia/events{/privacy}","received_events_url":"https://api.github.com/users/dceddia/received_events","type":"User","site_admin":false},"created_at":"2016-11-23T02:56:28Z","updated_at":"2016-11-23T02:56:28Z","body":"@dansiviter this SO answer might be helpful: http://stackoverflow.com/a/32943389/465887\r\n\r\nI'm working on enabling websocket proxying in Create React App (https://github.com/facebookincubator/create-react-app/issues/1013) and it looks like I can manually watch for the \"upgrade\" request coming from the devServer, and then call HPM's \"upgrade\" function.\r\n\r\nCRA is using HPM directly though, instead of the `devServer.proxy` config, so it might not apply to your use case, but this is the code I'm using to set it up (so far it seems to be working but I haven't tested thoroughly yet):\r\n\r\n```javascript\r\n    // Pass the scope regex both to Express and to the middleware for proxying\r\n    // of both HTTP and WebSockets to work without false positives.\r\n    var hpm = httpProxyMiddleware(pathname => mayProxy.test(pathname), {\r\n      target: proxy,\r\n      logLevel: 'debug',\r\n      onError: onProxyError(proxy),\r\n      secure: false,\r\n      changeOrigin: true,\r\n      ws: true\r\n    });\r\n    devServer.use(mayProxy, hpm);\r\n\r\n    devServer.listeningApp.on('upgrade', hpm.upgrade);\r\n```"}}
{"actor":{"display_login":"dceddia"}}