Skip to content

Commit 656c6e4

Browse files
committed
config: add Serve field
Currently (*kite.Kite).Run() uses default HTTP server for serving requests. If a custom http.Server (e.g. with adjusted timeouts etc.) is needed, a Serve field can be used to provide custom implementation. In particular this field is needed to disable HTTP2 server for cmd/tunnelserver in order to fix koding/koding#11269.
1 parent 799aba7 commit 656c6e4

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

config/config.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package config
44
import (
55
"errors"
66
"fmt"
7+
"net"
78
"net/http"
89
"net/http/cookiejar"
910
"os"
@@ -13,7 +14,7 @@ import (
1314
"github.com/koding/kite/kitekey"
1415
"github.com/koding/kite/protocol"
1516

16-
"github.com/dgrijalva/jwt-go"
17+
jwt "github.com/dgrijalva/jwt-go"
1718
"github.com/gorilla/websocket"
1819
"github.com/igm/sockjs-go/sockjs"
1920
)
@@ -100,6 +101,12 @@ type Config struct {
100101
// Required.
101102
SockJS *sockjs.Options
102103

104+
// Serve is serving HTTP requests using handler on requests
105+
// comming from the given listener.
106+
//
107+
// If Serve is nil, http.Serve is used by default.
108+
Serve func(net.Listener, http.Handler) error
109+
103110
KontrolURL string
104111
KontrolKey string
105112
KontrolUser string

server.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,14 @@ func (k *Kite) listenAndServe() error {
9191
defer close(k.closeC) // serving is finished, notify waiters.
9292
k.Log.Info("Serving...")
9393

94-
return http.Serve(k.listener, k)
94+
return k.serve(k.listener, k)
95+
}
96+
97+
func (k *Kite) serve(l net.Listener, h http.Handler) error {
98+
if k.Config.Serve != nil {
99+
return k.Config.Serve(l, h)
100+
}
101+
return http.Serve(l, h)
95102
}
96103

97104
// Port returns the TCP port number that the kite listens.

0 commit comments

Comments
 (0)