-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix([email protected]): limit number or redirects
Part of ooni/probe#2237
- Loading branch information
1 parent
700f94b
commit afe63b1
Showing
5 changed files
with
81 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package webconnectivity | ||
|
||
import "github.com/ooni/probe-cli/v3/internal/atomicx" | ||
|
||
// NumRedirects counts the number of redirects left. | ||
type NumRedirects struct { | ||
count *atomicx.Int64 | ||
} | ||
|
||
// NewNumRedirects creates a new NumRedirects instance. | ||
func NewNumRedirects(n int64) *NumRedirects { | ||
count := &atomicx.Int64{} | ||
count.Add(n) | ||
return &NumRedirects{ | ||
count: count, | ||
} | ||
} | ||
|
||
// CanFollowOneMoreRedirect returns true if we are | ||
// allowed to follow one more redirect. | ||
func (nr *NumRedirects) CanFollowOneMoreRedirect() bool { | ||
return nr.count.Add(-1) > 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters