ISSUE-332
This commit is contained in:
@ -112,6 +112,7 @@ log | path to log file| | LOG |
|
|||||||
cors-domains | comma separated list of domains for CORS, setting it enable CORS | | CORS_DOMAINS |
|
cors-domains | comma separated list of domains for CORS, setting it enable CORS | | CORS_DOMAINS |
|
||||||
clamav-host | host for clamav feature | | CLAMAV_HOST |
|
clamav-host | host for clamav feature | | CLAMAV_HOST |
|
||||||
rate-limit | request per minute | | RATE_LIMIT |
|
rate-limit | request per minute | | RATE_LIMIT |
|
||||||
|
max-upload-size | max upload size in kilobytes | | MAX_UPLOAD_SIZE |
|
||||||
|
|
||||||
If you want to use TLS using lets encrypt certificates, set lets-encrypt-hosts to your domain, set tls-listener to :443 and enable force-https.
|
If you want to use TLS using lets encrypt certificates, set lets-encrypt-hosts to your domain, set tls-listener to :443 and enable force-https.
|
||||||
|
|
||||||
|
10
cmd/cmd.go
10
cmd/cmd.go
@ -191,6 +191,12 @@ var globalFlags = []cli.Flag{
|
|||||||
Value: 0,
|
Value: 0,
|
||||||
EnvVar: "RATE_LIMIT",
|
EnvVar: "RATE_LIMIT",
|
||||||
},
|
},
|
||||||
|
cli.Int64Flag{
|
||||||
|
Name: "max-upload-size",
|
||||||
|
Usage: "max limit for upload, in kilobytes",
|
||||||
|
Value: 0,
|
||||||
|
EnvVar: "MAX_UPLOAD_SIZE",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "lets-encrypt-hosts",
|
Name: "lets-encrypt-hosts",
|
||||||
Usage: "host1, host2",
|
Usage: "host1, host2",
|
||||||
@ -351,6 +357,10 @@ func New() *Cmd {
|
|||||||
options = append(options, server.ClamavHost(v))
|
options = append(options, server.ClamavHost(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v := c.Int64("max-upload-size"); v > 0 {
|
||||||
|
options = append(options, server.MaxUploadSize(v))
|
||||||
|
}
|
||||||
|
|
||||||
if v := c.Int("rate-limit"); v > 0 {
|
if v := c.Int("rate-limit"); v > 0 {
|
||||||
options = append(options, server.RateLimit(v))
|
options = append(options, server.RateLimit(v))
|
||||||
}
|
}
|
||||||
|
@ -311,6 +311,12 @@ func (s *Server) postHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
contentLength := n
|
contentLength := n
|
||||||
|
|
||||||
|
if s.maxUploadSize > 0 && contentLength > s.maxUploadSize {
|
||||||
|
log.Print("Entity too large")
|
||||||
|
http.Error(w, http.StatusText(http.StatusRequestEntityTooLarge), http.StatusRequestEntityTooLarge)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
metadata := MetadataForRequest(contentType, r)
|
metadata := MetadataForRequest(contentType, r)
|
||||||
|
|
||||||
buffer := &bytes.Buffer{}
|
buffer := &bytes.Buffer{}
|
||||||
@ -455,6 +461,12 @@ func (s *Server) putHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
contentLength = n
|
contentLength = n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.maxUploadSize > 0 && contentLength > s.maxUploadSize {
|
||||||
|
log.Print("Entity too large")
|
||||||
|
http.Error(w, http.StatusText(http.StatusRequestEntityTooLarge), http.StatusRequestEntityTooLarge)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if contentLength == 0 {
|
if contentLength == 0 {
|
||||||
log.Print("Empty content-length")
|
log.Print("Empty content-length")
|
||||||
http.Error(w, errors.New("Could not upload empty file").Error(), 400)
|
http.Error(w, errors.New("Could not upload empty file").Error(), 400)
|
||||||
|
@ -25,11 +25,11 @@ THE SOFTWARE.
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
crypto_rand "crypto/rand"
|
||||||
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
gorillaHandlers "github.com/gorilla/handlers"
|
gorillaHandlers "github.com/gorilla/handlers"
|
||||||
"log"
|
"log"
|
||||||
crypto_rand "crypto/rand"
|
|
||||||
"encoding/binary"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -175,6 +175,12 @@ func Logger(logger *log.Logger) OptionFn {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MaxUploadSize(kbytes int64) OptionFn {
|
||||||
|
return func(srvr *Server) {
|
||||||
|
srvr.maxUploadSize = kbytes * 1024
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
func RateLimit(requests int) OptionFn {
|
func RateLimit(requests int) OptionFn {
|
||||||
return func(srvr *Server) {
|
return func(srvr *Server) {
|
||||||
srvr.rateLimitRequests = requests
|
srvr.rateLimitRequests = requests
|
||||||
@ -271,6 +277,7 @@ type Server struct {
|
|||||||
|
|
||||||
locks map[string]*sync.Mutex
|
locks map[string]*sync.Mutex
|
||||||
|
|
||||||
|
maxUploadSize int64
|
||||||
rateLimitRequests int
|
rateLimitRequests int
|
||||||
|
|
||||||
storage Storage
|
storage Storage
|
||||||
|
Reference in New Issue
Block a user