Skip to content

Commit

Permalink
Merge pull request #3 from Songmu/dialcontext
Browse files Browse the repository at this point in the history
support DialContext for go 1.7
  • Loading branch information
hakobe authored Jan 4, 2017
2 parents 3cae2f0 + b9b315b commit 0173892
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: go
go:
- 1.6
- 1.7
- tip
script:
- make lint
Expand Down
9 changes: 5 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package paranoidhttp

import (
"context"
"errors"
"fmt"
"log"
Expand Down Expand Up @@ -67,15 +68,15 @@ func safeAddr(hostport string) (string, error) {
//
// This is used to create a new paranoid http.Client,
// because I'm not sure about a paranoid behavior for IPv6 connections :(
func NewDialer(dialer *net.Dialer) func(network, addr string) (net.Conn, error) {
return func(network, hostport string) (net.Conn, error) {
func NewDialer(dialer *net.Dialer) func(ctx context.Context, network, addr string) (net.Conn, error) {
return func(ctx context.Context, network, hostport string) (net.Conn, error) {
switch network {
case "tcp", "tcp4":
addr, err := safeAddr(hostport)
if err != nil {
return nil, err
}
return dialer.Dial("tcp4", addr)
return dialer.DialContext(ctx, "tcp4", addr)
default:
return nil, errors.New("does not support any networks except tcp4")
}
Expand All @@ -92,7 +93,7 @@ func NewClient() (*http.Client, *http.Transport, *net.Dialer) {
}
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: NewDialer(dialer),
DialContext: NewDialer(dialer),
TLSHandshakeTimeout: 10 * time.Second,
}
return &http.Client{
Expand Down

0 comments on commit 0173892

Please sign in to comment.