Source File
reader.go
Belonging Package
net/textproto
package textproto
import (
)
func ( *bufio.Reader) *Reader {
commonHeaderOnce.Do(initCommonHeader)
return &Reader{R: }
}
func ( *Reader) () (string, error) {
, := .readLineSlice()
return string(),
}
func ( *Reader) () (string, error) {
, := .readContinuedLineSlice(noValidation)
return string(),
}
func ( *Reader) () ([]byte, error) {
, := .readContinuedLineSlice(noValidation)
if != nil {
:= make([]byte, len())
copy(, )
=
}
return ,
}
break
}
if != ' ' && != '\t' {
.R.UnreadByte()
break
}
++
}
return
}
func ( *Reader) ( int) ( int, bool, string, error) {
, := .ReadLine()
if != nil {
return
}
return parseCodeLine(, )
}
func ( string, int) ( int, bool, string, error) {
if len() < 4 || [3] != ' ' && [3] != '-' {
= ProtocolError("short response: " + )
return
}
= [3] == '-'
, = strconv.Atoi([0:3])
if != nil || < 100 {
= ProtocolError("invalid response code: " + )
return
}
= [4:]
if 1 <= && < 10 && /100 != ||
10 <= && < 100 && /10 != ||
100 <= && < 1000 && != {
= &Error{, }
}
return
}
func ( *Reader) ( int) ( int, string, error) {
, , , := .readCodeLine()
if == nil && {
= ProtocolError("unexpected multi-line response: " + )
}
return
}
= &Error{, }
}
return
}
const (
= iota // beginning of line; initial state; must be zero
// read . at beginning of line
// read .\r at beginning of line
// read \r (possibly at end of line)
// reading data in middle of line
// reached .\r\n end marker line
)
:= .r.R
for < len() && .state != {
var byte
, = .ReadByte()
if != nil {
if == io.EOF {
= io.ErrUnexpectedEOF
}
break
}
switch .state {
case :
if == '.' {
.state =
continue
}
if == '\r' {
.state =
continue
}
.state =
case :
if == '\r' {
.state =
continue
}
if == '\n' {
.state =
continue
}
.state =
case :
if == '\n' {
.state =
continue
.UnreadByte()
= '\r'
.state =
case :
if == '\n' {
.state =
break
var []string
:= .upcomingHeaderNewlines()
if > 0 {
= make([]string, )
}
:= make(MIMEHeader, )
if , := .R.Peek(1); == nil && ([0] == ' ' || [0] == '\t') {
, := .readLineSlice()
if != nil {
return ,
}
return , ProtocolError("malformed MIME header initial line: " + string())
}
for {
, := .readContinuedLineSlice(mustHaveFieldNameColon)
if len() == 0 {
return ,
}
:= bytes.IndexByte(, ':')
if < 0 {
return , ProtocolError("malformed MIME header line: " + string())
}
:= canonicalMIMEHeaderKey([:])
if == "" {
continue
}
return
}
++
= [+1:]
}
return
}
func ( string) string {
commonHeaderOnce.Do(initCommonHeader)
:= true
for := 0; < len(); ++ {
:= []
if !validHeaderFieldByte() {
return
}
if && 'a' <= && <= 'z' {
return canonicalMIMEHeaderKey([]byte())
}
if ! && 'A' <= && <= 'Z' {
return canonicalMIMEHeaderKey([]byte())
}
= == '-'
}
return
}
const toLower = 'a' - 'A'
func ( byte) bool {
return int() < len(isTokenTable) && isTokenTable[]
}
for , := range {
if validHeaderFieldByte() {
continue
if := commonHeader[string()]; != "" {
return
}
return string()
}
var commonHeader map[string]string
var commonHeaderOnce sync.Once
func () {
commonHeader = make(map[string]string)
for , := range []string{
"Accept",
"Accept-Charset",
"Accept-Encoding",
"Accept-Language",
"Accept-Ranges",
"Cache-Control",
"Cc",
"Connection",
"Content-Id",
"Content-Language",
"Content-Length",
"Content-Transfer-Encoding",
"Content-Type",
"Cookie",
"Date",
"Dkim-Signature",
"Etag",
"Expires",
"From",
"Host",
"If-Modified-Since",
"If-None-Match",
"In-Reply-To",
"Last-Modified",
"Location",
"Message-Id",
"Mime-Version",
"Pragma",
"Received",
"Return-Path",
"Server",
"Set-Cookie",
"Subject",
"To",
"User-Agent",
"Via",
"X-Forwarded-For",
"X-Imforwards",
"X-Powered-By",
} {
commonHeader[] =
}
}
var isTokenTable = [127]bool{
'!': true,
'#': true,
'$': true,
'%': true,
'&': true,
'\'': true,
'*': true,
'+': true,
'-': true,
'.': true,
'0': true,
'1': true,
'2': true,
'3': true,
'4': true,
'5': true,
'6': true,
'7': true,
'8': true,
'9': true,
'A': true,
'B': true,
'C': true,
'D': true,
'E': true,
'F': true,
'G': true,
'H': true,
'I': true,
'J': true,
'K': true,
'L': true,
'M': true,
'N': true,
'O': true,
'P': true,
'Q': true,
'R': true,
'S': true,
'T': true,
'U': true,
'W': true,
'V': true,
'X': true,
'Y': true,
'Z': true,
'^': true,
'_': true,
'`': true,
'a': true,
'b': true,
'c': true,
'd': true,
'e': true,
'f': true,
'g': true,
'h': true,
'i': true,
'j': true,
'k': true,
'l': true,
'm': true,
'n': true,
'o': true,
'p': true,
'q': true,
'r': true,
's': true,
't': true,
'u': true,
'v': true,
'w': true,
'x': true,
'y': true,
'z': true,
'|': true,
'~': true,
![]() |
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. |