2018-04-24 21:10:01 +00:00
|
|
|
package request
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.xdrm.io/gws/internal/http/reader"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Parse parses a byte array build a request object
|
|
|
|
func Parse(r io.Reader) (request *T, err error) {
|
|
|
|
|
|
|
|
/* (1) Get chunk reader */
|
|
|
|
cr, err := reader.NewReader(r)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Error while creating chunk reader: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (2) Init request */
|
|
|
|
req := new(T)
|
|
|
|
|
|
|
|
/* (3) Parse header line by line */
|
|
|
|
for {
|
|
|
|
|
|
|
|
line, err := cr.Read()
|
|
|
|
if err == io.EOF {
|
|
|
|
fmt.Printf("END OF READING\n");
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Cannot read from reader: %s", err)
|
|
|
|
}
|
|
|
|
|
2018-04-25 13:41:39 +00:00
|
|
|
err = req.parseHeader(line)
|
2018-04-24 21:10:01 +00:00
|
|
|
|
2018-04-25 13:41:39 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Parsing error: %s\n", err);
|
2018-04-24 21:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) GET {uri} HTTP/{version}
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Break apart */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (1) Check method */
|
|
|
|
return nil, nil
|
|
|
|
|
|
|
|
}
|