~adnano/go-gemini

ref: v0.2.2 go-gemini/gemini.go -rw-r--r-- 730 bytes
3d2110d9Adnan Maolood mux: Tweak documentation 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package gemini

import (
	"errors"
	"mime"
)

func init() {
	// Add Gemini mime types
	mime.AddExtensionType(".gmi", "text/gemini")
	mime.AddExtensionType(".gemini", "text/gemini")
}

// Errors.
var (
	ErrInvalidRequest  = errors.New("gemini: invalid request")
	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")
)

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
}