summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authormarliotto <[email protected]>2020-01-27 16:04:26 +0300
committermarliotto <[email protected]>2020-01-27 16:04:26 +0300
commite00d36c57c1227e614b0572ab0c0df98032f4298 (patch)
tree46d61d1db03692f3c75f931d290471f333f8fa2c /service
parent648aac1b800fe506fe41f9143c2a4a2d95be408d (diff)
fix REQUEST_URI for requests through FastCGI
Diffstat (limited to 'service')
-rw-r--r--service/http/fcgi_test.go46
-rw-r--r--service/http/request.go3
2 files changed, 49 insertions, 0 deletions
diff --git a/service/http/fcgi_test.go b/service/http/fcgi_test.go
index 58fbe557..5ebd9b4b 100644
--- a/service/http/fcgi_test.go
+++ b/service/http/fcgi_test.go
@@ -57,3 +57,49 @@ func Test_FCGI_Service_Echo(t *testing.T) {
assert.Equal(t, 201, w.Result().StatusCode)
assert.Equal(t, "WORLD", string(body))
}
+
+func Test_FCGI_Service_Request_Uri(t *testing.T) {
+ logger, _ := test.NewNullLogger()
+ logger.SetLevel(logrus.DebugLevel)
+
+ c := service.NewContainer(logger)
+ c.Register(ID, &Service{})
+
+ assert.NoError(t, c.Init(&testCfg{httpCfg: `{
+ "fcgi": {
+ "address": "tcp://0.0.0.0:6082"
+ },
+ "workers":{
+ "command": "php ../../tests/http/client.php request-uri pipes",
+ "pool": {"numWorkers": 1}
+ }
+ }`}))
+
+ s, st := c.Get(ID)
+ assert.NotNil(t, s)
+ assert.Equal(t, service.StatusOK, st)
+
+ // should do nothing
+ s.(*Service).Stop()
+
+ go func() { assert.NoError(t, c.Serve()) }()
+ time.Sleep(time.Millisecond * 100)
+ defer c.Stop()
+
+ fcgiConnFactory := gofast.SimpleConnFactory("tcp", "0.0.0.0:6082")
+
+ fcgiHandler := gofast.NewHandler(
+ gofast.BasicParamsMap(gofast.BasicSession),
+ gofast.SimpleClientFactory(fcgiConnFactory, 0),
+ )
+
+ w := httptest.NewRecorder()
+ req := httptest.NewRequest("GET", "http://site.local/hello-world", nil)
+ fcgiHandler.ServeHTTP(w, req)
+
+ body, err := ioutil.ReadAll(w.Result().Body)
+
+ assert.NoError(t, err)
+ assert.Equal(t, 200, w.Result().StatusCode)
+ assert.Equal(t, "http://site.local/hello-world", string(body))
+}
diff --git a/service/http/request.go b/service/http/request.go
index 5d91bfb6..630e26f6 100644
--- a/service/http/request.go
+++ b/service/http/request.go
@@ -170,6 +170,9 @@ func (r *Request) contentType() int {
// uri fetches full uri from request in a form of string (including https scheme if TLS connection is enabled).
func uri(r *http.Request) string {
+ if r.URL.Host != "" {
+ return r.URL.String()
+ }
if r.TLS != nil {
return fmt.Sprintf("https://%s%s", r.Host, r.URL.String())
}