2018-04-25 07:55:32 +00:00
|
|
|
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
|
|
|
|
|
2018-04-26 21:26:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetURI returns the actual URI
|
|
|
|
func (r T) GetURI() string {
|
|
|
|
return r.uri
|
2018-04-25 07:55:32 +00:00
|
|
|
}
|