mirror of
https://git.sr.ht/~adnano/go-gemini
synced 2024-09-19 18:53:43 +02:00
response: Limit response header size
This commit is contained in:
parent
4ee8740ee3
commit
0fb35e1337
10
response.go
10
response.go
@ -44,7 +44,12 @@ type Response struct {
|
|||||||
// ReadResponse reads a Gemini response from the provided io.ReadCloser.
|
// ReadResponse reads a Gemini response from the provided io.ReadCloser.
|
||||||
func ReadResponse(r io.ReadCloser) (*Response, error) {
|
func ReadResponse(r io.ReadCloser) (*Response, error) {
|
||||||
resp := &Response{}
|
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
|
// Read response header
|
||||||
b, err := br.ReadBytes('\n')
|
b, err := br.ReadBytes('\n')
|
||||||
@ -81,6 +86,9 @@ func ReadResponse(r io.ReadCloser) (*Response, error) {
|
|||||||
resp.Meta = string(meta)
|
resp.Meta = string(meta)
|
||||||
|
|
||||||
if resp.Status.Class() == StatusSuccess {
|
if resp.Status.Class() == StatusSuccess {
|
||||||
|
// Use unlimited reader
|
||||||
|
wr.Reader = r
|
||||||
|
|
||||||
type readCloser struct {
|
type readCloser struct {
|
||||||
io.Reader
|
io.Reader
|
||||||
io.Closer
|
io.Closer
|
||||||
|
Loading…
Reference in New Issue
Block a user