limit max http header length

pull/330/head
Darien Raymond 2016-12-16 17:01:47 +01:00
parent b17f06bb4e
commit 68164d46f9
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
1 changed files with 6 additions and 2 deletions

View File

@ -16,6 +16,8 @@ import (
const (
CRLF = "\r\n"
ENDING = CRLF + CRLF
maxHeaderLength = 8192
)
var (
@ -47,7 +49,8 @@ type HeaderReader struct {
func (*HeaderReader) Read(reader io.Reader) (*buf.Buffer, error) {
buffer := buf.NewSmall()
for {
totalBytes := 0
for totalBytes < maxHeaderLength {
err := buffer.AppendSupplier(buf.ReadFrom(reader))
if err != nil {
return nil, err
@ -57,7 +60,8 @@ func (*HeaderReader) Read(reader io.Reader) (*buf.Buffer, error) {
break
}
if buffer.Len() >= len(ENDING) {
leftover := buffer.BytesFrom(buffer.Len() - len(ENDING))
totalBytes += buffer.Len() - len(ENDING)
leftover := buffer.BytesFrom(-len(ENDING))
buffer.Reset(func(b []byte) (int, error) {
return copy(b, leftover), nil
})