appview/oauth: allow customizing client timeouts in xrpc reqs #841

merged
opened by oppi.li targeting master from op/tzszvtloukvm
Changed files
+15 -2
appview
oauth
+15 -2
appview/oauth/oauth.go
··· 202 exp int64 203 lxm string 204 dev bool 205 } 206 207 type ServiceClientOpt func(*ServiceClientOpts) 208 209 func WithService(service string) ServiceClientOpt { 210 return func(s *ServiceClientOpts) { 211 s.service = service ··· 233 } 234 } 235 236 func (s *ServiceClientOpts) Audience() string { 237 return fmt.Sprintf("did:web:%s", s.service) 238 } ··· 247 } 248 249 func (o *OAuth) ServiceClient(r *http.Request, os ...ServiceClientOpt) (*xrpc.Client, error) { 250 - opts := ServiceClientOpts{} 251 for _, o := range os { 252 o(&opts) 253 } ··· 274 }, 275 Host: opts.Host(), 276 Client: &http.Client{ 277 - Timeout: time.Second * 5, 278 }, 279 }, nil 280 }
··· 202 exp int64 203 lxm string 204 dev bool 205 + timeout time.Duration 206 } 207 208 type ServiceClientOpt func(*ServiceClientOpts) 209 210 + func DefaultServiceClientOpts() ServiceClientOpts { 211 + return ServiceClientOpts{ 212 + timeout: time.Second * 5, 213 + } 214 + } 215 + 216 func WithService(service string) ServiceClientOpt { 217 return func(s *ServiceClientOpts) { 218 s.service = service ··· 240 } 241 } 242 243 + func WithTimeout(timeout time.Duration) ServiceClientOpt { 244 + return func(s *ServiceClientOpts) { 245 + s.timeout = timeout 246 + } 247 + } 248 + 249 func (s *ServiceClientOpts) Audience() string { 250 return fmt.Sprintf("did:web:%s", s.service) 251 } ··· 260 } 261 262 func (o *OAuth) ServiceClient(r *http.Request, os ...ServiceClientOpt) (*xrpc.Client, error) { 263 + opts := DefaultServiceClientOpts() 264 for _, o := range os { 265 o(&opts) 266 } ··· 287 }, 288 Host: opts.Host(), 289 Client: &http.Client{ 290 + Timeout: opts.timeout, 291 }, 292 }, nil 293 }