(r types.Route)
| 46 | } |
| 47 | |
| 48 | func (ep *Entrypoint) StartAddRoute(r types.Route) error { |
| 49 | if r.ShouldExclude() { |
| 50 | ep.excludedRoutes.Add(r) |
| 51 | r.Task().OnCancel("remove_route", func() { |
| 52 | ep.excludedRoutes.Del(r) |
| 53 | }) |
| 54 | return nil |
| 55 | } |
| 56 | switch r := r.(type) { |
| 57 | case types.HTTPRoute: |
| 58 | if err := ep.AddHTTPRoute(r); err != nil { |
| 59 | return err |
| 60 | } |
| 61 | ep.shortLinkMatcher.AddRoute(r.Key()) |
| 62 | r.Task().OnCancel("remove_route", func() { |
| 63 | ep.delHTTPRoute(r) |
| 64 | ep.shortLinkMatcher.DelRoute(r.Key()) |
| 65 | }) |
| 66 | case types.StreamRoute: |
| 67 | if asSNIRoute(r) { |
| 68 | if !common.SNIRoutingForTCPRoutes { |
| 69 | return fmt.Errorf("route %q listens on the shared HTTPS listener, but TCP SNI routing is disabled", r.Name()) |
| 70 | } |
| 71 | if err := ep.sni.AddRoute(r); err != nil { |
| 72 | return err |
| 73 | } |
| 74 | ep.streamRoutes.Add(r) |
| 75 | r.Task().OnCancel("remove_sni_route", func() { |
| 76 | ep.sni.DelRoute(r) |
| 77 | _ = r.Stream().Close() |
| 78 | ep.streamRoutes.Del(r) |
| 79 | }) |
| 80 | return nil |
| 81 | } |
| 82 | |
| 83 | err := r.ListenAndServe(r.Task().Context(), nil, nil) |
| 84 | if err != nil { |
| 85 | return err |
| 86 | } |
| 87 | ep.streamRoutes.Add(r) |
| 88 | |
| 89 | r.Task().OnCancel("remove_route", func() { |
| 90 | r.Stream().Close() |
| 91 | ep.streamRoutes.Del(r) |
| 92 | }) |
| 93 | default: |
| 94 | return fmt.Errorf("unknown route type: %T", r) |
| 95 | } |
| 96 | return nil |
| 97 | } |
| 98 | |
| 99 | func getAddr(route types.HTTPRoute) (httpAddr, httpsAddr string) { |
| 100 | if port := route.ListenURL().Port(); port == "" || port == "0" { |
nothing calls this directly
no test coverage detected