File tree Expand file tree Collapse file tree 3 files changed +32
-6
lines changed
Expand file tree Collapse file tree 3 files changed +32
-6
lines changed Original file line number Diff line number Diff line change @@ -3,13 +3,13 @@ package app
33import (
44 "../param"
55 "../serverErrHandler"
6+ "../util"
67 "../vhost"
78 "crypto/tls"
89 "errors"
910 "net"
1011 "net/http"
1112 "os"
12- "strings"
1313 "sync"
1414)
1515
@@ -211,11 +211,7 @@ func NewApp(params []*param.Param) *App {
211211 l .handler = http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
212212 var serveVHost * vhost.VHost
213213
214- hostname := r .Host
215- colonIndex := strings .LastIndexByte (hostname , ':' )
216- if colonIndex >= 0 {
217- hostname = hostname [:colonIndex ]
218- }
214+ hostname := util .ExtractHostname (r .Host )
219215
220216 for _ , vh := range l .vhosts {
221217 if vh .MatchHostname (hostname ) {
Original file line number Diff line number Diff line change 1+ package util
2+
3+ import "strings"
4+
5+ func ExtractHostname (host string ) string {
6+ colonIndex := strings .LastIndexByte (host , ':' )
7+ if colonIndex >= 0 {
8+ return host [:colonIndex ]
9+ }
10+ return host
11+ }
Original file line number Diff line number Diff line change 1+ package util
2+
3+ import "testing"
4+
5+ func TestExtractHostname (t * testing.T ) {
6+ var host , hostname string
7+
8+ host = "example.com"
9+ hostname = ExtractHostname (host )
10+ if hostname != "example.com" {
11+ t .Error (hostname )
12+ }
13+
14+ host = "example.com:8080"
15+ hostname = ExtractHostname (host )
16+ if hostname != "example.com" {
17+ t .Error (hostname )
18+ }
19+ }
You can’t perform that action at this time.
0 commit comments