{"id":16828008,"url":"https://github.com/hyperlink/socket.io-sticky-headers","last_synced_at":"2025-03-17T20:29:19.888Z","repository":{"id":57365209,"uuid":"87433122","full_name":"hyperlink/socket.io-sticky-headers","owner":"hyperlink","description":"Use custom header to maintain sticky sessions with socket.io","archived":false,"fork":false,"pushed_at":"2017-11-20T19:28:30.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-14T09:43:58.632Z","etag":null,"topics":["socket-io","sticky-headers"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hyperlink.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-06T13:34:53.000Z","updated_at":"2023-04-11T15:20:19.000Z","dependencies_parsed_at":"2022-09-12T03:11:03.926Z","dependency_job_id":null,"html_url":"https://github.com/hyperlink/socket.io-sticky-headers","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperlink%2Fsocket.io-sticky-headers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperlink%2Fsocket.io-sticky-headers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperlink%2Fsocket.io-sticky-headers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperlink%2Fsocket.io-sticky-headers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyperlink","download_url":"https://codeload.github.com/hyperlink/socket.io-sticky-headers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244105253,"owners_count":20398831,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["socket-io","sticky-headers"],"created_at":"2024-10-13T11:24:07.352Z","updated_at":"2025-03-17T20:29:19.869Z","avatar_url":"https://github.com/hyperlink.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# socket.io-sticky-headers\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/hyperlink/socket.io-sticky-headers.svg)](https://greenkeeper.io/)\n\nUse custom header to maintain sticky sessions with socket.io\n\n## Problem\n\nFor cluster of socket.io servers Socket.io connections made by the client requires a handshake process that involves sending several XHR requests. If any of those requests fail to connect to the same instance the handshake will fail and socket.io will be in a reconnect loop (failing with 401 errors).\n\nSticky sessions are need to successfully connect to a cluster of socket.io servers. Usually this can be managed with a Cookie. However browsers such as Safari has very strict third party cookie rules which could prevent this from working. An example could be a chat client placed on a customers site.\n\nThis module patches the engine.io XHR polling to capture a custom http header response of your choosing. Any future requests made will use the same http header. Future requests will update the header if that header ever changed.\n\n## Install\n\n```bash\nnpm install socket.io-sticky-headers --save\n```\n\n## Usage\n\n### Socket.io\n\n```javascript\nrequire('socket.io-sticky-headers')(require('socket.io-client/node_modules/engine.io-client/lib/transports/polling-xhr'), 'My-Session-Id')\n```\n\n### Engine.io\n\n```javascript\nrequire('socket.io-sticky-headers')(require('engine.io-client/lib/transports/polling-xhr'), 'My-Session-Id')\n```\n\nPass `true` as the third argument if you wish to send the header as query param instead (which maybe more desirable for CORS reasons). You will need to provide a socket as shown below:\n\n```javascript\nconst stickyHeader = require('socket.io-sticky-headers')\nstickyHeader(require('engine.io-client/lib/transports/polling-xhr'), 'My-Session-Id', true)\n\nvar io = require('socket.io-client')\n\nvar socket = io('http://localhost:3000', {\n  reconnection: false,\n  'force new connection': true\n})\n\nstickyHeader.setSocket(socket)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperlink%2Fsocket.io-sticky-headers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyperlink%2Fsocket.io-sticky-headers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperlink%2Fsocket.io-sticky-headers/lists"}