1
0
Fork 0
mirror of https://git.sr.ht/~adnano/go-gemini synced 2024-05-06 00:26:19 +02:00

response: Limit response header size

This commit is contained in:
Adnan Maolood 2021-03-20 14:01:45 -04:00
parent 3dca29eb41
commit 72d437c82e

View File

@ -44,7 +44,12 @@ type Response struct {
// ReadResponse reads a Gemini response from the provided io.ReadCloser.
func ReadResponse(r io.ReadCloser) (*Response, error) {
resp := &Response{}
br := bufio.NewReader(r)
// Limit response header size
lr := io.LimitReader(r, 1029)
// Wrap the reader to remove the limit later on
wr := &struct{ io.Reader }{lr}
br := bufio.NewReader(wr)
// Read response header
b, err := br.ReadBytes('\n')
@ -81,6 +86,9 @@ func ReadResponse(r io.ReadCloser) (*Response, error) {
resp.Meta = string(meta)
if resp.Status.Class() == StatusSuccess {
// Use unlimited reader
wr.Reader = r
type readCloser struct {
io.Reader
io.Closer