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