mirror of
https://github.com/go-i2p/go-meta-dialer.git
synced 2025-08-19 08:45:29 -04:00
Compare commits
3 Commits
715e91be3c
...
b550471a50
Author | SHA1 | Date | |
---|---|---|---|
![]() |
b550471a50 | ||
![]() |
aafbeeb29f | ||
![]() |
793aa2de23 |
2
Makefile
Normal file
2
Makefile
Normal file
@@ -0,0 +1,2 @@
|
||||
fmt:
|
||||
find . -name '*.go' -not -path './vendor/*' -exec gofumpt -s -extra -w {} \;
|
24
client.go
24
client.go
@@ -1,8 +1,11 @@
|
||||
package metadialer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
@@ -32,6 +35,10 @@ func NewMetaHTTPClient(rootCAs *x509.CertPool) *MetaHTTPClient {
|
||||
}
|
||||
|
||||
// Use standard verification for all other domains
|
||||
if len(state.PeerCertificates) == 0 {
|
||||
return fmt.Errorf("no peer certificates provided")
|
||||
}
|
||||
|
||||
opts := x509.VerifyOptions{
|
||||
DNSName: state.ServerName,
|
||||
Intermediates: x509.NewCertPool(),
|
||||
@@ -64,7 +71,22 @@ func (c *MetaHTTPClient) Get(url string) (*http.Response, error) {
|
||||
|
||||
// Post is a convenience method for making POST requests
|
||||
func (c *MetaHTTPClient) Post(url, contentType string, body interface{}) (*http.Response, error) {
|
||||
return c.Client.Post(url, contentType, nil) // Replace nil with actual body handling
|
||||
// Convert the body interface{} to io.Reader
|
||||
var bodyReader io.Reader
|
||||
if body != nil {
|
||||
switch v := body.(type) {
|
||||
case io.Reader:
|
||||
bodyReader = v
|
||||
case []byte:
|
||||
bodyReader = bytes.NewReader(v)
|
||||
case string:
|
||||
bodyReader = strings.NewReader(v)
|
||||
default:
|
||||
// For other types, convert to string then to reader
|
||||
bodyReader = strings.NewReader(fmt.Sprintf("%v", v))
|
||||
}
|
||||
}
|
||||
return c.Client.Post(url, contentType, bodyReader)
|
||||
}
|
||||
|
||||
// PostForm is a convenience method for making POST requests with form data
|
||||
|
@@ -85,5 +85,4 @@ func main() {
|
||||
log.Println("Response Status:", resp.Status)
|
||||
}(conn)
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user