go-gemini/gemini.go

35 lines
730 B
Go
Raw Permalink Normal View History

2020-10-24 15:15:32 -04:00
package gemini
2020-09-25 19:09:49 -04:00
2020-09-26 16:52:14 -04:00
import (
2020-10-13 20:10:04 -04:00
"errors"
2021-02-24 14:28:47 -05:00
"mime"
2020-09-26 16:52:14 -04:00
)
func init() {
// Add Gemini mime types
mime.AddExtensionType(".gmi", "text/gemini")
mime.AddExtensionType(".gemini", "text/gemini")
}
2020-10-13 20:10:04 -04:00
// Errors.
var (
ErrInvalidRequest = errors.New("gemini: invalid request")
2020-11-05 15:27:12 -05:00
ErrInvalidResponse = errors.New("gemini: invalid response")
// ErrBodyNotAllowed is returned by ResponseWriter.Write calls
// when the response status code does not permit a body.
ErrBodyNotAllowed = errors.New("gemini: response status code does not allow body")
2020-10-13 20:10:04 -04:00
)
2021-03-20 12:27:20 -04:00
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
}