Skip to content
This repository was archived by the owner on Mar 23, 2020. It is now read-only.

Commit 12d0356

Browse files
committed
fix bugs
1 parent 17595fd commit 12d0356

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

main.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
const (
2323
// Version information
24-
Version = "SimpleHttpServer v1.3-beta.4"
24+
Version = "SimpleHttpServer v1.3-beta.5"
2525
// HTTPProxy returns HTTP_PROXY
2626
HTTPProxy = "HTTP_PROXY"
2727
// HTTPSProxy returns HTTPS_PROXY
@@ -50,8 +50,8 @@ var (
5050
enableColor = flag.String("enablecolor", "", "Enable color output by http status code. e.g.: false")
5151
enableUpload = flag.String("enableupload", "", "Enable upload files")
5252
maxRequestBodySize = flag.String("maxrequestbodysize", "", "Max request body size for upload big file")
53-
readTimeout = flag.String("readtimeout", "", "Limit read timeout (unit: ns), 0 for unlimited")
54-
writeTimeout = flag.String("writetimeout", "", "Limit write timeout (unit: ns), 0 for unlimited")
53+
readTimeout = flag.String("readtimeout", "", "Limit read timeout, 0s for unlimited")
54+
writeTimeout = flag.String("writetimeout", "", "Limit write timeout, 0s for unlimited")
5555
makeconfig = flag.String("makeconfig", "", "Make a config file. e.g.: config.yaml")
5656
config = &Config{}
5757
fsMap = make(map[string]fasthttp.RequestHandler)
@@ -202,19 +202,24 @@ func main() {
202202
}
203203
config.MaxRequestBodySize = i
204204
}
205+
if config.MaxRequestBodySize < 0 {
206+
log.Fatalf("error: %v", fmt.Errorf("MaxRequestBodySize must be large or equal 0"))
207+
} else if config.MaxRequestBodySize == 0 {
208+
config.MaxRequestBodySize = fasthttp.DefaultMaxRequestBodySize
209+
}
205210
if len(*readTimeout) > 0 {
206-
i, err := strconv.ParseInt(*readTimeout, 10, 64)
207-
if err != nil || i < 0 {
211+
i, err := time.ParseDuration(*readTimeout)
212+
if err != nil {
208213
log.Fatalf("error: %v", fmt.Errorf("argument readtimeout error"))
209214
}
210-
config.ReadTimeout = time.Duration(i)
215+
config.ReadTimeout = i
211216
}
212217
if len(*writeTimeout) > 0 {
213-
i, err := strconv.ParseInt(*writeTimeout, 10, 64)
214-
if err != nil || i < 0 {
218+
i, err := time.ParseDuration(*writeTimeout)
219+
if err != nil {
215220
log.Fatalf("error: %v", fmt.Errorf("argument writetimeout error"))
216221
}
217-
config.WriteTimeout = time.Duration(i)
222+
config.WriteTimeout = i
218223
}
219224

220225
// safe warning
@@ -734,7 +739,7 @@ enablecolor: true
734739
enableupload: true
735740
## maxrequestbodysize 0 to default size
736741
maxrequestbodysize: %d
737-
## timeout 0s is no limit
742+
## timeout 0s is unlimited
738743
readtimeout: 0s
739744
writetimeout: 0s
740745
logfile: ./simplehttpserver.log

0 commit comments

Comments
 (0)