@@ -884,34 +884,15 @@ func (c *Client) SetRootCertificate(pemFilePath string) *Client {
884
884
c .log .Errorf ("%v" , err )
885
885
return c
886
886
}
887
-
888
- config , err := c .tlsConfig ()
889
- if err != nil {
890
- c .log .Errorf ("%v" , err )
891
- return c
892
- }
893
- if config .RootCAs == nil {
894
- config .RootCAs = x509 .NewCertPool ()
895
- }
896
-
897
- config .RootCAs .AppendCertsFromPEM (rootPemData )
887
+ c .handleCAs ("root" , rootPemData )
898
888
return c
899
889
}
900
890
901
891
// SetRootCertificateFromString method helps to add one or more root certificates into Resty client
902
892
//
903
- // client.SetRootCertificateFromString("pem file content")
904
- func (c * Client ) SetRootCertificateFromString (pemContent string ) * Client {
905
- config , err := c .tlsConfig ()
906
- if err != nil {
907
- c .log .Errorf ("%v" , err )
908
- return c
909
- }
910
- if config .RootCAs == nil {
911
- config .RootCAs = x509 .NewCertPool ()
912
- }
913
-
914
- config .RootCAs .AppendCertsFromPEM ([]byte (pemContent ))
893
+ // client.SetRootCertificateFromString("pem certs content")
894
+ func (c * Client ) SetRootCertificateFromString (pemCerts string ) * Client {
895
+ c .handleCAs ("root" , []byte (pemCerts ))
915
896
return c
916
897
}
917
898
@@ -924,35 +905,37 @@ func (c *Client) SetClientRootCertificate(pemFilePath string) *Client {
924
905
c .log .Errorf ("%v" , err )
925
906
return c
926
907
}
927
-
928
- config , err := c .tlsConfig ()
929
- if err != nil {
930
- c .log .Errorf ("%v" , err )
931
- return c
932
- }
933
- if config .ClientCAs == nil {
934
- config .ClientCAs = x509 .NewCertPool ()
935
- }
936
-
937
- config .ClientCAs .AppendCertsFromPEM (rootPemData )
908
+ c .handleCAs ("client" , rootPemData )
938
909
return c
939
910
}
940
911
941
912
// SetClientRootCertificateFromString method helps to add one or more client's root certificates into Resty client
942
913
//
943
- // client.SetClientRootCertificateFromString("pem file content")
944
- func (c * Client ) SetClientRootCertificateFromString (pemContent string ) * Client {
914
+ // client.SetClientRootCertificateFromString("pem certs content")
915
+ func (c * Client ) SetClientRootCertificateFromString (pemCerts string ) * Client {
916
+ c .handleCAs ("client" , []byte (pemCerts ))
917
+ return c
918
+ }
919
+
920
+ func (c * Client ) handleCAs (scope string , permCerts []byte ) {
945
921
config , err := c .tlsConfig ()
946
922
if err != nil {
947
923
c .log .Errorf ("%v" , err )
948
- return c
949
- }
950
- if config .ClientCAs == nil {
951
- config .ClientCAs = x509 .NewCertPool ()
924
+ return
952
925
}
953
926
954
- config .ClientCAs .AppendCertsFromPEM ([]byte (pemContent ))
955
- return c
927
+ switch scope {
928
+ case "root" :
929
+ if config .RootCAs == nil {
930
+ config .RootCAs = x509 .NewCertPool ()
931
+ }
932
+ config .RootCAs .AppendCertsFromPEM (permCerts )
933
+ case "client" :
934
+ if config .ClientCAs == nil {
935
+ config .ClientCAs = x509 .NewCertPool ()
936
+ }
937
+ config .ClientCAs .AppendCertsFromPEM (permCerts )
938
+ }
956
939
}
957
940
958
941
// SetOutputDirectory method sets output directory for saving HTTP response into file.
0 commit comments