requester

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 30 Imported by: 1

Documentation

Overview

Package requester defines the RTBRequester interface and its implementations for executing RTB source round-trips.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrResponseAreNotSecure is returned when an HTTP response is received
	// for a request that requires HTTPS (i.e. contains http:// in markup).
	ErrResponseAreNotSecure = errors.New("response are not secure")

	// ErrInvalidResponseStatus is returned when the HTTP response status code
	// is not one of: 200, 204, 404.
	ErrInvalidResponseStatus = errors.New("invalid response status")

	// ErrResponseNoBid is returned when the RTB source explicitly has no bid
	// (HTTP 204 / 404 or empty SeatBid list).
	ErrResponseNoBid = adtype.ErrResponseNoBid

	// ErrUnsupportedRequestType is returned when the source is configured with
	// a request body encoding that is not yet implemented (e.g. XML, Protobuf).
	ErrUnsupportedRequestType = errors.New("request body type not supported")

	// ErrUndefinedRequestType is returned when the source has an unrecognised
	// RTBRequestType value.
	ErrUndefinedRequestType = errors.New("undefined request type")

	// ErrNilSource is returned when the RTBSource pointer is nil.
	ErrNilSource = errors.New("rtb source must not be nil")

	// ErrNilHTTPClient is returned when the HTTP client is nil.
	ErrNilHTTPClient = errors.New("http client must not be nil")
)

Errors set — sentinel errors for type-assertable error handling.

Functions

This section is empty.

Types

type HTTPStatusError

type HTTPStatusError struct {
	Code int
}

HTTPStatusError is a typed error that carries the unexpected HTTP status code returned by an RTB endpoint. It wraps ErrInvalidResponseStatus so callers can use errors.Is(err, ErrInvalidResponseStatus) while still being able to inspect the concrete code via errors.As.

func (*HTTPStatusError) Error

func (e *HTTPStatusError) Error() string

func (*HTTPStatusError) Is

func (e *HTTPStatusError) Is(target error) bool

Is satisfies errors.Is for the sentinel ErrInvalidResponseStatus.

type HttpRTBRequester

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

HttpRTBRequester implements RTBRequester by performing real HTTP calls to an RTB source.

func NewHttpRTBRequester

func NewHttpRTBRequester(source *admodels.RTBSource, netClient httpclient.Driver) (*HttpRTBRequester, error)

NewHttpRTBRequester creates a new HttpRTBRequester for the given source and HTTP client.

func (*HttpRTBRequester) Request

func (r *HttpRTBRequester) Request(request adtype.BidRequester, beginTime uint64) (adtype.Response, error)

Request sends the bid request to the RTB source and returns the response.

func (*HttpRTBRequester) SetSource

func (r *HttpRTBRequester) SetSource(src adtype.Source)

SetSource sets the adtype.Source used to tag bid response items. Call this after the driver (which implements adtype.Source) has been created.

type MatchItem

type MatchItem struct {
	BidResponse *openrtb.BidResponse
	Imp         *adtype.Impression
	AdFormat    *types.Format
}

func (*MatchItem) BuildResponse

func (m *MatchItem) BuildResponse() (*openrtb.BidResponse, error)

BuildResponse returns a deep-copied, ID-patched BidResponse that contains only the bids compatible with m.Imp (as determined by bidMatchesImpression). Returns an error when no qualifying bids survive the filter.

type MockRTBRequester

type MockRTBRequester struct {
	// Response to return on DoServerRequest. If nil, ErrResponseNoBid is returned.
	Response adtype.Response
	// Err to return on DoServerRequest. Overrides Response when non-nil.
	Err error
}

MockRTBRequester is a test implementation of RTBRequester that returns a pre-configured response without making any real HTTP calls.

func (*MockRTBRequester) Request

Request returns the pre-configured Response and Err fields.

type RTBRequester

type RTBRequester interface {
	Request(request adtype.BidRequester, beginTime uint64) (adtype.Response, error)
}

RTBRequester wraps the execution of a single RTB server round-trip. Implementations are responsible for sending a bid request to an RTB source and returning the resulting adtype.Response.

type SimulationRTBRequester

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

SimulationRTBRequester implements RTBRequester for simulation and replay testing. At construction it accepts a list of raw JSON OpenRTB bid-response strings and converts them into template objects. On each Request call it:

  • filters templates by ad-type compatibility and minimum bid floor
  • selects randomly from the matching set (falls back to all templates if none match)
  • deep-copies the selected template
  • generates fresh IDs for BidResponse.ID and every Bid.ID
  • assigns a new ID to every SeatBid.Seat
  • rewires every Bid.ImpID to cycle through the impressions present in the request

func NewSimulationRTBRequester

func NewSimulationRTBRequester(jsonResponses []string) (*SimulationRTBRequester, error)

NewSimulationRTBRequester parses jsonResponses into OpenRTB response objects and returns a ready-to-use SimulationRTBRequester. Returns an error if any JSON is malformed or the slice is empty.

func (*SimulationRTBRequester) Request

Request selects the next template response, deep-copies it, patches all identifiers (BidResponse.ID, Bid.ID, SeatBid.Seat, Bid.ImpID) and returns a fully prepared adtype.Response.

func (*SimulationRTBRequester) SetSource

func (s *SimulationRTBRequester) SetSource(src adtype.Source)

SetSource sets the adtype.Source used to tag bid response items. Call this after the driver (which implements adtype.Source) has been created.

type UndefinedTypeError

type UndefinedTypeError struct {
	TypeName string
}

UndefinedTypeError is returned when the source has an unrecognised RTBRequestType value.

func (*UndefinedTypeError) Error

func (e *UndefinedTypeError) Error() string

func (*UndefinedTypeError) Is

func (e *UndefinedTypeError) Is(target error) bool

Is satisfies errors.Is for the sentinel ErrUndefinedRequestType.

type UnsupportedTypeError

type UnsupportedTypeError struct {
	TypeName string
}

UnsupportedTypeError is returned when the source is configured with a request body encoding that is not implemented.

func (*UnsupportedTypeError) Error

func (e *UnsupportedTypeError) Error() string

func (*UnsupportedTypeError) Is

func (e *UnsupportedTypeError) Is(target error) bool

Is satisfies errors.Is for the sentinel ErrUnsupportedRequestType.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL