Skip to content

Commit f9fcb0f

Browse files
authored
Merge pull request #2 from smarty/ryan/http2
Ryan/http2
2 parents f300109 + 5ba71e8 commit f9fcb0f

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

‎config.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ type configuration struct {
3636
Logger logger
3737
ErrorLogger logger
3838
HTTPServer httpServer
39+
Protocols *http.Protocols
40+
HTTP2 *http.HTTP2Config
3941
}
4042

4143
func New(options ...option) ListenCloser {
@@ -73,6 +75,12 @@ func (singleton) IgnoredErrors(value ...error) option {
7375
func (singleton) HTTPServer(value httpServer) option {
7476
return func(this *configuration) { this.HTTPServer = value }
7577
}
78+
func (singleton) Protocols(value *http.Protocols) option {
79+
return func(this *configuration) { this.Protocols = value }
80+
}
81+
func (singleton) HTTP2(value *http.HTTP2Config) option {
82+
return func(this *configuration) { this.HTTP2 = value }
83+
}
7684
func (singleton) MaxRequestHeaderSize(value int) option {
7785
return func(this *configuration) { this.MaxRequestHeaderSize = value }
7886
}
@@ -133,6 +141,8 @@ func (singleton) apply(options ...option) option {
133141
ReadHeaderTimeout: this.ReadRequestHeaderTimeout,
134142
WriteTimeout: this.WriteResponseTimeout,
135143
IdleTimeout: this.IdleConnectionTimeout,
144+
Protocols: this.Protocols,
145+
HTTP2: this.HTTP2,
136146
BaseContext: func(net.Listener) context.Context { return this.Context },
137147
ErrorLog: newServerLogger(this.ErrorLogger),
138148
}
@@ -151,6 +161,8 @@ func (singleton) defaults(options ...option) []option {
151161
return append([]option{
152162
Options.ListenAddress(":http"),
153163
Options.TLSConfig(nil),
164+
Options.Protocols(nil),
165+
Options.HTTP2(nil),
154166
Options.MaxRequestHeaderSize(1024 * 2),
155167
Options.ReadRequestTimeout(time.Second * 5),
156168
Options.ReadRequestHeaderTimeout(time.Second),

‎config_test.go‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package httpserver
2+
3+
import (
4+
"net/http"
5+
"testing"
6+
7+
"github.com/smarty/gunit"
8+
"github.com/smarty/gunit/assert/should"
9+
)
10+
11+
func TestConfigurationFixture(t *testing.T) {
12+
gunit.Run(new(ConfigurationFixture), t)
13+
}
14+
15+
type ConfigurationFixture struct {
16+
*gunit.Fixture
17+
}
18+
19+
func (this *ConfigurationFixture) TestProtocolsAndHTTP2_DefaultToNil() {
20+
server := builtHTTPServer(New())
21+
22+
this.So(server.Protocols, should.BeNil)
23+
this.So(server.HTTP2, should.BeNil)
24+
}
25+
func (this *ConfigurationFixture) TestProtocolsAndHTTP2_ArePassedToTheServerThisPackageBuilds() {
26+
protocols := new(http.Protocols)
27+
protocols.SetHTTP1(true)
28+
protocols.SetUnencryptedHTTP2(true)
29+
http2 := &http.HTTP2Config{MaxConcurrentStreams: 42}
30+
31+
server := builtHTTPServer(New(
32+
Options.Protocols(protocols),
33+
Options.HTTP2(http2),
34+
))
35+
36+
this.So(server.Protocols, should.Equal, protocols)
37+
this.So(server.HTTP2, should.Equal, http2)
38+
}
39+
40+
func builtHTTPServer(value ListenCloser) *http.Server {
41+
return value.(*defaultServer).httpServer.(*http.Server)
42+
}

0 commit comments

Comments
 (0)