Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request nsqio#1384 from karalabe/disable-http
nsqd: allow disable both HTTP and HTTPS interfaces
  • Loading branch information
ploxiln committed Oct 22, 2021
2 parents 427d893 + 2c2c2a2 commit 802306e
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions nsqd/nsqd.go
Expand Up @@ -143,17 +143,18 @@ func New(opts *Options) (*NSQD, error) {
if err != nil {
return nil, fmt.Errorf("listen (%s) failed - %s", opts.TCPAddress, err)
}
n.httpListener, err = net.Listen("tcp", opts.HTTPAddress)
if err != nil {
return nil, fmt.Errorf("listen (%s) failed - %s", opts.HTTPAddress, err)
if opts.HTTPAddress != "" {
n.httpListener, err = net.Listen("tcp", opts.HTTPAddress)
if err != nil {
return nil, fmt.Errorf("listen (%s) failed - %s", opts.HTTPAddress, err)
}
}
if n.tlsConfig != nil && opts.HTTPSAddress != "" {
n.httpsListener, err = tls.Listen("tcp", opts.HTTPSAddress, n.tlsConfig)
if err != nil {
return nil, fmt.Errorf("listen (%s) failed - %s", opts.HTTPSAddress, err)
}
}

if opts.BroadcastHTTPPort == 0 {
opts.BroadcastHTTPPort = n.RealHTTPAddr().Port
}
Expand Down Expand Up @@ -191,14 +192,24 @@ func (n *NSQD) triggerOptsNotification() {
}

func (n *NSQD) RealTCPAddr() *net.TCPAddr {
if n.tcpListener == nil {
return &net.TCPAddr{}
}
return n.tcpListener.Addr().(*net.TCPAddr)

}

func (n *NSQD) RealHTTPAddr() *net.TCPAddr {
if n.httpListener == nil {
return &net.TCPAddr{}
}
return n.httpListener.Addr().(*net.TCPAddr)
}

func (n *NSQD) RealHTTPSAddr() *net.TCPAddr {
if n.httpsListener == nil {
return &net.TCPAddr{}
}
return n.httpsListener.Addr().(*net.TCPAddr)
}

Expand Down Expand Up @@ -242,12 +253,13 @@ func (n *NSQD) Main() error {
n.waitGroup.Wrap(func() {
exitFunc(protocol.TCPServer(n.tcpListener, n.tcpServer, n.logf))
})

httpServer := newHTTPServer(n, false, n.getOpts().TLSRequired == TLSRequired)
n.waitGroup.Wrap(func() {
exitFunc(http_api.Serve(n.httpListener, httpServer, "HTTP", n.logf))
})
if n.tlsConfig != nil && n.getOpts().HTTPSAddress != "" {
if n.httpListener != nil {
httpServer := newHTTPServer(n, false, n.getOpts().TLSRequired == TLSRequired)
n.waitGroup.Wrap(func() {
exitFunc(http_api.Serve(n.httpListener, httpServer, "HTTP", n.logf))
})
}
if n.httpsListener != nil {
httpsServer := newHTTPServer(n, true, true)
n.waitGroup.Wrap(func() {
exitFunc(http_api.Serve(n.httpsListener, httpsServer, "HTTPS", n.logf))
Expand Down

0 comments on commit 802306e

Please sign in to comment.