From b9f1a1f71a5b177565e6a0c731a7f20c73f05285 Mon Sep 17 00:00:00 2001 From: John Beisley Date: Thu, 2 Jan 2014 22:13:21 +0000 Subject: [PATCH] Reduce headers written by httpu, in case this confuses some devices. --- httpu/httpu.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/httpu/httpu.go b/httpu/httpu.go index 388d48c..1b34c25 100644 --- a/httpu/httpu.go +++ b/httpu/httpu.go @@ -47,10 +47,24 @@ func (httpu *HTTPUClient) Do(req *http.Request, timeout time.Duration, numSends httpu.connLock.Lock() defer httpu.connLock.Unlock() + // Create the request. This is a subset of what http.Request.Write does + // deliberately to avoid creating extra fields which may confuse some + // devices. var requestBuf bytes.Buffer - if err := req.Write(&requestBuf); err != nil { + method := req.Method + if method == "" { + method = "GET" + } + if _, err := fmt.Fprintf(&requestBuf, "%s %s HTTP/1.1\r\n", method, req.URL.RequestURI()); err != nil { return nil, err } + if err := req.Header.Write(&requestBuf); err != nil { + return nil, err + } + if _, err := requestBuf.Write([]byte{'\r', '\n'}); err != nil { + return nil, err + } + destAddr, err := net.ResolveUDPAddr("udp", req.Host) if err != nil { return nil, err