package comm

import "github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/internal/comm"

Package comm provides helpers for communicating with HTTP backends.

Index

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client provides a wrapper to our *http.Client that handles compression and serialization needs.

func New

func New(httpClient HTTPClient) *Client

New returns a new Client object.

func (*Client) JSONCall

func (c *Client) JSONCall(ctx context.Context, endpoint string, headers http.Header, qv url.Values, body, resp interface{}) error

JSONCall connects to the REST endpoint passing the HTTP query values, headers and JSON conversion of body in the HTTP body. It automatically handles compression and decompression with gzip. The response is JSON unmarshalled into resp. resp must be a pointer to a struct. If the body struct contains a field called "AdditionalFields" we use a custom marshal/unmarshal engine.

func (*Client) SOAPCall

func (c *Client) SOAPCall(ctx context.Context, endpoint, action string, headers http.Header, qv url.Values, body string, resp interface{}) error

SOAPCall returns the SOAP message given an endpoint, action, body of the request and the response object to marshal into.

func (*Client) URLFormCall

func (c *Client) URLFormCall(ctx context.Context, endpoint string, qv url.Values, resp interface{}) error

URLFormCall is used to make a call where we need to send application/x-www-form-urlencoded data to the backend and receive JSON back. qv will be encoded into the request body.

func (*Client) XMLCall

func (c *Client) XMLCall(ctx context.Context, endpoint string, headers http.Header, qv url.Values, resp interface{}) error

XMLCall connects to an endpoint and decodes the XML response into resp. This is used when sending application/xml . If sending XML via SOAP, use SOAPCall().

type HTTPClient

type HTTPClient interface {
	// Do sends an HTTP request and returns an HTTP response.
	Do(req *http.Request) (*http.Response, error)

	// CloseIdleConnections closes any idle connections in a "keep-alive" state.
	CloseIdleConnections()
}

HTTPClient represents an HTTP client. It's usually an *http.Client from the standard library.

Source Files

comm.go compress.go

Version
v1.4.2 (latest)
Published
Mar 26, 2025
Platform
linux/amd64
Imports
17 packages
Last checked
2 days ago

Tools for package owners.