func ParseReq(data []byte, req *Request) (leftover []byte, err error) {
	sdata := string(data)
	var i, s int
	var top string
	var clen int
	var q = -1
	// method, path, proto line
	for ; i < len(sdata); i++ {
		if sdata[i] == ' ' {
			req.Method = sdata[s:i]
			for i, s = i+1, i+1; i < len(sdata); i++ {
				if sdata[i] == '?' && q == -1 {
					q = i - s
				} else if sdata[i] == ' ' {
					if q != -1 {
						req.Path = sdata[s:q]
						req.Query = req.Path[q+1 : i]
					} else {
						req.Path = sdata[s:i]
					}
					for i, s = i+1, i+1; i < len(sdata); i++ {
						if sdata[i] == '\n' && sdata[i-1] == '\r' {
							req.Proto = sdata[s:i]
							i, s = i+1, i+1
							break
						}
					}
					break
				}
			}
			break
		}
	}
	if req.Proto == "" {
		return data, errors.New("malformed request")
	}
	top = sdata[:s]
	for ; i < len(sdata); i++ {
		if i > 1 && sdata[i] == '\n' && sdata[i-1] == '\r' {
			line := sdata[s : i-1]
			s = i + 1
			if line == "" {
				req.Head = sdata[len(top)+2 : i+1]
				i++
				if clen > 0 {
					if len(sdata[i:]) < clen {
						break
					}
					req.Body = sdata[i : i+clen]
					i += clen
				}
				return data[i:], nil
			}
			if strings.HasPrefix(line, "Content-Length:") {
				n, err := strconv.ParseInt(strings.TrimSpace(line[len("Content-Length:"):]), 10, 64)
				if err == nil {
					clen = int(n)
				}
			}
		}
	}
	// not enough data
	return data, nil
}
// ParseReq is a very simple http request parser. This operation
// waits for the entire payload to be buffered before returning a
// valid request.
ParseReq is a very simple http request parser. This operation
waits for the entire payload to be buffered before returning a
valid request.
// ParseReq is a very simple http request parser . This operation // waits for the entire payload to be buffered before returning a // valid request .
func ParseReq(data []byte, req *Request) (leftover []byte, err error) {
	sdata := string(data)
	var i, s int
	var top string
	var clen int
	var q = -1
	for ; i < len(sdata); i++ {
		if sdata[i] == ' ' {
			req.Method = sdata[s:i]
			for i, s = i+1, i+1; i < len(sdata); i++ {
				if sdata[i] == '?' && q == -1 {
					q = i - s
				} else if sdata[i] == ' ' {
					if q != -1 {
						req.Path = sdata[s:q]
						req.Query = req.Path[q+1 : i]
					} else {
						req.Path = sdata[s:i]
					}
					for i, s = i+1, i+1; i < len(sdata); i++ {
						if sdata[i] == '\n' && sdata[i-1] == '\r' {
							req.Proto = sdata[s:i]
							i, s = i+1, i+1
							break
						}
					}
					break
				}
			}
			break
		}
	}
	if req.Proto == "" {
		return data, errors.New("malformed request")
	}
	top = sdata[:s]
	for ; i < len(sdata); i++ {
		if i > 1 && sdata[i] == '\n' && sdata[i-1] == '\r' {
			line := sdata[s : i-1]
			s = i + 1
			if line == "" {
				req.Head = sdata[len(top)+2 : i+1]
				i++
				if clen > 0 {
					if len(sdata[i:]) < clen {
						break
					}
					req.Body = sdata[i : i+clen]
					i += clen
				}
				return data[i:], nil
			}
			if strings.HasPrefix(line, "Content-Length:") {
				n, err := strconv.ParseInt(strings.TrimSpace(line[len("Content-Length:"):]), 10, 64)
				if err == nil {
					clen = int(n)
				}
			}
		}
	}
	return data, nil
}
func ParseReq ( data [ ] byte , req * Request ) ( leftover [ ] byte , err error ) { sdata := string ( data ) var i , s int var top string var clen int var q = - 1 for ; i < len ( sdata ) ; i ++ { if sdata [ i ] == ' ' { req . Method = sdata [ s : i ] for i , s = i + 1 , i + 1 ; i < len ( sdata ) ; i ++ { if sdata [ i ] == '?' && q == - 1 { q = i - s } else if sdata [ i ] == ' ' { if q != - 1 { req . Path = sdata [ s : q ] req . Query = req . Path [ q + 1 : i ] } else { req . Path = sdata [ s : i ] } for i , s = i + 1 , i + 1 ; i < len ( sdata ) ; i ++ { if sdata [ i ] == '\n' && sdata [ i - 1 ] == '\r' { req . Proto = sdata [ s : i ] i , s = i + 1 , i + 1 break } } break } } break } } if req . Proto == " " { return data , errors . New ( " " ) } top = sdata [ : s ] for ; i < len ( sdata ) ; i ++ { if i > 1 && sdata [ i ] == '\n' && sdata [ i - 1 ] == '\r' { line := sdata [ s : i - 1 ] s = i + 1 if line == " " { req . Head = sdata [ len ( top ) + 2 : i + 1 ] i ++ if clen > 0 { if len ( sdata [ i : ] ) < clen { break } req . Body = sdata [ i : i + clen ] i += clen } return data [ i : ] , nil } if strings . HasPrefix ( line , " " ) { n , err := strconv . ParseInt ( strings . TrimSpace ( line [ len ( " " ) : ] ) , 10 , 64 ) if err == nil { clen = int ( n ) } } } } return data , nil }
ParseReq is a very simple http request parser.
ParseReq is a very simple http request parser .
// method, path, proto line // not enough data