You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
630 B
22 lines
630 B
package api
|
|
|
|
import (
|
|
"io"
|
|
"marmic/servicetrade-toolbox/internal/auth"
|
|
"net/http"
|
|
)
|
|
|
|
// AuthenticatedRequest wraps an http.Request with the session cookie
|
|
func AuthenticatedRequest(session *auth.Session, method, url string, body io.Reader) (*http.Request, error) {
|
|
req, err := http.NewRequest(method, url, body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
req.Header.Set("Cookie", session.Cookie)
|
|
return req, nil
|
|
}
|
|
|
|
// DoAuthenticatedRequest performs an authenticated request and returns the response
|
|
func DoAuthenticatedRequest(session *auth.Session, req *http.Request) (*http.Response, error) {
|
|
return session.Client.Do(req)
|
|
}
|
|
|