diff --git a/helpers.go b/helpers.go index 878cfbe..1586892 100644 --- a/helpers.go +++ b/helpers.go @@ -7,6 +7,9 @@ import ( "github.com/rs/zerolog/log" ) +// DoRequestNoRead makes a request and returns the response +// Compared to DoRequest, this function does not read the response body +// This function encapsulates the boilerplate for logging func DoRequestNoRead(req *http.Request) (*http.Response, error) { log.Debug().Str("method", req.Method).Str("host", req.Host).Str("path", req.URL.Path).Msg("Request") resp, err := client.Do(req) @@ -21,6 +24,8 @@ func DoRequestNoRead(req *http.Request) (*http.Response, error) { return resp, nil } +// DoRequest makes a request and returns the response and body +// This function encapsulates the boilerplate for logging and reading the response body func DoRequest(req *http.Request) (*http.Response, []byte, error) { log.Debug().Str("method", req.Method).Str("host", req.Host).Str("path", req.URL.Path).Msg("Request") resp, err := client.Do(req) @@ -42,6 +47,7 @@ func DoRequest(req *http.Request) (*http.Response, []byte, error) { return resp, body, nil } +// ApplySclaHeaders applies headers to a request for thescla.org func ApplySclaHeaders(req *http.Request) { req.Header.Set("Origin", "http://www2.thescla.org") req.Header.Set("Connection", "keep-alive") @@ -51,6 +57,7 @@ func ApplySclaHeaders(req *http.Request) { req.Header.Set("Accept-Encoding", "gzip, deflate") } +// ApplyUtsaHeaders applies headers to a request for utsa.edu func ApplyUtsaHeaders(req *http.Request) { req.Header.Set("Connection", "keep-alive") req.Header.Set("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0")