Skip to content

Commit

Permalink
Get go-couchbase working with https.
Browse files Browse the repository at this point in the history
Change-Id: I1be13ce0a0fefd7407a4690d4611739114a41fd6
Reviewed-on: http://review.couchbase.org/61277
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Eben Haber <eben@couchbase.com>
  • Loading branch information
ebenhaber committed Mar 15, 2016
1 parent 6274761 commit 9bac287
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions pools.go
Expand Up @@ -2,6 +2,7 @@ package couchbase

import (
"bytes"
"crypto/tls"
"encoding/base64"
"encoding/json"
"errors"
Expand Down Expand Up @@ -463,13 +464,24 @@ func isHttpConnError(err error) bool {
strings.Contains(estr, "connection reset")
}

var client *http.Client

func doHTTPRequest(req *http.Request) (*http.Response, error) {

var err error
var res *http.Response

// we need a client that ignores certificate errors, since we self-sign
// our certs
if client == nil {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client = &http.Client{Transport: tr}
}

for i := 0; i < HTTP_MAX_RETRY; i++ {
res, err = HTTPClient.Do(req)
res, err = client.Do(req)
if err != nil && isHttpConnError(err) {
continue
}
Expand All @@ -493,9 +505,9 @@ func doPostAPI(
var requestUrl string

if q := strings.Index(path, "?"); q > 0 {
requestUrl = "http://" + baseURL.Host + path[:q] + "?" + path[q+1:]
requestUrl = baseURL.Scheme + "://" + baseURL.Host + path[:q] + "?" + path[q+1:]
} else {
requestUrl = "http://" + baseURL.Host + path
requestUrl = baseURL.Scheme + "://" + baseURL.Host + path
}

postData := url.Values{}
Expand Down Expand Up @@ -540,12 +552,14 @@ func queryRestAPI(
authHandler AuthHandler,
out interface{}) error {

fmt.Printf("queryRestAPI, baseURL: %v, schema %s, path: %s\n", baseURL, baseURL.Scheme, path)

var requestUrl string

if q := strings.Index(path, "?"); q > 0 {
requestUrl = "http://" + baseURL.Host + path[:q] + "?" + path[q+1:]
requestUrl = baseURL.Scheme + "://" + baseURL.Host + path[:q] + "?" + path[q+1:]
} else {
requestUrl = "http://" + baseURL.Host + path
requestUrl = baseURL.Scheme + "://" + baseURL.Host + path
}

req, err := http.NewRequest("GET", requestUrl, nil)
Expand Down

0 comments on commit 9bac287

Please sign in to comment.