I want to return "too large body" response whenever a request's body is 
larger than setting.
However, when the request has "Expect" header, the connection may be reset 
if the requestbody is not read to end.

Then, I added check function. The function check 'Content-Length' and 
return error response if the length is larger than setting.

if !checkExpect(request.Header) { // check if "Expect" header exists
    // do nothing...( this block is to take C1 coverage )
} else {
    return NewError("body is too large")
}
buf := bytes.NewBuffer([]byte{})
_, err := io.CopyN(buf, request.Body, setting + 1)
if err == nil {
    return NewError("body is too large")
} else if err == io.EOF {
    // do nothing...( this block is to take C1 coverage )
} else {
    return NewError("failed to read")
}

But, if 'Content-Length' is camouflaged and smaller than real bodysize, 
this code read body and connection may be reset.
In addition, if the request has "Transfer-Encoding" header, 
request.ContentLength is -1.

Why the connection is reset when the requestbody is not read to end?
When "Content-Length" header is camoflauged or negative value, How should I 
keep the connection?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/5982d5ed-3ce4-4a26-b84a-6a5d2094c45d%40googlegroups.com.

Reply via email to