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
This commit is contained in:
Makis Maropoulos 2016-07-03 16:21:57 +02:00
parent c443dc9808
commit 0d4b0ecd43
5 changed files with 37 additions and 7 deletions

View File

@ -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

View File

@ -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

16
http.go
View File

@ -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) {

View File

@ -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
}

View File

@ -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