diff options
| author | Adnan Maolood <[email protected]> | 2021-03-20 12:27:20 -0400 |
|---|---|---|
| committer | Adnan Maolood <[email protected]> | 2021-03-20 12:27:20 -0400 |
| commit | 5141eaafaa991a5ab4221fa466e86a167d8910c7 (patch) | |
| tree | 4b8939eed193b54d3c53369616385b77274621a9 /gemini.go | |
| parent | response: Treat empty meta as invalid (diff) | |
| download | go-gemini-5141eaafaa991a5ab4221fa466e86a167d8910c7.tar.xz go-gemini-5141eaafaa991a5ab4221fa466e86a167d8910c7.zip | |
Tweak request and response parsing
Diffstat (limited to 'gemini.go')
| -rw-r--r-- | gemini.go | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -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 +} |