Skip to content
Permalink
Browse files

use JoinHostPort to support IPv6 addresses

  • Loading branch information...
Brian Cunnie
Brian Cunnie committed Dec 10, 2016
1 parent 287d32b commit 0316b3a5b58241ca78a75057fb64e6dfc6741f7b
Showing with 17 additions and 3 deletions.
  1. +3 −2 director/factory.go
  2. +6 −0 director/factory_config_test.go
  3. +2 −1 uaa/factory.go
  4. +6 −0 uaa/factory_config_test.go
@@ -2,6 +2,7 @@ package director

import (
"fmt"
"net"
"net/http"
"net/url"

@@ -66,7 +67,7 @@ func (f Factory) httpClient(config Config, taskReporter TaskReporter, fileReport
return err
}

req.URL.Host = fmt.Sprintf("%s:%d", config.Host, config.Port)
req.URL.Host = net.JoinHostPort(config.Host, fmt.Sprintf("%d", config.Port))

req.Header.Del("Referer")

@@ -80,7 +81,7 @@ func (f Factory) httpClient(config Config, taskReporter TaskReporter, fileReport

endpoint := url.URL{
Scheme: "https",
Host: fmt.Sprintf("%s:%d", config.Host, config.Port),
Host: net.JoinHostPort(config.Host, fmt.Sprintf("%d", config.Port)),
}

return NewClient(endpoint.String(), httpClient, taskReporter, fileReporter, f.logger), nil
@@ -32,6 +32,12 @@ var _ = Describe("NewConfigFromURL", func() {
Expect(config).To(Equal(Config{Host: "host", Port: 4443}))
})

It("works with ipv6 hosts", func() {
config, err := NewConfigFromURL("https://[2600:1f17:a63:5c00:5a20:7eec:cf9:e31f]:25555")
Expect(err).ToNot(HaveOccurred())
Expect(config).To(Equal(Config{Host: "2600:1f17:a63:5c00:5a20:7eec:cf9:e31f", Port: 25555}))
})

It("returns error if url is empty", func() {
_, err := NewConfigFromURL("")
Expect(err).To(HaveOccurred())
@@ -2,6 +2,7 @@ package uaa

import (
"fmt"
"net"
"net/url"

bosherr "github.com/cloudfoundry/bosh-utils/errors"
@@ -54,7 +55,7 @@ func (f Factory) httpClient(config Config) (Client, error) {

endpoint := url.URL{
Scheme: "https",
Host: fmt.Sprintf("%s:%d", config.Host, config.Port),
Host: net.JoinHostPort(config.Host, fmt.Sprintf("%d", config.Port)),
Path: config.Path,
}

@@ -38,6 +38,12 @@ var _ = Describe("NewConfigFromURL", func() {
Expect(config).To(Equal(Config{Host: "host", Port: 4443, Path: "/zakrules"}))
})

It("works with ipv6 hosts", func() {
config, err := NewConfigFromURL("https://[2600:1f17:a63:5c00:5a20:7eec:cf9:e31f]:4443")
Expect(err).ToNot(HaveOccurred())
Expect(config).To(Equal(Config{Host: "2600:1f17:a63:5c00:5a20:7eec:cf9:e31f", Port: 4443}))
})

It("returns error if url is empty", func() {
_, err := NewConfigFromURL("")
Expect(err).To(HaveOccurred())

0 comments on commit 0316b3a

Please sign in to comment.
You can’t perform that action at this time.