{"id":37098917,"url":"https://github.com/grepplabs/backstream","last_synced_at":"2026-01-14T12:01:43.613Z","repository":{"id":214966170,"uuid":"732323741","full_name":"grepplabs/backstream","owner":"grepplabs","description":"A library for establishing outbound WebSocket connections from HTTP servers, overcoming ingress restrictions.","archived":false,"fork":false,"pushed_at":"2024-01-04T20:05:40.000Z","size":74,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T18:01:44.345Z","etag":null,"topics":["http","library","websockets"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/grepplabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"custom":"https://paypal.me/grepplabs?locale.x=en_GB"}},"created_at":"2023-12-16T09:47:17.000Z","updated_at":"2025-01-28T17:20:54.000Z","dependencies_parsed_at":"2024-01-04T21:24:53.803Z","dependency_job_id":null,"html_url":"https://github.com/grepplabs/backstream","commit_stats":null,"previous_names":["grepplabs/backstream"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/grepplabs/backstream","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grepplabs%2Fbackstream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grepplabs%2Fbackstream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grepplabs%2Fbackstream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grepplabs%2Fbackstream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grepplabs","download_url":"https://codeload.github.com/grepplabs/backstream/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grepplabs%2Fbackstream/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28419272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["http","library","websockets"],"created_at":"2026-01-14T12:01:42.948Z","updated_at":"2026-01-14T12:01:43.608Z","avatar_url":"https://github.com/grepplabs.png","language":"Go","readme":"# backstream\n\n[![Release](https://img.shields.io/github/v/release/grepplabs/backstream?sort=semver)](https://github.com/grepplabs/backstream/releases)\n[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n![Build](https://github.com/grepplabs/backstream/workflows/tests/badge.svg)\n\n## Overview\nThe backstream is a library designed for environments with restricted ingress connections.\nIt enables HTTP servers to establish outbound WebSocket connections to a central HTTP service.\nOnce connected, users can send HTTP requests to the central service, which efficiently forwards them downstream to the\nappropriate WebSocket-enabled servers, effectively bypassing ingress restrictions.\n\n\u003cp style=\"text-align: center;\"\u003e\u003cimg src=\"docs/backstream.png\" alt=\"backstream\"\u003e\u003c/p\u003e\n\n## Usage\n\nWrite a `proxy` server.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"flag\"\n\t\"log/slog\"\n\t\"net/http\"\n\t\"os\"\n\t\"time\"\n\n\t\"github.com/grepplabs/backstream/handler\"\n\t\"github.com/grepplabs/backstream/ws\"\n)\n\nfunc main() {\n\taddr := flag.String(\"addr\", \":8080\", \"Listen address\")\n\tflag.Parse()\n\n\tcodec := handler.NewHttpProtoCodec()\n\tproxyHandler := handler.NewProxyHandler(codec, handler.WithProxyDefaultRequestTimeout(3*time.Second))\n\tlogger := slog.New(slog.NewJSONHandler(os.Stderr, \u0026slog.HandlerOptions{Level: slog.LevelDebug}))\n\tserve := ws.NewServe(context.Background(), proxyHandler, codec.MessageCodec(), ws.WithServeLogger(logger), ws.WithRequireClientId(true))\n\n\tmux := http.NewServeMux()\n\tmux.HandleFunc(\"/ws\", func(w http.ResponseWriter, r *http.Request) {\n\t\tserve.HandleWS(w, r)\n\t})\n\tmux.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n\t\tserve.HandleProxy(w, r)\n\t})\n\tserver := \u0026http.Server{\n\t\tAddr:              *addr,\n\t\tReadHeaderTimeout: 3 * time.Second,\n\t\tHandler:           mux,\n\t}\n\tif err := server.ListenAndServe(); err != nil {\n\t\tlogger.Error(err.Error())\n\t}\n}\n```\n\nWrite a `HTTP service` server.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"flag\"\n\t\"log/slog\"\n\t\"net/http\"\n\t\"os\"\n\n\t\"github.com/grepplabs/backstream/handler\"\n\t\"github.com/grepplabs/backstream/ws\"\n)\n\nfunc main() {\n\taddr := flag.String(\"addr\", \":8081\", \"Listen address\")\n\tproxyUrl := flag.String(\"proxy-url\", \"ws://localhost:8080/ws\", \"Proxy websocket endpoint\")\n\tclientID := flag.String(\"client-id\", \"4711\", \"Client ID\")\n\tflag.Parse()\n\n\tcodec := handler.NewHttpProtoCodec()\n\tlogger := slog.New(slog.NewJSONHandler(os.Stderr, \u0026slog.HandlerOptions{Level: slog.LevelDebug})).With(slog.String(\"client-id\", *clientID))\n\tmux := http.NewServeMux()\n\twsHandler := handler.NewRecoveryHandler(handler.NewHTTPHandler(func(w http.ResponseWriter, r *http.Request) {\n\t\tmux.ServeHTTP(w, r)\n\t}, codec), logger)\n\tclient := ws.NewClient(context.Background(), *proxyUrl, wsHandler, codec.MessageCodec(), ws.WithClientLogger(logger), ws.WithClientID(*clientID))\n\tclient.Start()\n\n\tmux.HandleFunc(\"/test\", func(w http.ResponseWriter, r *http.Request) {\n\t\tw.WriteHeader(200)\n\t})\n\tserver := \u0026http.Server{\n\t\tAddr:    *addr,\n\t\tHandler: mux,\n\t}\n\tif err := server.ListenAndServe(); err != nil {\n\t\tlogger.Error(err.Error())\n\t}\n}\n```\n\nInvoke `test` endpoint against the `proxy` server.\n\n```bash\ncurl -v -H 'x-backstream-client-id: 4711' http://localhost:8080/test\ncurl -v -H 'x-backstream-client-id: 4711' -H 'x-backstream-request-timeout: 12s' http://localhost:8080/test\n```\n","funding_links":["https://paypal.me/grepplabs?locale.x=en_GB"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrepplabs%2Fbackstream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrepplabs%2Fbackstream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrepplabs%2Fbackstream/lists"}