diff --git a/requesturi/bytes_tolerant.go b/requesturi/bytes_tolerant.go new file mode 100644 index 0000000..c36fa6a --- /dev/null +++ b/requesturi/bytes_tolerant.go @@ -0,0 +1,30 @@ +package requesturi + +import ( + "sourcecode.social/reiver/go-rfc2616/sp" +) + +func BytesTolerant(p []byte) (result []byte, rest []byte, ok bool) { + + if len(p) <= 0 { + return nil, nil, false + } + + { + p0 := p[0] + + if sp.ByteIsTolerant(p0) || '\r' == p0 || '\n' == p0 { + return nil, p, false + } + } + + { + for i,b := range p { + if sp.ByteIsTolerant(p0) || '\r' == p0 || '\n' == p0 { + return p[:i], p[i:], true + } + } + + return p, nil, true + } +}