this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

clean up rainbow host URL wrangling a bit

+37 -27
+2 -2
splitter/handlers.go
··· 52 52 // first forward to the upstream 53 53 xrpcc := xrpc.Client{ 54 54 Client: s.upstreamClient, 55 - Host: s.conf.XrpcRootUrl(), 55 + Host: s.conf.UpstreamHostHTTP(), 56 56 } 57 57 58 58 err := comatproto.SyncRequestCrawl(ctx, &xrpcc, &body) ··· 84 84 85 85 // Proxies a request to the single upstream (relay) 86 86 func (s *Splitter) ProxyRequestUpstream(c echo.Context) error { 87 - u, err := url.Parse(s.conf.XrpcRootUrl()) 87 + u, err := url.Parse(s.conf.UpstreamHostHTTP()) 88 88 if err != nil { 89 89 return err 90 90 }
+35 -25
splitter/splitter.go
··· 55 55 Logger *slog.Logger 56 56 } 57 57 58 - func (sc *SplitterConfig) XrpcRootUrl() string { 59 - if strings.HasPrefix(sc.UpstreamHost, "http://") { 60 - return sc.UpstreamHost 58 + func (sc *SplitterConfig) UpstreamHostWebsocket() string { 59 + 60 + if !strings.Contains(sc.UpstreamHost, "://") { 61 + return "wss://" + sc.UpstreamHost 61 62 } 62 - if strings.HasPrefix(sc.UpstreamHost, "https://") { 63 - return sc.UpstreamHost 63 + u, err := url.Parse(sc.UpstreamHost) 64 + if err != nil { 65 + // this will cause an error downstream 66 + return "" 64 67 } 65 - if strings.HasPrefix(sc.UpstreamHost, "ws://") { 66 - return "http://" + sc.UpstreamHost[5:] 67 - } 68 - if strings.HasPrefix(sc.UpstreamHost, "wss://") { 69 - return "https://" + sc.UpstreamHost[6:] 68 + 69 + switch u.Scheme { 70 + case "http", "ws": 71 + return "ws://" + u.Host 72 + case "https", "wss": 73 + return "wss://" + u.Host 74 + default: 75 + return "wss://" + u.Host 70 76 } 71 - return "https://" + sc.UpstreamHost 72 77 } 73 78 74 - func (sc *SplitterConfig) UpstreamUrl() string { 75 - if strings.HasPrefix(sc.UpstreamHost, "http://") { 76 - return "ws://" + sc.UpstreamHost[7:] 79 + func (sc *SplitterConfig) UpstreamHostHTTP() string { 80 + 81 + if !strings.Contains(sc.UpstreamHost, "://") { 82 + return "https://" + sc.UpstreamHost 77 83 } 78 - if strings.HasPrefix(sc.UpstreamHost, "https://") { 79 - return "wss://" + sc.UpstreamHost[8:] 84 + u, err := url.Parse(sc.UpstreamHost) 85 + if err != nil { 86 + // this will cause an error downstream 87 + return "" 80 88 } 81 - if strings.HasPrefix(sc.UpstreamHost, "ws://") { 82 - return sc.UpstreamHost 83 - } 84 - if strings.HasPrefix(sc.UpstreamHost, "wss://") { 85 - return sc.UpstreamHost 89 + 90 + switch u.Scheme { 91 + case "http", "ws": 92 + return "http://" + u.Host 93 + case "https", "wss": 94 + return "https://" + u.Host 95 + default: 96 + return "https://" + u.Host 86 97 } 87 - return "wss://" + sc.UpstreamHost 88 98 } 89 99 90 100 func NewSplitter(conf SplitterConfig, nextCrawlers []string) (*Splitter, error) { ··· 107 117 } 108 118 } 109 119 110 - _, err := url.Parse(conf.UpstreamUrl()) 120 + _, err := url.Parse(conf.UpstreamHostHTTP()) 111 121 if err != nil { 112 - return nil, fmt.Errorf("failed to parse upstream url %#v: %w", conf.UpstreamUrl(), err) 122 + return nil, fmt.Errorf("failed to parse upstream url %#v: %w", conf.UpstreamHostHTTP(), err) 113 123 } 114 124 115 125 s := &Splitter{ ··· 296 306 func (s *Splitter) subscribeWithRedialer(ctx context.Context, cursor int64) { 297 307 d := websocket.Dialer{} 298 308 299 - upstreamUrl, err := url.Parse(s.conf.UpstreamUrl()) 309 + upstreamUrl, err := url.Parse(s.conf.UpstreamHostWebsocket()) 300 310 if err != nil { 301 311 panic(err) // this should have been checked in NewSplitter 302 312 }