summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.go22
1 files changed, 14 insertions, 8 deletions
diff --git a/main.go b/main.go
index f270f13..24ce456 100644
--- a/main.go
+++ b/main.go
@@ -23,11 +23,13 @@ import (
const (
MetadataExt = ".metadata"
DefaultMimeType = "application/octet-stream"
+ DefaultMaxSize = (10 << 23) // 83MB
)
type Server struct {
- data string
- host string
+ data string
+ host string
+ maxSize int64
}
type Metadata struct {
@@ -185,9 +187,10 @@ func (s *Server) post(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
return
}
+ r.Body = http.MaxBytesReader(w, r.Body, s.maxSize) // impose maximum request size
mimeType := r.Header.Get("content-type")
if strings.HasPrefix(mimeType, "multipart/form-data;") {
- r.ParseMultipartForm(10 << 23) // 83MB
+ r.ParseMultipartForm(1 << 23) // max 8MB in RAM
textName, err := s.postText(r)
if err != nil {
log.Print("Error text upload: ", err)
@@ -259,13 +262,15 @@ func (s *Server) Index(w http.ResponseWriter, r *http.Request) {
func main() {
var (
- addr string
- data string
- host string
+ addr string
+ data string
+ host string
+ maxSize uint32
)
flag.StringVarP(&addr, "addr", "a", "0.0.0.0:9000", "The address to bind to")
flag.StringVarP(&data, "data-path", "d", "./data", "The path to the data")
flag.StringVarP(&host, "host", "h", "", "The host url, e.g. http://127.0.0.1")
+ flag.Uint32VarP(&maxSize, "max-size", "", DefaultMaxSize, "The maximum file upload size")
flag.Parse()
datadir, err := filepath.Abs(data)
@@ -273,8 +278,9 @@ func main() {
log.Fatal(err)
}
s := &Server{
- data: datadir,
- host: host,
+ data: datadir,
+ host: host,
+ maxSize: int64(maxSize),
}
mux := http.NewServeMux()
mux.HandleFunc("/", s.Index)