Hello,

I need to implement client tls under fasthttp. when I set Client TLSConfig 
it is not even make a request and status code 200 return, could someone 
help me over it?

package main

import (
  "fmt"
  log "github.com/Sirupsen/logrus"
  "github.com/valyala/fasthttp"
  "crypto/tls"
  "crypto/x509"
  "io/ioutil"
)

func req(method string, url string, data []byte) (int, []byte) {
    cert, err := tls.LoadX509KeyPair("a.txt", "a.key")
    if err != nil {
      log.Fatal(err)
    }

    // Load CA cert
    caCert, err := ioutil.ReadFile("a.csr")
    if err != nil {
      log.Fatal(err)
    }
    caCertPool := x509.NewCertPool()
    caCertPool.AppendCertsFromPEM(caCert)

    // Setup HTTPS client
    tlsConfig := &tls.Config{
      Certificates: []tls.Certificate{cert},
      RootCAs:      caCertPool,
    }

  req := fasthttp.AcquireRequest()
  req.SetRequestURI(url)
  req.Header.SetMethod(method)
  req.SetBody(data)
  resp := fasthttp.AcquireResponse()
  
  client := &fasthttp.Client{
    TLSConfig: tlsConfig,
  }
  client.Do(req, resp)  
  statusCode := resp.StatusCode()
  body := resp.Body()
  return statusCode, body
}

func main(){
  a, b := req("GET", "https://google.com";, nil)

  fmt.Printf(string(b))
  fmt.Println(a)

}

 


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/37cb0a30-27b4-4822-bdea-0da6d63e3741n%40googlegroups.com.

Reply via email to