package reqline import ( "fmt" "bytes" ) // parseRequestLine parses the first HTTP request line func (r *T) Parse(b []byte) error { /* (1) Split by ' ' */ parts := bytes.Split(b, []byte(" ")) /* (2) Fail when missing parts */ if len(parts) != 3 { return fmt.Errorf("Malformed Request-Line must have 3 space-separated elements, got %d", len(parts)) } /* (3) Extract HTTP method */ err := r.extractHttpMethod(parts[0]) if err != nil { return err } /* (4) Extract URI */ err = r.extractURI(parts[1]) if err != nil { return err } /* (5) Extract version */ err = r.extractHttpVersion(parts[2]) if err != nil { return err } return nil }