"log"
"net"
"net/http"
+ "net/textproto"
"os"
"os/exec"
"path/filepath"
continue
}
header, val := parts[0], parts[1]
- header = strings.TrimSpace(header)
- val = strings.TrimSpace(val)
+ header = textproto.TrimString(header)
+ val = textproto.TrimString(val)
switch {
case header == "Status":
if len(val) < 3 {
import (
"log"
"net"
+ "net/textproto"
"strconv"
"strings"
"time"
}
cookies := make([]*Cookie, 0, cookieCount)
for _, line := range h["Set-Cookie"] {
- parts := strings.Split(strings.TrimSpace(line), ";")
+ parts := strings.Split(textproto.TrimString(line), ";")
if len(parts) == 1 && parts[0] == "" {
continue
}
- parts[0] = strings.TrimSpace(parts[0])
+ parts[0] = textproto.TrimString(parts[0])
j := strings.Index(parts[0], "=")
if j < 0 {
continue
Raw: line,
}
for i := 1; i < len(parts); i++ {
- parts[i] = strings.TrimSpace(parts[i])
+ parts[i] = textproto.TrimString(parts[i])
if len(parts[i]) == 0 {
continue
}
cookies := make([]*Cookie, 0, len(lines)+strings.Count(lines[0], ";"))
for _, line := range lines {
- line = strings.TrimSpace(line)
+ line = textproto.TrimString(line)
var part string
for len(line) > 0 { // continue since we have rest
} else {
part, line = line, ""
}
- part = strings.TrimSpace(part)
+ part = textproto.TrimString(part)
if len(part) == 0 {
continue
}
var ranges []httpRange
noOverlap := false
for _, ra := range strings.Split(s[len(b):], ",") {
- ra = strings.TrimSpace(ra)
+ ra = textproto.TrimString(ra)
if ra == "" {
continue
}
if i < 0 {
return nil, errors.New("invalid range")
}
- start, end := strings.TrimSpace(ra[:i]), strings.TrimSpace(ra[i+1:])
+ start, end := textproto.TrimString(ra[:i]), textproto.TrimString(ra[i+1:])
var r httpRange
if start == "" {
// If no start is specified, end specifies the
"fmt"
"io/ioutil"
"net/http"
+ "net/textproto"
"strconv"
"strings"
// This a modified version of same function found in net/http/transfer.go. This
// one just ignores an invalid header.
func parseContentLength(cl string) int64 {
- cl = strings.TrimSpace(cl)
+ cl = textproto.TrimString(cl)
if cl == "" {
return -1
}
"log"
"net"
"net/http"
+ "net/textproto"
"net/url"
"strings"
"sync"
func removeConnectionHeaders(h http.Header) {
for _, f := range h["Connection"] {
for _, sf := range strings.Split(f, ",") {
- if sf = strings.TrimSpace(sf); sf != "" {
+ if sf = textproto.TrimString(sf); sf != "" {
h.Del(sf)
}
}
// Content-Length headers if they differ in value.
// If there are dups of the value, remove the dups.
// See Issue 16490.
- first := strings.TrimSpace(contentLens[0])
+ first := textproto.TrimString(contentLens[0])
for _, ct := range contentLens[1:] {
- if first != strings.TrimSpace(ct) {
+ if first != textproto.TrimString(ct) {
return 0, fmt.Errorf("http: message cannot contain multiple Content-Length headers; got %q", contentLens)
}
}
// Logic based on Content-Length
var cl string
if len(contentLens) == 1 {
- cl = strings.TrimSpace(contentLens[0])
+ cl = textproto.TrimString(contentLens[0])
}
if cl != "" {
n, err := parseContentLength(cl)
// parseContentLength trims whitespace from s and returns -1 if no value
// is set, or the value if it's >= 0.
func parseContentLength(cl string) (int64, error) {
- cl = strings.TrimSpace(cl)
+ cl = textproto.TrimString(cl)
if cl == "" {
return -1, nil
}