Skip to content

Commit

Permalink
adding user configurable read timeouts (#901)
Browse files Browse the repository at this point in the history
* making default timeout user configurable

* editing tests to pass & cleanup

* adding comment to GetTimeout

* moving timeout to config only and removing unnecessary timeout params

* adding hidden flag, removing config/profile timeout related functions

* removing timeout from playback (not needed)
  • Loading branch information
joyluu-stripe committed Jun 28, 2022
1 parent ad4cf2a commit 8af2aaa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pkg/cmd/listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type listenCmd struct {
skipUpdate bool
apiBaseURL string
noWSS bool
timeout int64
}

func newListenCmd() *listenCmd {
Expand Down Expand Up @@ -86,6 +87,9 @@ Stripe account.`,
lc.cmd.Flags().BoolVar(&lc.noWSS, "no-wss", false, "Force unencrypted ws:// protocol instead of wss://")
lc.cmd.Flags().MarkHidden("no-wss") // #nosec G104

lc.cmd.Flags().Int64Var(&lc.timeout, "timeout", 30, "Sets timeout duration")
lc.cmd.Flags().MarkHidden("timeout")

// renamed --load-from-webhooks-api to --use-configured-webhooks, but want to keep backward compatibility
lc.cmd.Flags().SetNormalizeFunc(func(f *pflag.FlagSet, name string) pflag.NormalizedName {
if name == "load-from-webhooks-api" {
Expand Down Expand Up @@ -149,6 +153,7 @@ func (lc *listenCmd) runListenCmd(cmd *cobra.Command, args []string) error {
SkipVerify: lc.skipVerify,
Log: logger,
NoWSS: lc.noWSS,
Timeout: lc.timeout,
Events: lc.events,
OutCh: proxyOutCh,
})
Expand Down
4 changes: 3 additions & 1 deletion pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ type Config struct {
Log *log.Logger
// Force use of unencrypted ws:// protocol instead of wss://
NoWSS bool
// Override default timeout
Timeout int64

// OutCh is the channel to send logs and statuses to for processing in other packages
OutCh chan websocket.IElement
Expand Down Expand Up @@ -535,7 +537,7 @@ func Init(ctx context.Context, cfg *Config) (*Proxy, error) {
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
Timeout: defaultTimeout,
Timeout: time.Duration(cfg.Timeout) * time.Second,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: cfg.SkipVerify},
},
Expand Down

0 comments on commit 8af2aaa

Please sign in to comment.