go-gemini/gemini.go

35 lines
730 B
Go
Raw Permalink Normal View History

2020-10-24 19:15:32 +00:00
package gemini
2020-09-25 23:09:49 +00:00
2020-09-26 20:52:14 +00:00
import (
2020-10-14 00:10:04 +00:00
"errors"
2021-02-24 19:28:47 +00:00
"mime"
2020-09-26 20:52:14 +00:00
)
func init() {
// Add Gemini mime types
mime.AddExtensionType(".gmi", "text/gemini")
mime.AddExtensionType(".gemini", "text/gemini")
}
2020-10-14 00:10:04 +00:00
// Errors.
var (
ErrInvalidRequest = errors.New("gemini: invalid request")
2020-11-05 20:27:12 +00: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-14 00:10:04 +00:00
)
2021-03-20 16:27:20 +00: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
}