Compare commits

...

3 Commits

Author SHA1 Message Date
eyedeekay
b550471a50 makefile 2025-05-26 21:24:19 -04:00
eyedeekay
aafbeeb29f fmt 2025-05-26 21:23:08 -04:00
eyedeekay
793aa2de23 implement post body handling 2025-05-26 21:19:38 -04:00
3 changed files with 25 additions and 2 deletions

2
Makefile Normal file
View File

@@ -0,0 +1,2 @@
fmt:
find . -name '*.go' -not -path './vendor/*' -exec gofumpt -s -extra -w {} \;

View File

@@ -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

View File

@@ -85,5 +85,4 @@ func main() {
log.Println("Response Status:", resp.Status)
}(conn)
}
}