Skip to content

Commit

Permalink
http proxy: add mandatory name to ListenerConfig in ExtraListeners
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatczuk committed Nov 8, 2024
1 parent 9f04cba commit 02db5ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 8 additions & 3 deletions http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var ErrConnectFallback = martian.ErrConnectFallback

type HTTPProxyConfig struct {
HTTPServerConfig
ExtraListeners []ListenerConfig
ExtraListeners []NamedListenerConfig
Name string
MITM *MITMConfig
MITMDomains Matcher
Expand Down Expand Up @@ -124,6 +124,11 @@ func (c *HTTPProxyConfig) Validate() error {
if err := c.HTTPServerConfig.Validate(); err != nil {
return err
}
for _, lc := range c.ExtraListeners {
if lc.Name == "" {
return errors.New("extra listener name is required")
}
}
if c.Protocol != HTTPScheme && c.Protocol != HTTPSScheme {
return fmt.Errorf("unsupported protocol: %s", c.Protocol)
}
Expand Down Expand Up @@ -582,10 +587,10 @@ func (hp *HTTPProxy) listen() (_ []net.Listener, ferr error) {
}
}()

for _, lc := range append([]ListenerConfig{hp.config.ListenerConfig}, hp.config.ExtraListeners...) {
for _, lc := range append([]NamedListenerConfig{{ListenerConfig: hp.config.ListenerConfig}}, hp.config.ExtraListeners...) {
l := new(Listener)
*l = prototype
l.ListenerConfig = lc
l.ListenerConfig = lc.ListenerConfig
if err := l.Listen(); err != nil {
return nil, err
}
Expand Down
5 changes: 5 additions & 0 deletions net.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ func DefaultListenerConfig(addr string) *ListenerConfig {
}
}

type NamedListenerConfig struct {
Name string
ListenerConfig
}

type Listener struct {
ListenerConfig
TLSConfig *tls.Config
Expand Down

0 comments on commit 02db5ad

Please sign in to comment.