Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backup 3 #1044

Closed
wants to merge 52 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
06ba819
allow context to override the default timeout
nkreiger Dec 17, 2023
cf2a4c3
test
nkreiger Dec 17, 2023
17e2ed0
move back
nkreiger Dec 17, 2023
07b07ab
mod it
nkreiger Dec 17, 2023
d8b345e
reverse
nkreiger Dec 17, 2023
99199a3
Update README.md
Vedadiyan Jan 9, 2024
0451096
Bump andstor/file-existence-action from 2 to 3
dependabot[bot] Jan 29, 2024
5bca322
Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /test/conformance
dependabot[bot] Jan 29, 2024
c3352b2
Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /test/benchmark
dependabot[bot] Dec 18, 2023
7f1d5c9
Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /samples/kafka
dependabot[bot] Jan 29, 2024
fabca7c
Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /test/integration
dependabot[bot] Jan 29, 2024
d998abd
Bump golang.org/x/crypto in /protocol/kafka_sarama/v2
dependabot[bot] Jan 29, 2024
ae1f79e
Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /samples/http
dependabot[bot] Jan 29, 2024
ae09cbb
Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /samples/nats
dependabot[bot] Jan 29, 2024
33b16db
Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /samples/stan
dependabot[bot] Dec 18, 2023
4de59c0
Bump golang.org/x/crypto in /samples/nats_jetstream
dependabot[bot] Dec 18, 2023
a2e3d7b
Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /protocol/nats/v2
dependabot[bot] Jan 29, 2024
c8bda6d
Bump golang.org/x/crypto in /protocol/nats_jetstream/v2
dependabot[bot] Jan 29, 2024
af182c7
Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /protocol/stan/v2
dependabot[bot] Jan 29, 2024
51d55c8
proposal the confluent binding for kafka
yanmxa Jan 26, 2024
7680e41
sync-tck-tests-2024.01.30
Cali0707 Jan 30, 2024
10fca48
fix a few test cases
Cali0707 Feb 1, 2024
e96f4f5
fix like expression parser
Cali0707 Feb 1, 2024
fcb0e56
Fix docstring typos in nats and jetstream protocol
jafossum Feb 8, 2024
c0de9a1
Bump golangci/golangci-lint-action from 3 to 4
dependabot[bot] Feb 12, 2024
4f6155d
Bump the bundler group across 1 directories with 1 update
dependabot[bot] Feb 6, 2024
bdfe56e
oops
duglin Feb 20, 2024
1200817
Avoid modifying the DefaultClient's Transport
tcnghia Mar 1, 2024
6bfccd2
Update v2/protocol/http/protocol.go
mattmoor Mar 1, 2024
c41dcaf
Bump the go_modules group across 2 directories with 1 update
dependabot[bot] Mar 6, 2024
d08b768
Bump the go_modules group across 4 directories with 1 update
dependabot[bot] Mar 13, 2024
2f2ad40
Bump the go_modules group across 1 directory with 1 update
dependabot[bot] Mar 16, 2024
5ade6d4
confluent kafka binding
yanmxa Dec 7, 2023
bd8149e
Add eventHandler option for confluent kafka producer
yanmxa Apr 1, 2024
ba3ff7a
Support content types following structured syntax suffixes
dan-j Jan 19, 2024
eed9a4e
Bump the go_modules group across 9 directories with 1 update
dependabot[bot] Apr 19, 2024
d0fb4d8
move to protocol
nkreiger Apr 21, 2024
a9341b3
reset
nkreiger Apr 21, 2024
8eed34a
fix go.mod
nkreiger Apr 21, 2024
9b3e3db
add/update tests
nkreiger Apr 21, 2024
741dae0
Update v2/protocol/http/options_test.go
nkreiger Apr 22, 2024
f5ce062
update based on comments, update comment
nkreiger Apr 22, 2024
82278f2
fix: support multiple amqp data fields
embano1 Apr 14, 2024
b16594e
chore: add codeowners file
embano1 Apr 22, 2024
948a219
Update v2/protocol/http/protocol.go
nkreiger Apr 24, 2024
f0281a0
Update v2/protocol/http/protocol.go
nkreiger Apr 24, 2024
bfce173
resolve issues, add timeout
nkreiger Apr 24, 2024
8542e34
Merge branch 'main' into main
nkreiger Apr 24, 2024
320d4cf
updated tests, and enforce no negative
nkreiger Apr 24, 2024
d57cf11
updated with pointer
nkreiger Apr 24, 2024
465d994
Merge branch 'main' into main
nkreiger Apr 25, 2024
f0240c9
add changes based on feedback
nkreiger Apr 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions v2/protocol/http/options.go
Expand Up @@ -83,6 +83,38 @@ func WithShutdownTimeout(timeout time.Duration) Option {
}
}

// WithReadTimeout overwrites the default read timeout (600s) of the http
// server. The specified timeout must not be negative. A timeout of 0 disables
// read timeouts in the http server.
func WithReadTimeout(timeout time.Duration) Option {
return func(p *Protocol) error {
if p == nil {
return fmt.Errorf("http read timeout option can not set nil protocol")
}
if timeout < 0 {
return fmt.Errorf("http read timeout must not be negative")
}
p.readTimeout = &timeout
return nil
}
}

// WithWriteTimeout overwrites the default write timeout (600s) of the http
// server. The specified timeout must not be negative. A timeout of 0 disables
// write timeouts in the http server.
func WithWriteTimeout(timeout time.Duration) Option {
return func(p *Protocol) error {
if p == nil {
return fmt.Errorf("http write timeout option can not set nil protocol")
}
if timeout < 0 {
return fmt.Errorf("http write timeout must not be negative")
}
p.writeTimeout = &timeout
return nil
}
}

func checkListen(p *Protocol, prefix string) error {
switch {
case p.listener.Load() != nil:
Expand Down
114 changes: 112 additions & 2 deletions v2/protocol/http/options_test.go
Expand Up @@ -315,6 +315,106 @@ func TestWithShutdownTimeout(t *testing.T) {
}
}

func TestWithReadTimeout(t *testing.T) {
expected := time.Minute * 4
testCases := map[string]struct {
t *Protocol
timeout time.Duration
want *Protocol
wantErr string
}{
"valid timeout": {
t: &Protocol{},
timeout: time.Minute * 4,
want: &Protocol{
readTimeout: &expected,
},
},
"negative timeout": {
t: &Protocol{},
timeout: -1,
wantErr: "http read timeout must not be negative",
},
"nil protocol": {
wantErr: "http read timeout option can not set nil protocol",
},
}
for n, tc := range testCases {
t.Run(n, func(t *testing.T) {

err := tc.t.applyOptions(WithReadTimeout(tc.timeout))

if tc.wantErr != "" || err != nil {
var gotErr string
if err != nil {
gotErr = err.Error()
}
if diff := cmp.Diff(tc.wantErr, gotErr); diff != "" {
t.Errorf("unexpected error (-want, +got) = %v", diff)
}
return
}

got := tc.t

if diff := cmp.Diff(tc.want, got,
cmpopts.IgnoreUnexported(Protocol{})); diff != "" {
t.Errorf("unexpected (-want, +got) = %v", diff)
}
})
}
}

func TestWithWriteTimeout(t *testing.T) {
expected := time.Minute * 4

testCases := map[string]struct {
t *Protocol
timeout time.Duration
want *Protocol
wantErr string
}{
"valid timeout": {
t: &Protocol{},
timeout: time.Minute * 4,
want: &Protocol{
writeTimeout: &expected,
},
},
"negative timeout": {
t: &Protocol{},
timeout: -1,
wantErr: "http write timeout must not be negative",
},
"nil protocol": {
wantErr: "http write timeout option can not set nil protocol",
},
}
for n, tc := range testCases {
t.Run(n, func(t *testing.T) {

err := tc.t.applyOptions(WithWriteTimeout(tc.timeout))

if tc.wantErr != "" || err != nil {
var gotErr string
if err != nil {
gotErr = err.Error()
}
if diff := cmp.Diff(tc.wantErr, gotErr); diff != "" {
t.Errorf("unexpected error (-want, +got) = %v", diff)
}
return
}

got := tc.t

if diff := cmp.Diff(tc.want, got,
cmpopts.IgnoreUnexported(Protocol{})); diff != "" {
t.Errorf("unexpected (-want, +got) = %v", diff)
}
})
}
}
func TestWithPort(t *testing.T) {
testCases := map[string]struct {
t *Protocol
Expand Down Expand Up @@ -389,9 +489,19 @@ func forceClose(tr *Protocol) {
}

func TestWithPort0(t *testing.T) {
noReadWriteTimeout := time.Duration(0)

testCases := map[string]func() (*Protocol, error){
"WithPort0": func() (*Protocol, error) { return New(WithPort(0)) },
"SetPort0": func() (*Protocol, error) { return &Protocol{Port: 0}, nil },
"WithPort0": func() (*Protocol, error) {
return New(WithPort(0))
},
"SetPort0": func() (*Protocol, error) {
return &Protocol{
Port: 0,
readTimeout: &noReadWriteTimeout,
writeTimeout: &noReadWriteTimeout,
}, nil
},
}
for name, f := range testCases {
t.Run(name, func(t *testing.T) {
Expand Down
23 changes: 23 additions & 0 deletions v2/protocol/http/protocol.go
Expand Up @@ -70,6 +70,18 @@ type Protocol struct {
// If 0, DefaultShutdownTimeout is used.
ShutdownTimeout time.Duration

// readTimeout defines the http.Server ReadTimeout It is the maximum duration
// for reading the entire request, including the body. If not overwritten by an
// option, the default value (600s) is used
readTimeout *time.Duration

// writeTimeout defines the http.Server WriteTimeout It is the maximum duration
// before timing out writes of the response. It is reset whenever a new
// request's header is read. Like ReadTimeout, it does not let Handlers make
// decisions on a per-request basis. If not overwritten by an option, the
// default value (600s) is used
writeTimeout *time.Duration

// Port is the port configured to bind the receiver to. Defaults to 8080.
// If you want to know the effective port you're listening to, use GetListeningPort()
Port int
Expand Down Expand Up @@ -116,6 +128,17 @@ func New(opts ...Option) (*Protocol, error) {
p.ShutdownTimeout = DefaultShutdownTimeout
}

// use default timeout from abuse protection value
defaultTimeout := DefaultTimeout

if p.readTimeout == nil {
p.readTimeout = &defaultTimeout
}

if p.writeTimeout == nil {
p.writeTimeout = &defaultTimeout
}

if p.isRetriableFunc == nil {
p.isRetriableFunc = defaultIsRetriableFunc
}
Expand Down
4 changes: 2 additions & 2 deletions v2/protocol/http/protocol_lifecycle.go
Expand Up @@ -40,8 +40,8 @@ func (p *Protocol) OpenInbound(ctx context.Context) error {
p.server = &http.Server{
Addr: listener.Addr().String(),
Handler: attachMiddleware(p.Handler, p.middleware),
ReadTimeout: DefaultTimeout,
WriteTimeout: DefaultTimeout,
ReadTimeout: *p.readTimeout,
WriteTimeout: *p.writeTimeout,
}

// Shutdown
Expand Down
3 changes: 3 additions & 0 deletions v2/protocol/http/protocol_test.go
Expand Up @@ -26,6 +26,7 @@ import (

func TestNew(t *testing.T) {
dst := DefaultShutdownTimeout
ot := DefaultTimeout

testCases := map[string]struct {
opts []Option
Expand All @@ -36,6 +37,8 @@ func TestNew(t *testing.T) {
want: &Protocol{
Client: http.DefaultClient,
ShutdownTimeout: dst,
readTimeout: &ot,
writeTimeout: &ot,
Port: -1,
},
},
Expand Down