<commit_before>package client

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

	"github.com/libopenstorage/openstorage/volume"
)

type Client struct {
	base       *url.URL
	version    string
	httpClient *http.Client
}

func (c *Client) VolumeDriver() volume.VolumeDriver {
	return newVolumeClient(c)
}

func (c *Client) Status() (*Status, error) {
	var status Status
	err := c.Get().UsePath("/status").Do().Unmarshal(&status)
	return &status, err
}

func (c *Client) Get() *Request {
	return NewRequest(&http.Client{}, c.base, "GET", c.version)
}

func (c *Client) Post() *Request {
	return NewRequest(&http.Client{}, c.base, "POST", c.version)
}

func (c *Client) Put() *Request {
	return NewRequest(&http.Client{}, c.base, "PUT", c.version)
}

func (c *Client) Delete() *Request {
	return NewRequest(&http.Client{}, c.base, "DELETE", c.version)
}

func New(host string, version string) (*Client, error) {
	baseURL, err := url.Parse(host)
	if err != nil {
		return nil, err
	}
	if baseURL.Path == "" {
		baseURL.Path = "/"
	}
	c := &Client{
		base:       baseURL,
		version:    version,
		httpClient: &http.Client{},
	}
	return c, nil
}<commit_msg>http client from socket path<commit_after>package client

import (
	"crypto/tls"
	"net"
	"net/http"
	"net/url"
	"time"

	"github.com/libopenstorage/openstorage/volume"
)

type Client struct {
	base       *url.URL
	version    string
	httpClient *http.Client
}

func (c *Client) VolumeDriver() volume.VolumeDriver {
	return newVolumeClient(c)
}

func (c *Client) Status() (*Status, error) {
	var status Status
	err := c.Get().UsePath("/status").Do().Unmarshal(&status)
	return &status, err
}

func (c *Client) Get() *Request {
	return NewRequest(&http.Client{}, c.base, "GET", c.version)
}

func (c *Client) Post() *Request {
	return NewRequest(&http.Client{}, c.base, "POST", c.version)
}

func (c *Client) Put() *Request {
	return NewRequest(&http.Client{}, c.base, "PUT", c.version)
}

func (c *Client) Delete() *Request {
	return NewRequest(&http.Client{}, c.base, "DELETE", c.version)
}

func newHTTPClient(u *url.URL, tlsConfig *tls.Config, timeout time.Duration) *http.Client {

	httpTransport := &http.Transport{
		TLSClientConfig: tlsConfig,
	}

	switch u.Scheme {
	default:
		httpTransport.Dial = func(proto, addr string) (net.Conn, error) {
			return net.DialTimeout(proto, addr, timeout)
		}
	case "unix":
		socketPath := u.Path
		unixDial := func(proto, addr string) (net.Conn, error) {
			return net.DialTimeout("unix", socketPath, timeout)
		}
		httpTransport.Dial = unixDial
		// Override the main URL object so the HTTP lib won't complain
		u.Scheme = "http"
		u.Host = "unix.sock"
		u.Path = ""
	}
	return &http.Client{Transport: httpTransport}
}

func New(host string, version string) (*Client, error) {

	baseURL, err := url.Parse(host)
	if err != nil {
		return nil, err
	}
	if baseURL.Path == "" {
		baseURL.Path = "/"
	}
	httpClient := newHTTPClient(baseURL, nil, 10*time.Second)
	c := &Client{
		base:       baseURL,
		version:    version,
		httpClient: httpClient,
	}
	return c, nil
}
{'fraction_non_alphanumeric': 0.16146004603748768, 'fraction_numerical': 0.0006576783952647156, 'mean_word_length': 3.9868852459016395, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6766283', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1087, 'n_words': 283}