diff options
| author | Adnan Maolood <[email protected]> | 2020-10-27 23:35:22 -0400 |
|---|---|---|
| committer | Adnan Maolood <[email protected]> | 2020-10-27 23:35:22 -0400 |
| commit | 4c5167f590384278e211622e7b1ba134bd379c76 (patch) | |
| tree | 0a46b38f5a6b88b640d3ebd0e843efb721dd6311 /client.go | |
| parent | Restrict client certificates to certain paths (diff) | |
| download | go-gemini-4c5167f590384278e211622e7b1ba134bd379c76.tar.xz go-gemini-4c5167f590384278e211622e7b1ba134bd379c76.zip | |
Add Client.GetInput field
Diffstat (limited to 'client.go')
| -rw-r--r-- | client.go | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -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 } |