server: optional speed limit
This commit is contained in:
parent
2345447d59
commit
7f18a3bac0
@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/mxk/go-flowrate/flowrate"
|
||||
)
|
||||
|
||||
var SERVER_HEADER string = `contented/0.1`
|
||||
@ -19,8 +20,9 @@ type ServerPublicProperties struct {
|
||||
}
|
||||
|
||||
type ServerOptions struct {
|
||||
DataDirectory string
|
||||
DBPath string
|
||||
DataDirectory string
|
||||
DBPath string
|
||||
BandwidthLimit int64
|
||||
ServerPublicProperties
|
||||
}
|
||||
|
||||
@ -119,6 +121,9 @@ func (this *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if this.opts.MaxUploadBytes > 0 {
|
||||
r.Body = http.MaxBytesReader(w, r.Body, this.opts.MaxUploadBytes)
|
||||
}
|
||||
if this.opts.BandwidthLimit > 0 {
|
||||
r.Body = flowrate.NewReader(r.Body, this.opts.BandwidthLimit)
|
||||
}
|
||||
|
||||
if r.Method == "GET" && strings.HasPrefix(r.URL.Path, `/view/`) {
|
||||
err := this.handleView(w, r, r.URL.Path[6:])
|
||||
|
@ -17,11 +17,14 @@ func main() {
|
||||
dbPath := flag.String("db", "contented.db", "Path for metadata database")
|
||||
appTitle := flag.String("title", "contented", "Title used in web interface")
|
||||
maxUploadMb := flag.Int("max", 8, "Maximum size of uploaded files in MiB (set zero for unlimited)")
|
||||
maxUploadSpeed := flag.Int("speed", 0, "Maximum upload speed in bytes/sec (set zero for unlimited)")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
svr, err := contented.NewServer(&contented.ServerOptions{
|
||||
DataDirectory: *dataDir,
|
||||
DBPath: *dbPath,
|
||||
DataDirectory: *dataDir,
|
||||
DBPath: *dbPath,
|
||||
BandwidthLimit: int64(*maxUploadSpeed),
|
||||
ServerPublicProperties: contented.ServerPublicProperties{
|
||||
AppTitle: *appTitle,
|
||||
MaxUploadBytes: int64(*maxUploadMb) * 1024 * 1024,
|
||||
|
Loading…
Reference in New Issue
Block a user