๐Ÿ’พ Archived View for source.community โ€บ ckaznocha โ€บ gemini โ€บ blob โ€บ main โ€บ request.go captured on 2023-01-29 at 03:22:40. Gemini links have been rewritten to link to archived content

View Raw

More Information

โฌ…๏ธ Previous capture (2022-01-08)

โžก๏ธ Next capture (2023-07-10)

๐Ÿšง View Differences

-=-=-=-=-=-=-

                                                         .
,-. ,-. . . ,-. ,-. ,-.    ,-. ,-. ,-,-. ,-,-. . . ,-. . |- . .
`-. | | | | |   |   |-'    |   | | | | | | | | | | | | | |  | |
`-' `-' `-^ '   `-' `-' :: `-' `-' ' ' ' ' ' ' `-^ ' ' ' `' `-|
                                                             /|
                                                            `-'

Profile for ckaznocha

ckaznocha / gemini

git clone https://source.community/ckaznocha/gemini.git

Branches

Log

Tree

/request.go (main)

โ†‘ /

blob

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โ”‚ }
โ”€โ”€โ”€โ”€โ•ฏ

ยท ยท ยท

๐Ÿก Home

FAQs

Privacy Policy

Terms & Conditions

Official Gemlog

info@source.community

ยฉ 2023 source.community