From 0d4b0ecd43872d782929ddabf496a4bb2d03912c Mon Sep 17 00:00:00 2001 From: Makis Maropoulos Date: Sun, 3 Jul 2016 16:21:57 +0200 Subject: [PATCH] Rocket chat is on, Add Port() to the HTTPServer, disable subdomain persistence on subdomains when 127.0.0.1/0.0.0.0 I already made a test framework integration but I will commit this when I finish with the basic tests, we are going to final v3 --- CONTRIBUTING.md | 2 +- README.md | 2 +- http.go | 16 ++++++++++++++++ initiatory.go | 21 +++++++++++++++++---- sessions/manager.go | 3 ++- 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5ce2e94c..a52e7647 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,6 +34,6 @@ The more information you can provide, the more likely someone will be successful ## Contributing Fixes If you are interested in fixing issues and contributing directly to the Iris base, please see the document [How to Contribute](https://github.com/iris-contrib/wiki/blob/master/How-to-Contribute.md). -[Chat]: https://gitter.im/kataras/iris +[Chat]: https://kataras.rocket.chat/channel/iris [ChatMain]: https://kataras.rocket.chat/channel/iris [ChatAlternative]: https://gitter.im/kataras/iris diff --git a/README.md b/README.md index 19a43cdb..cff7b320 100644 --- a/README.md +++ b/README.md @@ -188,7 +188,7 @@ License can be found [here](LICENSE). [Release Widget]: https://img.shields.io/badge/release-v3.0.0--rc.4-blue.svg?style=flat-square [Release]: https://github.com/kataras/iris/releases [Chat Widget]: https://img.shields.io/badge/community-chat-00BCD4.svg?style=flat-square -[Chat]: https://gitter.im/kataras/iris +[Chat]: https://kataras.rocket.chat/channel/iris [ChatMain]: https://kataras.rocket.chat/channel/iris [ChatAlternative]: https://gitter.im/kataras/iris [Report Widget]: https://img.shields.io/badge/report%20card-A%2B-F44336.svg?style=flat-square diff --git a/http.go b/http.go index dc5003dc..6d72aaa5 100644 --- a/http.go +++ b/http.go @@ -7,6 +7,7 @@ import ( "net/http/pprof" "os" "sort" + "strconv" "strings" "sync" @@ -283,6 +284,21 @@ func (s *Server) Host() (host string) { } +// Port returns the port which server listening for +// if no port given with the ListeningAddr, it returns 80 +func (s *Server) Port() (port int) { + a := s.Config.ListeningAddr + if portIdx := strings.IndexByte(a, ':'); portIdx == 0 { + p, err := strconv.Atoi(a[portIdx+1:]) + if err != nil { + port = 80 + } else { + port = p + } + } + return +} + // VirtualHost returns the s.Config.ListeningAddr // func (s *Server) VirtualHost() (host string) { diff --git a/initiatory.go b/initiatory.go index 91541762..6d238e18 100644 --- a/initiatory.go +++ b/initiatory.go @@ -4,8 +4,10 @@ import ( "fmt" "os" "sync" + "testing" "time" + "github.com/gavv/httpexpect" "github.com/kataras/iris/config" "github.com/kataras/iris/logger" "github.com/kataras/iris/render/rest" @@ -33,7 +35,7 @@ var ( // Where to use that? // this is used on extreme cases when you don't know which .Listen/.NoListen will be called // and you want to run/declare something external-not-Iris (all Iris functionality declared before .Listen/.NoListen) AFTER the server is started and plugins finished. - // see the ./test/iris_test.go + // see the server_test.go for an example Available chan bool ) @@ -87,6 +89,8 @@ type Framework struct { Plugins PluginContainer Websocket websocket.Server Available chan bool + // this is setted once when .Tester(t) is called + testFramework *httpexpect.Expect } // New creates and returns a new Iris station aka Framework. @@ -195,11 +199,12 @@ func (s *Framework) closeServer() error { // justServe initializes the whole framework but server doesn't listens to a specific net.Listener func (s *Framework) justServe(optionalAddr ...string) *Server { - addr := config.DefaultServerAddr + s.HTTPServer.Config = &s.Config.Server + if len(optionalAddr) > 0 { - addr = optionalAddr[0] + s.HTTPServer.Config.ListeningAddr = optionalAddr[0] } - s.HTTPServer.Config.ListeningAddr = addr + s.initialize() s.Plugins.DoPreListen(s) s.HTTPServer.SetHandler(s.mux) @@ -210,3 +215,11 @@ func (s *Framework) justServe(optionalAddr ...string) *Server { return s.HTTPServer } + +// tester returns the test framework +func (s *Framework) tester(t *testing.T) *httpexpect.Expect { + if s.testFramework == nil { + s.testFramework = NewTester(s, t) + } + return s.testFramework +} diff --git a/sessions/manager.go b/sessions/manager.go index 64585359..6eb0efa0 100644 --- a/sessions/manager.go +++ b/sessions/manager.go @@ -101,10 +101,11 @@ func (m *Manager) Start(ctx context.IContext) store.IStore { if portIdx := strings.IndexByte(requestDomain, ':'); portIdx > 0 { requestDomain = requestDomain[0:portIdx] } + if requestDomain == "0.0.0.0" || requestDomain == "127.0.0.1" { // for these type of hosts, we can't allow subdomains persistance, // the web browser doesn't understand the mysubdomain.0.0.0.0 and mysubdomain.127.0.0.1 as scorrectly ubdomains because of the many dots - cookie.SetDomain(requestDomain) + // so don't set a domain here } else if strings.Count(requestDomain, ".") > 0 { // there is a problem with .localhost setted as the domain, so we check that first