Skip to content

Commit

Permalink
Backup 3 (#1)
Browse files Browse the repository at this point in the history
* allow context to override the default timeout

Signed-off-by: Noah Kreiger <[email protected]>

* test

Signed-off-by: Noah Kreiger <[email protected]>

* move back

Signed-off-by: Noah Kreiger <[email protected]>

* mod it

Signed-off-by: Noah Kreiger <[email protected]>

* reverse

Signed-off-by: Noah Kreiger <[email protected]>

* Update README.md

Signed-off-by: Pouya Vedadiyan <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Bump andstor/file-existence-action from 2 to 3

Bumps [andstor/file-existence-action](https://github.com/andstor/file-existence-action) from 2 to 3.
- [Release notes](https://github.com/andstor/file-existence-action/releases)
- [Commits](andstor/file-existence-action@v2...v3)

---
updated-dependencies:
- dependency-name: andstor/file-existence-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /test/conformance

Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.14.0 to 0.17.0.
- [Commits](golang/crypto@v0.14.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /test/benchmark

Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.14.0 to 0.17.0.
- [Commits](golang/crypto@v0.14.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /samples/kafka

Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.14.0 to 0.17.0.
- [Commits](golang/crypto@v0.14.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /test/integration

Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.14.0 to 0.17.0.
- [Commits](golang/crypto@v0.14.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Bump golang.org/x/crypto in /protocol/kafka_sarama/v2

Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.14.0 to 0.17.0.
- [Commits](golang/crypto@v0.14.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /samples/http

Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.14.0 to 0.17.0.
- [Commits](golang/crypto@v0.14.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /samples/nats

Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.14.0 to 0.17.0.
- [Commits](golang/crypto@v0.14.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /samples/stan

Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.14.0 to 0.17.0.
- [Commits](golang/crypto@v0.14.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Bump golang.org/x/crypto in /samples/nats_jetstream

Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.14.0 to 0.17.0.
- [Commits](golang/crypto@v0.14.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /protocol/nats/v2

Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.14.0 to 0.17.0.
- [Commits](golang/crypto@v0.14.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Bump golang.org/x/crypto in /protocol/nats_jetstream/v2

Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.14.0 to 0.17.0.
- [Commits](golang/crypto@v0.14.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Bump golang.org/x/crypto from 0.14.0 to 0.17.0 in /protocol/stan/v2

Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.14.0 to 0.17.0.
- [Commits](golang/crypto@v0.14.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* proposal the confluent binding for kafka

Signed-off-by: myan <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* sync-tck-tests-2024.01.30

Signed-off-by: Calum Murray <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* fix a few test cases

Signed-off-by: Calum Murray <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* fix like expression parser

Signed-off-by: Calum Murray <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Fix docstring typos in nats and jetstream protocol

Signed-off-by: John A. Fossum <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Bump golangci/golangci-lint-action from 3 to 4

Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 3 to 4.
- [Release notes](https://github.com/golangci/golangci-lint-action/releases)
- [Commits](golangci/golangci-lint-action@v3...v4)

---
updated-dependencies:
- dependency-name: golangci/golangci-lint-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Bump the bundler group across 1 directories with 1 update

Bumps the bundler group with 1 update in the /docs directory: [nokogiri](https://github.com/sparklemotion/nokogiri).

Updates `nokogiri` from 1.14.3 to 1.16.2
- [Release notes](https://github.com/sparklemotion/nokogiri/releases)
- [Changelog](https://github.com/sparklemotion/nokogiri/blob/main/CHANGELOG.md)
- [Commits](sparklemotion/nokogiri@v1.14.3...v1.16.2)

---
updated-dependencies:
- dependency-name: nokogiri
  dependency-type: indirect
  dependency-group: bundler-security-group
...

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* oops

Signed-off-by: Doug Davis <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Avoid modifying the DefaultClient's Transport

Signed-off-by: Nghia Tran <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Update v2/protocol/http/protocol.go

Signed-off-by: Noah Kreiger <[email protected]>

* Bump the go_modules group across 2 directories with 1 update

Bumps the go_modules group with 1 update in the /test/sql directory: [github.com/cloudevents/sdk-go/v2](https://github.com/cloudevents/sdk-go).

Updates `github.com/cloudevents/sdk-go/v2` from 2.14.0 to 2.15.2
- [Release notes](https://github.com/cloudevents/sdk-go/releases)
- [Commits](v2.14.0...v2.15.2)

---
updated-dependencies:
- dependency-name: github.com/cloudevents/sdk-go/v2
  dependency-type: direct:production
  dependency-group: go_modules-security-group
...

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Bump the go_modules group across 4 directories with 1 update

Bumps the go_modules group with 1 update in the /binding/format/protobuf/v2 directory: google.golang.org/protobuf.
Bumps the go_modules group with 1 update in the /protocol/pubsub/v2 directory: google.golang.org/protobuf.
Bumps the go_modules group with 1 update in the /samples/http directory: google.golang.org/protobuf.
Bumps the go_modules group with 1 update in the /samples/pubsub directory: google.golang.org/protobuf.

Updates `google.golang.org/protobuf` from 1.26.0 to 1.33.0

Updates `google.golang.org/protobuf` from 1.30.0 to 1.33.0

Updates `google.golang.org/protobuf` from 1.30.0 to 1.33.0

Updates `google.golang.org/protobuf` from 1.30.0 to 1.33.0

---
updated-dependencies:
- dependency-name: google.golang.org/protobuf
  dependency-type: direct:production
  dependency-group: go_modules-security-group
- dependency-name: google.golang.org/protobuf
  dependency-type: indirect
  dependency-group: go_modules-security-group
- dependency-name: google.golang.org/protobuf
  dependency-type: direct:production
  dependency-group: go_modules-security-group
- dependency-name: google.golang.org/protobuf
  dependency-type: indirect
  dependency-group: go_modules-security-group
...

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Bump the go_modules group across 1 directory with 1 update

Bumps the go_modules group with 1 update in the /samples/http directory: [github.com/gin-gonic/gin](https://github.com/gin-gonic/gin).

Updates `github.com/gin-gonic/gin` from 1.8.2 to 1.9.1
- [Release notes](https://github.com/gin-gonic/gin/releases)
- [Changelog](https://github.com/gin-gonic/gin/blob/master/CHANGELOG.md)
- [Commits](gin-gonic/gin@v1.8.2...v1.9.1)

---
updated-dependencies:
- dependency-name: github.com/gin-gonic/gin
  dependency-type: direct:production
  dependency-group: go_modules-security-group
...

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* confluent kafka binding

Signed-off-by: myan <[email protected]>

add message implementation

Signed-off-by: myan <[email protected]>

add ut test

Signed-off-by: myan <[email protected]>

add integration test

Signed-off-by: myan <[email protected]>

add integration test and samples

Signed-off-by: Meng Yan <[email protected]>

offset

Signed-off-by: Meng Yan <[email protected]>

remove the ctx

Signed-off-by: myan <[email protected]>

 review

Signed-off-by: Meng Yan <[email protected]>

remove

Signed-off-by: Meng Yan <[email protected]>

init consumer and producer on 1 client

Signed-off-by: myan <[email protected]>

reply the reviews

Signed-off-by: myan <[email protected]>

fix the ci

Signed-off-by: myan <[email protected]>

ci fix

Signed-off-by: Meng Yan <[email protected]>

add confluent test in github action

Signed-off-by: Meng Yan <[email protected]>

add the mis-used test case

Signed-off-by: Meng Yan <[email protected]>

remove the invalidated bootstrapserver

Signed-off-by: Meng Yan <[email protected]>

log kafka error message

Signed-off-by: myan <[email protected]>

review

Signed-off-by: myan <[email protected]>

Update protocol/kafka_confluent/v2/option.go

Co-authored-by: Michael Gasch <[email protected]>
Signed-off-by: myan <[email protected]>

add the auto recover option

Signed-off-by: myan <[email protected]>

kafka error handler

Signed-off-by: myan <[email protected]>

remove the delievery chan

Signed-off-by: myan <[email protected]>

Update protocol/kafka_confluent/v2/protocol.go

Co-authored-by: Michael Gasch <[email protected]>

Update protocol/kafka_confluent/v2/protocol.go

Co-authored-by: Michael Gasch <[email protected]>

Update protocol/kafka_confluent/v2/option.go

Co-authored-by: Michael Gasch <[email protected]>

Update protocol/kafka_confluent/v2/protocol.go

Co-authored-by: Michael Gasch <[email protected]>

reply review

Signed-off-by: myan <[email protected]>

modify the git action

Signed-off-by: Meng Yan <[email protected]>

reply review

Signed-off-by: Meng Yan <[email protected]>

reply review

Signed-off-by: Meng Yan <[email protected]>

handle race condition between sender and closer

Signed-off-by: Meng Yan <[email protected]>

reply review

Signed-off-by: Meng Yan <[email protected]>

reply review1

Signed-off-by: Meng Yan <[email protected]>

add defer close

Signed-off-by: Meng Yan <[email protected]>

add comment

Signed-off-by: Meng Yan <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Add eventHandler option for confluent kafka producer

Signed-off-by: Meng Yan <[email protected]>

reply review

Signed-off-by: Meng Yan <[email protected]>

Update protocol/kafka_confluent/v2/protocol.go

Co-authored-by: Michael Gasch <[email protected]>
Signed-off-by: Meng Yan <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Support content types following structured syntax suffixes

This enables the encoding/decoding of custom content types which
use the `+json` or `+xml` suffix to indicate that their encoding
is JSON or XML respectively. Users can also add their own suffixes
to the registry in a similar fashion to how `datacodec.AddDecoder()`
and `dataodec.AddEncoder()` work, but via the `AddStructuredSuffixDecoder`
and `AddStructuredSuffixEncoder` functions.

Signed-off-by: dan-j <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Bump the go_modules group across 9 directories with 1 update

Bumps the go_modules group with 1 update in the /observability/opencensus/v2 directory: [golang.org/x/net](https://github.com/golang/net).
Bumps the go_modules group with 1 update in the /protocol/kafka_sarama/v2 directory: [golang.org/x/net](https://github.com/golang/net).
Bumps the go_modules group with 1 update in the /protocol/pubsub/v2 directory: [golang.org/x/net](https://github.com/golang/net).
Bumps the go_modules group with 1 update in the /samples/http directory: [golang.org/x/net](https://github.com/golang/net).
Bumps the go_modules group with 1 update in the /samples/kafka directory: [golang.org/x/net](https://github.com/golang/net).
Bumps the go_modules group with 1 update in the /samples/pubsub directory: [golang.org/x/net](https://github.com/golang/net).
Bumps the go_modules group with 1 update in the /test/benchmark directory: [golang.org/x/net](https://github.com/golang/net).
Bumps the go_modules group with 1 update in the /test/conformance directory: [golang.org/x/net](https://github.com/golang/net).
Bumps the go_modules group with 1 update in the /test/integration directory: [golang.org/x/net](https://github.com/golang/net).

Updates `golang.org/x/net` from 0.17.0 to 0.23.0
- [Commits](golang/net@v0.17.0...v0.23.0)

Updates `golang.org/x/net` from 0.17.0 to 0.23.0
- [Commits](golang/net@v0.17.0...v0.23.0)

Updates `golang.org/x/net` from 0.17.0 to 0.23.0
- [Commits](golang/net@v0.17.0...v0.23.0)

Updates `golang.org/x/net` from 0.17.0 to 0.23.0
- [Commits](golang/net@v0.17.0...v0.23.0)

Updates `golang.org/x/net` from 0.17.0 to 0.23.0
- [Commits](golang/net@v0.17.0...v0.23.0)

Updates `golang.org/x/net` from 0.17.0 to 0.23.0
- [Commits](golang/net@v0.17.0...v0.23.0)

Updates `golang.org/x/net` from 0.17.0 to 0.23.0
- [Commits](golang/net@v0.17.0...v0.23.0)

Updates `golang.org/x/net` from 0.17.0 to 0.23.0
- [Commits](golang/net@v0.17.0...v0.23.0)

Updates `golang.org/x/net` from 0.17.0 to 0.23.0
- [Commits](golang/net@v0.17.0...v0.23.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: indirect
  dependency-group: go_modules
- dependency-name: golang.org/x/net
  dependency-type: indirect
  dependency-group: go_modules
- dependency-name: golang.org/x/net
  dependency-type: indirect
  dependency-group: go_modules
- dependency-name: golang.org/x/net
  dependency-type: indirect
  dependency-group: go_modules
- dependency-name: golang.org/x/net
  dependency-type: indirect
  dependency-group: go_modules
- dependency-name: golang.org/x/net
  dependency-type: indirect
  dependency-group: go_modules
- dependency-name: golang.org/x/net
  dependency-type: indirect
  dependency-group: go_modules
- dependency-name: golang.org/x/net
  dependency-type: indirect
  dependency-group: go_modules
- dependency-name: golang.org/x/net
  dependency-type: indirect
  dependency-group: go_modules
...

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* move to protocol

Signed-off-by: Noah Kreiger <[email protected]>

* reset

Signed-off-by: Noah Kreiger <[email protected]>

* fix go.mod

Signed-off-by: Noah Kreiger <[email protected]>

* add/update tests

Signed-off-by: Noah Kreiger <[email protected]>

* Update v2/protocol/http/options_test.go

Co-authored-by: Michael Gasch <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* update based on comments, update comment

Signed-off-by: Noah Kreiger <[email protected]>

* fix: support multiple amqp data fields

Ref: cloudevents/spec#1275
Signed-off-by: Michael Gasch <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* chore: add codeowners file

Closes: #1037
Signed-off-by: Michael Gasch <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Update v2/protocol/http/protocol.go

Co-authored-by: Michael Gasch <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* Update v2/protocol/http/protocol.go

Co-authored-by: Michael Gasch <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>

* resolve issues, add timeout

Signed-off-by: Noah Kreiger <[email protected]>

* updated tests, and enforce no negative

Signed-off-by: Noah Kreiger <[email protected]>

* updated with pointer

Signed-off-by: Noah Kreiger <[email protected]>

* add changes based on feedback

Signed-off-by: Noah Kreiger <[email protected]>

---------

Signed-off-by: Noah Kreiger <[email protected]>
Signed-off-by: Pouya Vedadiyan <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: myan <[email protected]>
Signed-off-by: Calum Murray <[email protected]>
Signed-off-by: John A. Fossum <[email protected]>
Signed-off-by: Doug Davis <[email protected]>
Signed-off-by: Nghia Tran <[email protected]>
Signed-off-by: Meng Yan <[email protected]>
Signed-off-by: dan-j <[email protected]>
Signed-off-by: Michael Gasch <[email protected]>
Co-authored-by: Pouya Vedadiyan <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: myan <[email protected]>
Co-authored-by: Calum Murray <[email protected]>
Co-authored-by: John A. Fossum <[email protected]>
Co-authored-by: Doug Davis <[email protected]>
Co-authored-by: Nghia Tran <[email protected]>
Co-authored-by: Matt Moore <[email protected]>
Co-authored-by: Michael Gasch <[email protected]>
Co-authored-by: dan-j <[email protected]>
Signed-off-by: Noah Kreiger <[email protected]>
  • Loading branch information
11 people committed Apr 27, 2024
1 parent 9c00184 commit f80c9e2
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 4 deletions.
32 changes: 32 additions & 0 deletions v2/protocol/http/options.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit f80c9e2

Please sign in to comment.