summaryrefslogtreecommitdiff
path: root/http
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-06-10 17:18:23 +0300
committerWolfy-J <[email protected]>2018-06-10 17:18:23 +0300
commit094a4c211022b9446ef988c74c546ad6efb09722 (patch)
tree603ade627491960108154d6301868c9b881cd101 /http
parent232aa8f3c20a060e556ab431467f4f7b3f83bfbf (diff)
http service
Diffstat (limited to 'http')
-rw-r--r--http/config.go10
-rw-r--r--http/service.go2
-rw-r--r--http/uploads.go2
-rw-r--r--http/uploads_config.go12
4 files changed, 15 insertions, 11 deletions
diff --git a/http/config.go b/http/config.go
index efcaae30..abb14d9a 100644
--- a/http/config.go
+++ b/http/config.go
@@ -2,7 +2,6 @@ package http
import (
"github.com/spiral/roadrunner"
- "fmt"
)
// Configures RoadRunner HTTP server.
@@ -10,8 +9,8 @@ type Config struct {
// Enable enables http service.
Enable bool
- // Host and port to handle as http server.
- Host, Port string
+ // Address and port to handle as http server.
+ Address string
// MaxRequest specified max size for payload body in bytes, set 0 to unlimited.
MaxRequest int64
@@ -27,8 +26,3 @@ type Config struct {
func (cfg *Config) Valid() error {
return nil
}
-
-// httpAddr returns prepared http listen address.
-func (cfg *Config) httpAddr() string {
- return fmt.Sprintf("%s:%v", cfg.Host, cfg.Port)
-}
diff --git a/http/service.go b/http/service.go
index c31c4a47..bf25667d 100644
--- a/http/service.go
+++ b/http/service.go
@@ -64,7 +64,7 @@ func (s *Service) Serve() error {
s.rr = rr
s.srv = &Server{cfg: s.cfg, rr: s.rr}
- s.http = &http.Server{Addr: s.cfg.httpAddr()}
+ s.http = &http.Server{Addr: s.cfg.Address}
s.rr.Listen(s.listener)
s.srv.Listen(s.listener)
diff --git a/http/uploads.go b/http/uploads.go
index 62167a6c..1f3060c0 100644
--- a/http/uploads.go
+++ b/http/uploads.go
@@ -112,7 +112,7 @@ func (f *FileUpload) Open(cfg *UploadsConfig) error {
}
defer file.Close()
- tmp, err := ioutil.TempFile(cfg.Dir, "upload")
+ tmp, err := ioutil.TempFile(cfg.TmpDir(), "upload")
if err != nil {
// most likely cause of this issue is missing tmp dir
f.Error = UploadErrorNoTmpDir
diff --git a/http/uploads_config.go b/http/uploads_config.go
index ac80723f..715de69a 100644
--- a/http/uploads_config.go
+++ b/http/uploads_config.go
@@ -3,6 +3,7 @@ package http
import (
"strings"
"path"
+ "os"
)
// UploadsConfig describes file location and controls access to them.
@@ -15,8 +16,17 @@ type UploadsConfig struct {
Forbid []string
}
+// TmpDir returns temporary directory.
+func (cfg *UploadsConfig) TmpDir() string {
+ if cfg.Dir != "" {
+ return cfg.Dir
+ }
+
+ return os.TempDir()
+}
+
// Forbid must return true if file extension is not allowed for the upload.
-func (cfg UploadsConfig) Forbids(filename string) bool {
+func (cfg *UploadsConfig) Forbids(filename string) bool {
ext := strings.ToLower(path.Ext(filename))
for _, v := range cfg.Forbid {