rpc: enforce the 128KB request limits on websockets too

This commit is contained in:
Péter Szilágyi
2018-03-13 13:23:44 +02:00
parent 6a2d2869f6
commit 555f42cfd8
4 changed files with 66 additions and 22 deletions

View File

@ -27,16 +27,16 @@ import (
"mime"
"net"
"net/http"
"strings"
"sync"
"time"
"github.com/rs/cors"
"strings"
)
const (
contentType = "application/json"
maxHTTPRequestContentLength = 1024 * 128
contentType = "application/json"
maxRequestContentLength = 1024 * 128
)
var nullAddr, _ = net.ResolveTCPAddr("tcp", "127.0.0.1:0")
@ -182,8 +182,8 @@ func validateRequest(r *http.Request) (int, error) {
if r.Method == http.MethodPut || r.Method == http.MethodDelete {
return http.StatusMethodNotAllowed, errors.New("method not allowed")
}
if r.ContentLength > maxHTTPRequestContentLength {
err := fmt.Errorf("content length too large (%d>%d)", r.ContentLength, maxHTTPRequestContentLength)
if r.ContentLength > maxRequestContentLength {
err := fmt.Errorf("content length too large (%d>%d)", r.ContentLength, maxRequestContentLength)
return http.StatusRequestEntityTooLarge, err
}
mt, _, err := mime.ParseMediaType(r.Header.Get("content-type"))