aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorAdnan Maolood <[email protected]>2020-12-18 00:12:32 -0500
committerAdnan Maolood <[email protected]>2020-12-18 00:12:32 -0500
commite2c907a7f65a98a1737ffe50f55d6c7dfa9abb9e (patch)
tree2bf87afb600fde3843ea09536965896955ecedb0 /client.go
parentUpdate switch statement (diff)
downloadgo-gemini-e2c907a7f65a98a1737ffe50f55d6c7dfa9abb9e.tar.xz
go-gemini-e2c907a7f65a98a1737ffe50f55d6c7dfa9abb9e.zip
client: Remove GetInput and CheckRedirect callbacks
Diffstat (limited to 'client.go')
-rw-r--r--client.go53
1 files changed, 1 insertions, 52 deletions
diff --git a/client.go b/client.go
index 7eea9d8..2dc2ccc 100644
--- a/client.go
+++ b/client.go
@@ -6,7 +6,6 @@ import (
"crypto/tls"
"crypto/x509"
"net"
- "net/url"
"strings"
"time"
)
@@ -20,15 +19,6 @@ type Client struct {
// and the request will be aborted.
TrustCertificate func(hostname string, cert *x509.Certificate) error
- // GetInput is called to retrieve input when the server requests it.
- // If GetInput is nil or returns false, no input will be sent and
- // the response will be returned.
- GetInput func(prompt string, sensitive bool) (input string, ok bool)
-
- // CheckRedirect determines whether to follow a redirect.
- // If CheckRedirect is nil, redirects will not be followed.
- CheckRedirect func(req *Request, via []*Request) error
-
// Timeout specifies a time limit for requests made by this
// Client. The timeout includes connection time and reading
// the response body. The timer remains running after
@@ -49,10 +39,6 @@ func (c *Client) Get(url string) (*Response, error) {
// Do performs a Gemini request and returns a Gemini response.
func (c *Client) Do(req *Request) (*Response, error) {
- return c.do(req, nil)
-}
-
-func (c *Client) do(req *Request, via []*Request) (*Response, error) {
// Extract hostname
colonPos := strings.LastIndex(req.Host, ":")
if colonPos == -1 {
@@ -75,7 +61,7 @@ func (c *Client) do(req *Request, via []*Request) (*Response, error) {
},
ServerName: hostname,
}
-
+ // Set connection context
ctx := req.Context
if ctx == nil {
ctx = context.Background()
@@ -106,43 +92,6 @@ func (c *Client) do(req *Request, via []*Request) (*Response, error) {
// Store connection state
resp.TLS = conn.ConnectionState()
- switch resp.Status.Class() {
- case StatusClassInput:
- if c.GetInput == nil {
- break
- }
-
- input, ok := c.GetInput(resp.Meta, resp.Status == StatusSensitiveInput)
- if ok {
- req.URL.ForceQuery = true
- req.URL.RawQuery = QueryEscape(input)
- return c.do(req, via)
- }
-
- case StatusClassRedirect:
- if c.CheckRedirect == nil {
- break
- }
-
- if via == nil {
- via = []*Request{}
- }
- via = append(via, req)
-
- target, err := url.Parse(resp.Meta)
- if err != nil {
- return resp, err
- }
- target = req.URL.ResolveReference(target)
-
- redirect := NewRequestFromURL(target)
- redirect.Context = req.Context
- if err := c.CheckRedirect(redirect, via); err != nil {
- return resp, err
- }
- return c.do(redirect, via)
- }
-
return resp, nil
}