๐พ Archived View for source.community โบ ckaznocha โบ gemini โบ blob โบ main โบ request.go captured on 2023-04-26 at 13:22:52. Gemini links have been rewritten to link to archived content
โฌ ๏ธ Previous capture (2023-01-29)
โก๏ธ Next capture (2023-07-10)
-=-=-=-=-=-=-
. ,-. ,-. . . ,-. ,-. ,-. ,-. ,-. ,-,-. ,-,-. . . ,-. . |- . . `-. | | | | | | |-' | | | | | | | | | | | | | | | | | `-' `-' `-^ ' `-' `-' :: `-' `-' ' ' ' ' ' ' `-^ ' ' ' `' `-| /| `-'
git clone https://source.community/ckaznocha/gemini.git
View raw contents of /request.go (main)
โโโโโฎ 1โ package gemini 2โ 3โ import ( 4โ "bufio" 5โ "crypto/x509/pkix" 6โ "fmt" 7โ "net/textproto" 8โ ) 9โ 10โ const maxRequestLength = 1024 11โ 12โ // Request is a Gemini request. 13โ type Request struct { 14โ Subject *pkix.Name 15โ URI *URI 16โ RemoteAddr string 17โ } 18โ 19โ // ReadRequest reads and parses a Gemini request from buffer. It returns an 20โ // error if the request could not be read or was malformed. 21โ func ReadRequest(b *bufio.Reader) (*Request, error) { 22โ u := []byte{} 23โ cr := false 24โ 25โ for { 26โ b, err := b.ReadByte() 27โ if err != nil { 28โ return nil, fmt.Errorf("%w: %s", ErrRequestRead, err) 29โ } 30โ 31โ if b == '\r' { 32โ cr = true 33โ 34โ continue 35โ } 36โ 37โ if cr && b == '\n' { 38โ break 39โ } 40โ 41โ cr = false 42โ 43โ u = append(u, b) 44โ if len(u) > maxRequestLength { 45โ return nil, ErrMaxRequestLengthExceeded 46โ } 47โ } 48โ 49โ uri, err := ParseRequestURI(string(textproto.TrimBytes(u))) 50โ if err != nil { 51โ return nil, err 52โ } 53โ 54โ return &Request{URI: uri}, nil 55โ } โโโโโฏ
ยท ยท ยท
ยฉ 2023 source.community