MCPcopy Create free account
hub / github.com/gobwas/httphead / ParseRequestLine

Function ParseRequestLine

head.go:35–63  ·  view source on GitHub ↗

ParseRequestLine parses http request line like "GET / HTTP/1.0".

(line []byte)

Source from the content-addressed store, hash-verified

33
34// ParseRequestLine parses http request line like "GET / HTTP/1.0".
35func ParseRequestLine(line []byte) (r RequestLine, ok bool) {
36 var i int
37 for i = 0; i < len(line); i++ {
38 c := line[i]
39 if !OctetTypes[c].IsToken() {
40 if i > 0 && c == ' ' {
41 break
42 }
43 return
44 }
45 }
46 if i == len(line) {
47 return
48 }
49
50 var proto []byte
51 r.Method = line[:i]
52 r.URI, proto = split2(line[i+1:], ' ')
53 if len(r.URI) == 0 {
54 return
55 }
56 if major, minor, ok := ParseVersion(proto); ok {
57 r.Version.Major = major
58 r.Version.Minor = minor
59 return r, true
60 }
61
62 return r, false
63}
64
65// SplitResponseLine splits given slice of bytes into three chunks without
66// parsing.

Callers 1

TestParseRequestLineFunction · 0.85

Calls 3

split2Function · 0.85
ParseVersionFunction · 0.85
IsTokenMethod · 0.80

Tested by 1

TestParseRequestLineFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…