Compare commits
No commits in common. "1bcbb2079e81243e00198002cf8ae4f08303d570" and "9c972ffa6bb0faf851c4c6e607178e905e3937a9" have entirely different histories.
1bcbb2079e
...
9c972ffa6b
@ -1,7 +1,6 @@
|
|||||||
package remote
|
package remote
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
@ -177,6 +176,8 @@ func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKRespons
|
|||||||
var okResponse api.OKResponse
|
var okResponse api.OKResponse
|
||||||
var errResponse api.ErrResponse
|
var errResponse api.ErrResponse
|
||||||
|
|
||||||
|
InfoLogger.Printf("Outgoing request:", req.URL, req.Body)
|
||||||
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
resp, err := http.DefaultClient.Do(req)
|
resp, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -185,7 +186,6 @@ func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKRespons
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
InfoLogger.Printf("Received response for %s: Status Code: %d | Content-Type: %s", req.URL, resp.StatusCode, resp.Header.Get("Content-Type"))
|
|
||||||
body, err := io.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -216,29 +216,10 @@ func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKRespons
|
|||||||
|
|
||||||
func doCustodialRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) {
|
func doCustodialRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) {
|
||||||
req.Header.Set("X-GE-KEY", config.CustodialAPIKey)
|
req.Header.Set("X-GE-KEY", config.CustodialAPIKey)
|
||||||
logRequestDetails(req)
|
|
||||||
return doRequest(ctx, req, rcpt)
|
return doRequest(ctx, req, rcpt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func doDataRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) {
|
func doDataRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) {
|
||||||
req.Header.Set("X-GE-KEY", config.DataAPIKey)
|
req.Header.Set("X-GE-KEY", config.DataAPIKey)
|
||||||
logRequestDetails(req)
|
|
||||||
return doRequest(ctx, req, rcpt)
|
return doRequest(ctx, req, rcpt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func logRequestDetails(req *http.Request) {
|
|
||||||
var bodyBytes []byte
|
|
||||||
contentType := req.Header.Get("Content-Type")
|
|
||||||
if req.Body != nil {
|
|
||||||
bodyBytes, err := io.ReadAll(req.Body)
|
|
||||||
if err != nil {
|
|
||||||
ErrorLogger.Printf("Error reading request body: %s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
req.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
|
|
||||||
} else {
|
|
||||||
bodyBytes = []byte("-")
|
|
||||||
}
|
|
||||||
|
|
||||||
InfoLogger.Printf("URL: %s | Content-Type: %s | Method: %s| Request Body: %s", req.URL, contentType, req.Method, string(bodyBytes))
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user