From 9d3d523309eae7cbb501b8d17abcb9d5bf49baff Mon Sep 17 00:00:00 2001 From: dingjun Date: Thu, 1 Sep 2022 14:41:32 +0800 Subject: [PATCH] line ending: crlf->lf --- client_https.go | 118 ++++++++++++++++++++++++------------------------ 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/client_https.go b/client_https.go index ad4127e..c326b81 100644 --- a/client_https.go +++ b/client_https.go @@ -1,59 +1,59 @@ -package main - -import ( - "bytes" - "context" - "fmt" - "io" - "net/http" - "time" - - "github.com/miekg/dns" -) - -type httpclient struct { - Net string - Timeout time.Duration - HTTPClient *http.Client -} - -func (c *httpclient) Exchange(msg *dns.Msg, upstream string) (*dns.Msg, int, error) { - data, err := msg.Pack() - if err != nil { - return nil, 0, err - } - - req, err := http.NewRequest("POST", upstream, bytes.NewReader(data)) - if err != nil { - return nil, 0, err - } - - req.Header.Set("Content-Type", dnsMsgType) - - ctx, cancel := context.WithTimeout(context.Background(), c.Timeout) - defer cancel() - - req = req.WithContext(ctx) - - resp, err := c.HTTPClient.Do(req) - if err != nil { - return nil, 0, err - } - defer resp.Body.Close() - - if resp.StatusCode != http.StatusOK { - return nil, 0, fmt.Errorf("http error %d", resp.StatusCode) - } - - data, err = io.ReadAll(resp.Body) - if err != nil { - return nil, 0, err - } - - m := new(dns.Msg) - if err = m.Unpack(data); err != nil { - return nil, 0, err - } - - return m, 0, nil -} +package main + +import ( + "bytes" + "context" + "fmt" + "io" + "net/http" + "time" + + "github.com/miekg/dns" +) + +type httpclient struct { + Net string + Timeout time.Duration + HTTPClient *http.Client +} + +func (c *httpclient) Exchange(msg *dns.Msg, upstream string) (*dns.Msg, int, error) { + data, err := msg.Pack() + if err != nil { + return nil, 0, err + } + + req, err := http.NewRequest("POST", upstream, bytes.NewReader(data)) + if err != nil { + return nil, 0, err + } + + req.Header.Set("Content-Type", dnsMsgType) + + ctx, cancel := context.WithTimeout(context.Background(), c.Timeout) + defer cancel() + + req = req.WithContext(ctx) + + resp, err := c.HTTPClient.Do(req) + if err != nil { + return nil, 0, err + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + return nil, 0, fmt.Errorf("http error %d", resp.StatusCode) + } + + data, err = io.ReadAll(resp.Body) + if err != nil { + return nil, 0, err + } + + m := new(dns.Msg) + if err = m.Unpack(data); err != nil { + return nil, 0, err + } + + return m, 0, nil +}