diff --git a/cerberus_test.go b/cerberus_test.go index 677ea0d..7067cb5 100644 --- a/cerberus_test.go +++ b/cerberus_test.go @@ -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 { diff --git a/http.go b/http.go index c9a1b4b..ac44856 100644 --- a/http.go +++ b/http.go @@ -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