summaryrefslogtreecommitdiff
path: root/service/http/service.go
diff options
context:
space:
mode:
authorDmitry Patsura <[email protected]>2019-06-13 17:46:22 +0300
committerDmitry Patsura <[email protected]>2019-06-13 20:01:23 +0300
commitf427a13ac091ce5ef814c58870782105adf48c12 (patch)
tree21de0a765af298b3f5c03fab7a5c8256e7649650 /service/http/service.go
parent82cfc4f8f89252083aa09e8370b9605d38808b70 (diff)
Feature: FastCGI - initial #115
Diffstat (limited to 'service/http/service.go')
-rw-r--r--service/http/service.go43
1 files changed, 40 insertions, 3 deletions
diff --git a/service/http/service.go b/service/http/service.go
index 8105d218..8db13c15 100644
--- a/service/http/service.go
+++ b/service/http/service.go
@@ -7,8 +7,10 @@ import (
"github.com/spiral/roadrunner/service/env"
"github.com/spiral/roadrunner/service/http/attributes"
"github.com/spiral/roadrunner/service/rpc"
+ "github.com/spiral/roadrunner/util"
"golang.org/x/net/http2"
"net/http"
+ "net/http/fcgi"
"net/url"
"strings"
"sync"
@@ -37,6 +39,7 @@ type Service struct {
handler *Handler
http *http.Server
https *http.Server
+ fcgi *http.Server
}
// Attach attaches controller. Currently only one controller is supported.
@@ -97,6 +100,10 @@ func (s *Service) Serve() error {
s.https = s.initSSL()
}
+ if s.cfg.EnableFCGI() {
+ s.fcgi = &http.Server{Addr: s.cfg.Address, Handler: s}
+ }
+
s.mu.Unlock()
if err := s.rr.Start(); err != nil {
@@ -104,10 +111,22 @@ func (s *Service) Serve() error {
}
defer s.rr.Stop()
- err := make(chan error, 2)
- go func() { err <- s.http.ListenAndServe() }()
+ err := make(chan error, 3)
+
+ go func() {
+ err <- s.http.ListenAndServe()
+ }()
+
if s.https != nil {
- go func() { err <- s.https.ListenAndServeTLS(s.cfg.SSL.Cert, s.cfg.SSL.Key) }()
+ go func() {
+ err <- s.https.ListenAndServeTLS(s.cfg.SSL.Cert, s.cfg.SSL.Key)
+ }()
+ }
+
+ if s.fcgi != nil {
+ go func() {
+ err <- s.ListenAndServeFCGI()
+ }()
}
return <-err
@@ -121,6 +140,10 @@ func (s *Service) Stop() {
return
}
+ if s.fcgi != nil {
+ go s.fcgi.Shutdown(context.Background())
+ }
+
if s.https != nil {
go s.https.Shutdown(context.Background())
}
@@ -136,6 +159,20 @@ func (s *Service) Server() *roadrunner.Server {
return s.rr
}
+func (s *Service) ListenAndServeFCGI() error {
+ l, err := util.CreateListener(s.cfg.FCGI.Address);
+ if err != nil {
+ return err
+ }
+
+ err = fcgi.Serve(l, s.http.Handler)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
// ServeHTTP handles connection using set of middleware and rr PSR-7 server.
func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if s.https != nil && r.TLS == nil && s.cfg.SSL.Redirect {