Add challenge page parser util

This commit is contained in:
y a t s
2026-02-09 09:06:19 -05:00
parent 34ceeced8f
commit 8f868a3930
2 changed files with 17 additions and 3 deletions

View File

@@ -13,7 +13,7 @@ import (
"golang.org/x/net/proxy"
)
const _TEST_HOST = "kiwifarms.jp"
const _TEST_HOST = "kiwifarms.st"
const _TEST_ONION = "kiwifarmsaaf4t2h7gc3dfc5ojhmqruw2nit3uejrpiagrxeuxiyxcyd.onion"
type errBadZeroCheck struct {

18
http.go
View File

@@ -70,6 +70,21 @@ func NewChallenge(ctx context.Context, hc http.Client, host string) (Challenge,
return c, nil
}
func ParseChallenge(r io.Reader, host string) (Challenge, error) {
u, err := parseHost(host)
if err != nil {
return Challenge{}, err
}
c, err := parseTags(r)
if err != nil {
return Challenge{}, err
}
c.host = u
return c, nil
}
// Submit a Solution for a Challenge.
//
// If redirect is empty, "/" is used as a sensible default.
@@ -137,8 +152,7 @@ func postSolution(ctx context.Context, hc http.Client, s Solution) (*http.Respon
// TODO: Additionally verify failure from response JSON. Maybe include resp body in err type.
// Rejected solution response: status=400 body={"success":false,"reason":"invalid_solution","action":"retry"}
if resp.StatusCode == 400 {
defer resp.Body.Close()
return nil, &ErrInvalidSolution{s}
return resp, &ErrInvalidSolution{s}
}
return resp, nil