forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
legacy.go
97 lines (84 loc) · 3.07 KB
/
legacy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package adapters
import (
"context"
"crypto/tls"
"net/http"
"time"
"github.com/prebid/prebid-server/pbs"
"github.com/prebid/prebid-server/ssl"
)
// This file contains some deprecated, legacy types.
//
// These support the `/auction` endpoint, but will be replaced by `/openrtb2/auction`.
// New demand partners should ignore this file, and implement the Bidder interface.
// Adapter is a deprecated interface which connects prebid-server to a demand partner.
// PBS is currently being rewritten to use Bidder, and this will be removed after.
// Their primary purpose is to produce bids in response to Auction requests.
type Adapter interface {
// Name must be identical to the BidderName.
Name() string
// Determines whether this adapter should get callouts if there is not a synched user ID.
SkipNoCookies() bool
// Call produces bids which should be considered, given the auction params.
//
// In practice, implementations almost always make one call to an external server here.
// However, that is not a requirement for satisfying this interface.
//
// An error here will cause all bids to be ignored. If the error was caused by bad user input,
// this should return a BadInputError. If it was caused by bad server behavior
// (e.g. 500, unexpected response format, etc), this should return a BadServerResponseError.
Call(ctx context.Context, req *pbs.PBSRequest, bidder *pbs.PBSBidder) (pbs.PBSBidSlice, error)
}
// HTTPAdapterConfig groups options which control how HTTP requests are made by adapters.
type HTTPAdapterConfig struct {
// See IdleConnTimeout on https://golang.org/pkg/net/http/#Transport
IdleConnTimeout time.Duration
// See MaxIdleConns on https://golang.org/pkg/net/http/#Transport
MaxConns int
// See MaxIdleConnsPerHost on https://golang.org/pkg/net/http/#Transport
MaxConnsPerHost int
}
type HTTPAdapter struct {
Client *http.Client
}
// DefaultHTTPAdapterConfig is an HTTPAdapterConfig that chooses sensible default values.
var DefaultHTTPAdapterConfig = &HTTPAdapterConfig{
MaxConns: 50,
MaxConnsPerHost: 10,
IdleConnTimeout: 60 * time.Second,
}
// NewHTTPAdapter creates an HTTPAdapter which obeys the rules given by the config, and
// has all the available SSL certs available in the project.
func NewHTTPAdapter(c *HTTPAdapterConfig) *HTTPAdapter {
ts := &http.Transport{
MaxIdleConns: c.MaxConns,
MaxIdleConnsPerHost: c.MaxConnsPerHost,
IdleConnTimeout: c.IdleConnTimeout,
TLSClientConfig: &tls.Config{RootCAs: ssl.GetRootCAPool()},
}
return &HTTPAdapter{
Client: &http.Client{
Transport: ts,
},
}
}
// used for callOne (possibly pull all of the shared code here)
type CallOneResult struct {
StatusCode int
ResponseBody string
Bid *pbs.PBSBid
Error error
}
type MisconfiguredAdapter struct {
TheName string
Err error
}
func (b *MisconfiguredAdapter) Name() string {
return b.TheName
}
func (b *MisconfiguredAdapter) SkipNoCookies() bool {
return false
}
func (b *MisconfiguredAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidder *pbs.PBSBidder) (pbs.PBSBidSlice, error) {
return nil, b.Err
}