Source File
response.go
Belonging Package
net/http
type Response struct {
Status string // e.g. "200 OK"
StatusCode int // e.g. 200
Proto string // e.g. "HTTP/1.0"
ProtoMajor int // e.g. 1
ProtoMinor int // e.g. 0
func ( *Response) () []*Cookie {
return readSetCookies(.Header)
}
var ErrNoLocation = errors.New("http: no Location header in response")
, := .ReadLine()
if != nil {
if == io.EOF {
= io.ErrUnexpectedEOF
}
return nil,
}
if := strings.IndexByte(, ' '); == -1 {
return nil, badStringError("malformed HTTP response", )
} else {
.Proto = [:]
.Status = strings.TrimLeft([+1:], " ")
}
:= .Status
if := strings.IndexByte(.Status, ' '); != -1 {
= .Status[:]
}
if len() != 3 {
return nil, badStringError("malformed HTTP status code", )
}
.StatusCode, = strconv.Atoi()
if != nil || .StatusCode < 0 {
return nil, badStringError("malformed HTTP status code", )
}
var bool
if .ProtoMajor, .ProtoMinor, = ParseHTTPVersion(.Proto); ! {
return nil, badStringError("malformed HTTP version", .Proto)
}
, := .ReadMIMEHeader()
if != nil {
if == io.EOF {
= io.ErrUnexpectedEOF
}
return nil,
}
.Header = Header()
fixPragmaCacheControl(.Header)
= readTransfer(, )
if != nil {
return nil,
}
return , nil
}
func ( *Response) (, int) bool {
return .ProtoMajor > ||
.ProtoMajor == && .ProtoMinor >=
}
:= .Status
if == "" {
var bool
, = statusText[.StatusCode]
if ! {
= "status code " + strconv.Itoa(.StatusCode)
}
= strings.TrimPrefix(, strconv.Itoa(.StatusCode)+" ")
}
if , := fmt.Fprintf(, "HTTP/%d.%d %03d %s\r\n", .ProtoMajor, .ProtoMinor, .StatusCode, ); != nil {
return
}
if .ContentLength == -1 && !.Close && .ProtoAtLeast(1, 1) && !chunked(.TransferEncoding) && !.Uncompressed {
.Close = true
}
, := newTransferWriter()
if != nil {
return
}
= .writeHeader(, nil)
if != nil {
return
}
= .Header.WriteSubset(, respExcludeHeader)
if != nil {
return
}
:= .shouldSendContentLength()
if .ContentLength == 0 && !chunked(.TransferEncoding) && ! && bodyAllowedForStatus(.StatusCode) {
if , := io.WriteString(, "Content-Length: 0\r\n"); != nil {
return
}
}
if , := io.WriteString(, "\r\n"); != nil {
return
}
func ( *Response) () bool {
return isProtocolSwitchResponse(.StatusCode, .Header)
}
func ( int, Header) bool {
return == StatusSwitchingProtocols && isProtocolSwitchHeader()
}
func ( Header) bool {
return .Get("Upgrade") != "" &&
httpguts.HeaderValuesContainsToken(["Connection"], "Upgrade")
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |