Skip to content

Commit

Permalink
fix(httppull): refresh token before header parsing (#2100)
Browse files Browse the repository at this point in the history
Signed-off-by: xjasonlyu <[email protected]>
  • Loading branch information
xjasonlyu committed Jul 17, 2023
1 parent 03b8543 commit 89d955d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions internal/io/http/httppull_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ func (hps *PullSource) doPull(ctx api.StreamContext, rcvTime time.Time, omd5 *st
}
}

// check oAuth token expiration
if hps.accessConf != nil && hps.accessConf.ExpireInSecond > 0 &&
int(time.Now().Sub(hps.tokenLastUpdateAt).Abs().Seconds()) >= hps.accessConf.ExpireInSecond {
ctx.GetLogger().Debugf("Refreshing token for HTTP pull")
if err := hps.refresh(ctx); err != nil {
ctx.GetLogger().Warnf("Refresh HTTP pull token error: %v", err)
}
}
headers, err := hps.parseHeaders(ctx, hps.tokens)
if err != nil {
return []api.SourceTuple{
Expand All @@ -106,14 +114,6 @@ func (hps *PullSource) doPull(ctx api.StreamContext, rcvTime time.Time, omd5 *st
},
}
}
// check oAuth token expiration
if hps.accessConf != nil && hps.accessConf.ExpireInSecond > 0 &&
int(time.Now().Sub(hps.tokenLastUpdateAt).Abs().Seconds()) >= hps.accessConf.ExpireInSecond {
ctx.GetLogger().Debugf("Refreshing token")
if err := hps.refresh(ctx); err != nil {
ctx.GetLogger().Warnf("Refresh token error: %v", err)
}
}
ctx.GetLogger().Debugf("httppull source sending request url: %s, headers: %v, body %s", url, headers, hps.config.Body)
if resp, e := httpx.Send(ctx.GetLogger(), hps.client, hps.config.BodyType, hps.config.Method, url, headers, true, body); e != nil {
ctx.GetLogger().Warnf("Found error %s when trying to reach %v ", e, hps)
Expand Down

0 comments on commit 89d955d

Please sign in to comment.