aboutsummaryrefslogtreecommitdiff
path: root/gemini.go
diff options
context:
space:
mode:
authorAdnan Maolood <[email protected]>2021-03-20 12:27:20 -0400
committerAdnan Maolood <[email protected]>2021-03-20 12:27:20 -0400
commit5141eaafaa991a5ab4221fa466e86a167d8910c7 (patch)
tree4b8939eed193b54d3c53369616385b77274621a9 /gemini.go
parentresponse: Treat empty meta as invalid (diff)
downloadgo-gemini-5141eaafaa991a5ab4221fa466e86a167d8910c7.tar.xz
go-gemini-5141eaafaa991a5ab4221fa466e86a167d8910c7.zip
Tweak request and response parsing
Diffstat (limited to 'gemini.go')
-rw-r--r--gemini.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/gemini.go b/gemini.go
index 25160f9..f4b211e 100644
--- a/gemini.go
+++ b/gemini.go
@@ -11,8 +11,6 @@ func init() {
mime.AddExtensionType(".gemini", "text/gemini")
}
-var crlf = []byte("\r\n")
-
// Errors.
var (
ErrInvalidRequest = errors.New("gemini: invalid request")
@@ -22,3 +20,15 @@ var (
// when the response status code does not permit a body.
ErrBodyNotAllowed = errors.New("gemini: response status code does not allow body")
)
+
+var crlf = []byte("\r\n")
+
+func trimCRLF(b []byte) ([]byte, bool) {
+ // Check for CR
+ if len(b) < 2 || b[len(b)-2] != '\r' {
+ return nil, false
+ }
+ // Trim CRLF
+ b = b[:len(b)-2]
+ return b, true
+}