From c273e80fcbc89e4bd1d7889d3b95d1da40ed487e Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Fri, 8 Dec 2023 13:44:36 -0800 Subject: [PATCH] initial commits --- requesturi/bytes_tolerant.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 requesturi/bytes_tolerant.go 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 + } +}