-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to add PKI certificate to a request #38
Comments
req uses http.Client, you can customize the client, for example: package main
import (
"crypto/tls"
"crypto/x509"
"github.com/imroc/req"
"io/ioutil"
"log"
"net/http"
)
const (
localCertFile = "/usr/local/internal-ca/ca.crt"
)
func main() {
// Get the SystemCertPool, continue with an empty pool on error
rootCAs, _ := x509.SystemCertPool()
if rootCAs == nil {
rootCAs = x509.NewCertPool()
}
// Read in the cert file
certs, err := ioutil.ReadFile(localCertFile)
if err != nil {
log.Fatalf("Failed to append %q to RootCAs: %v", localCertFile, err)
}
// Append our cert to the system pool
if ok := rootCAs.AppendCertsFromPEM(certs); !ok {
log.Println("No certs appended, using system certs only")
}
// Trust the augmented cert pool in our client
config := &tls.Config{
InsecureSkipVerify: false,
RootCAs: rootCAs,
}
tr := &http.Transport{TLSClientConfig: config}
client := &http.Client{Transport: tr}
req.SetClient(client)
} |
thx && understood, but given kennethreitz/requests can handle certs conveniently, shall we make the analogical APIs available? |
sounds great, I'll consider this |
v2 support this, try and enjoy :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for client cert and trusted ca cert
thx
The text was updated successfully, but these errors were encountered: