Set the Content-Length for POST queries
This commit is contained in:
parent
7174fdc8c8
commit
68ff5d2205
|
@ -7,7 +7,6 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -163,7 +162,7 @@ func (xTransport *XTransport) resolve(dnsClient *dns.Client, host string, resolv
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (xTransport *XTransport) Fetch(method string, url *url.URL, accept string, contentType string, body *io.ReadCloser, timeout time.Duration, padding *string) (*http.Response, time.Duration, error) {
|
func (xTransport *XTransport) Fetch(method string, url *url.URL, accept string, contentType string, body *[]byte, timeout time.Duration, padding *string) (*http.Response, time.Duration, error) {
|
||||||
if timeout <= 0 {
|
if timeout <= 0 {
|
||||||
timeout = xTransport.timeout
|
timeout = xTransport.timeout
|
||||||
}
|
}
|
||||||
|
@ -185,7 +184,9 @@ func (xTransport *XTransport) Fetch(method string, url *url.URL, accept string,
|
||||||
Close: false,
|
Close: false,
|
||||||
}
|
}
|
||||||
if body != nil {
|
if body != nil {
|
||||||
req.Body = *body
|
req.ContentLength = int64(len(*body))
|
||||||
|
bc := ioutil.NopCloser(bytes.NewReader(*body))
|
||||||
|
req.Body = bc
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
host := url.Host
|
host := url.Host
|
||||||
|
@ -259,9 +260,9 @@ func (xTransport *XTransport) Get(url *url.URL, accept string, timeout time.Dura
|
||||||
return xTransport.Fetch("GET", url, accept, "", nil, timeout, nil)
|
return xTransport.Fetch("GET", url, accept, "", nil, timeout, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (xTransport *XTransport) Post(url *url.URL, accept string, contentType string, body []byte, timeout time.Duration, padding *string) (*http.Response, time.Duration, error) {
|
func (xTransport *XTransport) Post(url *url.URL, accept string, contentType string, body *[]byte, timeout time.Duration, padding *string) (*http.Response, time.Duration, error) {
|
||||||
bc := ioutil.NopCloser(bytes.NewReader(body))
|
|
||||||
return xTransport.Fetch("POST", url, accept, contentType, &bc, timeout, padding)
|
return xTransport.Fetch("POST", url, accept, contentType, body, timeout, padding)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (xTransport *XTransport) DoHQuery(useGet bool, url *url.URL, body []byte, timeout time.Duration) (*http.Response, time.Duration, error) {
|
func (xTransport *XTransport) DoHQuery(useGet bool, url *url.URL, body []byte, timeout time.Duration) (*http.Response, time.Duration, error) {
|
||||||
|
@ -280,7 +281,7 @@ func (xTransport *XTransport) DoHQuery(useGet bool, url *url.URL, body []byte, t
|
||||||
url2.RawQuery = qs.Encode()
|
url2.RawQuery = qs.Encode()
|
||||||
return xTransport.Get(&url2, dataType, timeout)
|
return xTransport.Get(&url2, dataType, timeout)
|
||||||
}
|
}
|
||||||
return xTransport.Post(url, dataType, dataType, body, timeout, padding)
|
return xTransport.Post(url, dataType, dataType, &body, timeout, padding)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (xTransport *XTransport) makePad(padLen int) *string {
|
func (xTransport *XTransport) makePad(padLen int) *string {
|
||||||
|
|
Loading…
Reference in New Issue