aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorAdnan Maolood <[email protected]>2020-10-27 23:35:22 -0400
committerAdnan Maolood <[email protected]>2020-10-27 23:35:22 -0400
commit4c5167f590384278e211622e7b1ba134bd379c76 (patch)
tree0a46b38f5a6b88b640d3ebd0e843efb721dd6311 /client.go
parentRestrict client certificates to certain paths (diff)
downloadgo-gemini-4c5167f590384278e211622e7b1ba134bd379c76.tar.xz
go-gemini-4c5167f590384278e211622e7b1ba134bd379c76.zip
Add Client.GetInput field
Diffstat (limited to 'client.go')
-rw-r--r--client.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/client.go b/client.go
index 91402b1..823fa05 100644
--- a/client.go
+++ b/client.go
@@ -24,6 +24,10 @@ type Client struct {
// redirects will be enforced.
CheckRedirect func(req *Request, via []*Request) error
+ // GetInput, if not nil, will be called to retrieve input when the server
+ // requests it.
+ GetInput func(prompt string, sensitive bool) (string, bool)
+
// GetCertificate, if not nil, will be called when a server requests a certificate.
// The returned certificate will be used when sending the request again.
// If the certificate is nil, the request will not be sent again and
@@ -141,7 +145,17 @@ func (c *Client) do(req *Request, via []*Request) (*Response, error) {
return resp, ErrTooManyRedirects
}
return c.do(redirect, via)
+ } else if resp.Status.Class() == StatusClassInput {
+ if c.GetInput != nil {
+ input, ok := c.GetInput(resp.Meta, resp.Status == StatusSensitiveInput)
+ if ok {
+ req.URL.ForceQuery = true
+ req.URL.RawQuery = url.QueryEscape(input)
+ return c.do(req, via)
+ }
+ }
}
+
return resp, nil
}