MCPcopy
hub / github.com/benbjohnson/wtf / newRequest

Method newRequest

http/http.go:38–55  ·  view source on GitHub ↗

newRequest returns a new HTTP request but adds the current user's API key and sets the accept & content type headers to use JSON.

(ctx context.Context, method, url string, body io.Reader)

Source from the content-addressed store, hash-verified

36// newRequest returns a new HTTP request but adds the current user's API key
37// and sets the accept & content type headers to use JSON.
38func (c *Client) newRequest(ctx context.Context, method, url string, body io.Reader) (*http.Request, error) {
39 // Build new request with base URL.
40 req, err := http.NewRequest(method, c.URL+url, body)
41 if err != nil {
42 return nil, err
43 }
44
45 // Set API key in header.
46 if user := wtf.UserFromContext(ctx); user != nil && user.APIKey != "" {
47 req.Header.Set("Authorization", "Bearer "+user.APIKey)
48 }
49
50 // Default to JSON format.
51 req.Header.Set("Accept", "application/json")
52 req.Header.Set("Content-type", "application/json")
53
54 return req, nil
55}
56
57// SessionCookieName is the name of the cookie used to store the session.
58const SessionCookieName = "session"

Callers 5

FindDialByIDMethod · 0.80
FindDialsMethod · 0.80
CreateDialMethod · 0.80
DeleteDialMethod · 0.80

Calls 1

UserFromContextFunction · 0.92

Tested by

no test coverage detected