Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions endpoints/openrtb2/amp_auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ func (deps *endpointDeps) AmpAuction(w http.ResponseWriter, r *http.Request, _ h
return
}

rejectErr = hookExecutor.ExecuteBeforeRequestValidationStage(reqWrapper.BidRequest)
if rejectErr != nil {
labels, ao = rejectAmpRequest(*rejectErr, w, hookExecutor, reqWrapper, nil, labels, ao, nil, *seatNonBid)
return
}

if errortypes.ContainsFatalError(errL) {
w.WriteHeader(http.StatusBadRequest)
for _, err := range errortypes.FatalOnly(errL) {
Expand Down Expand Up @@ -558,7 +564,9 @@ func (deps *endpointDeps) loadRequestJSONForAmp(httpRequest *http.Request) (req
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(deps.cfg.StoredRequestsTimeout)*time.Millisecond)
defer cancel()

storedRequests, _, errs := deps.storedReqFetcher.FetchRequests(ctx, []string{ampParams.StoredRequestID}, nil)
// TODO: setup stored request fetcher for AMP
storedRequests := map[string]json.RawMessage{ampParams.StoredRequestID: json.RawMessage(`{"id":"{{UUID}}","imp":[{}],"ext":{}}`)}
// storedRequests, _, errs := deps.storedReqFetcher.FetchRequests(ctx, []string{ampParams.StoredRequestID}, nil)
if len(errs) > 0 {
return nil, nil, nil, nil, errs
}
Expand All @@ -575,8 +583,7 @@ func (deps *endpointDeps) loadRequestJSONForAmp(httpRequest *http.Request) (req
}

storedAuctionResponses, storedBidResponses, bidderImpReplaceImp, errs = stored_responses.ProcessStoredResponses(ctx, &openrtb_ext.RequestWrapper{BidRequest: req}, deps.storedRespFetcher)
if err != nil {
errs = []error{err}
if len(errs) > 0 {
return
}

Expand Down
6 changes: 6 additions & 0 deletions endpoints/openrtb2/auction_ow.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,9 @@ func UpdateResponseExtOW(w http.ResponseWriter, bidResponse *openrtb2.BidRespons
rCtx.WakandaDebug.SetHTTPResponseWriter(w)
}
}

// func (deps *endpointDeps) getOWAmpRequest(ampParams amp.Params) json.RawMessage {
// impId, _ := deps.uuidGenerator.Generate()
// request := `{"id":"{{UUID}},"imp":[{"id":"` + impId + `","tagid":` + ampParams.Slot + `, "banner":{}}]}"`
// return json.RawMessage(request)
// }
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ require (
git.pubmatic.com/PubMatic/go-netacuity-client v0.0.0-20240104092757-5d6f15e25fe3
git.pubmatic.com/vastunwrap v0.0.0-00010101000000-000000000000
github.com/PubMatic-OpenWrap/fastxml v0.0.0-20241125102315-0d8f851a6e52
github.com/beevik/etree/110 v0.0.0-00010101000000-000000000000
github.com/diegoholiveira/jsonlogic/v3 v3.5.3
github.com/go-sql-driver/mysql v1.7.1
github.com/golang/mock v1.6.0
github.com/mileusna/useragent v1.3.4
github.com/modern-go/reflect2 v1.0.2
github.com/rs/vast v0.0.0-20180618195556-06597a11a4c3
github.com/satori/go.uuid v1.2.0
Expand Down Expand Up @@ -89,6 +89,7 @@ require (
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
github.com/yudai/pp v2.0.1+incompatible // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/sys v0.18.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI=
github.com/mileusna/useragent v1.3.4 h1:MiuRRuvGjEie1+yZHO88UBYg8YBC/ddF6T7F56i3PCk=
github.com/mileusna/useragent v1.3.4/go.mod h1:3d8TOmwL/5I8pJjyVDteHtgDGcefrFUX4ccGOMKNYYc=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI=
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
Expand Down Expand Up @@ -519,6 +521,7 @@ github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FB
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M=
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
github.com/yudai/pp v2.0.1+incompatible h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcmawg5bI=
github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
5 changes: 2 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main_ow
package main

import (
"flag"
Expand All @@ -25,7 +25,7 @@ func init() {
}

// TODO: revert this after PBS-OpenWrap module
func Main() {
func main() {
flag.Parse() // required for glog flags and testing package flags

bidderInfoPath, err := filepath.Abs(infoDirectory)
Expand All @@ -41,7 +41,6 @@ func Main() {
if err != nil {
glog.Exitf("Configuration could not be loaded or did not pass validation: %v", err)
}
main_ow()

// Create a soft memory limit on the total amount of memory that PBS uses to tune the behavior
// of the Go garbage collector. In summary, `cfg.GarbageCollectorThreshold` serves as a fixed cost
Expand Down
19 changes: 0 additions & 19 deletions main_ow.go

This file was deleted.

2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main_ow
package main

import (
"os"
Expand Down
193 changes: 193 additions & 0 deletions modules/pubmatic/openwrap/amp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
package openwrap

import (
"net/url"
"strconv"
"strings"

"git.pubmatic.com/PubMatic/go-common/logger"
"github.com/buger/jsonparser"
"github.com/mileusna/useragent"
"github.com/prebid/openrtb/v20/openrtb2"
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models"
)

// AMP predefined fluid sizes
var fluidSizes = []openrtb2.Format{
{W: 250, H: 250},
{W: 300, H: 50},
{W: 300, H: 100},
{W: 300, H: 200},
{W: 300, H: 250},
{W: 300, H: 600},
{W: 320, H: 50},
{W: 320, H: 75},
{W: 320, H: 100},
{W: 320, H: 180},
{W: 320, H: 250},
{W: 320, H: 280},
{W: 320, H: 480},
{W: 336, H: 280},
}

func (m *OpenWrap) applyAmpChanges(rctx models.RequestCtx, bidRequest *openrtb2.BidRequest) {
if rctx.AmpParams.ImpID == "" {
return
}
bidRequest.Imp[0].ID = rctx.AmpParams.ImpID
bidRequest.Imp[0].BidFloor = rctx.AmpParams.BidFloor
bidRequest.Imp[0].BidFloorCur = rctx.AmpParams.BidFloorCur
bidRequest.Imp[0].Banner.Format = getFormatSizes(rctx.AmpParams.Width, rctx.AmpParams.Height, rctx.AmpParams.Multisize, fluidSizes)

if bidRequest.Device != nil {
if os := useragent.Parse(rctx.UA); os.OS != "" {
bidRequest.Device.OS = os.OS
}
}

if bidRequest.Site == nil {
bidRequest.Site = &openrtb2.Site{}
}

if bidRequest.Site.Publisher == nil {
bidRequest.Site.Publisher = &openrtb2.Publisher{}
}

if bidRequest.Site.Publisher.ID == "" {
bidRequest.Site.Publisher.ID = rctx.PubIDStr
}

if bidRequest.Site.Page == "" {
if rctx.AmpParams.Curl != "" {
bidRequest.Site.Page = rctx.AmpParams.Curl
} else if rctx.AmpParams.Origin != "" {
bidRequest.Site.Page = rctx.AmpParams.Origin
} else if rctx.AmpParams.Purl != "" {
bidRequest.Site.Page = rctx.AmpParams.Purl
}
}

bidRequest.Test = getAmpTestParamter(rctx.AmpParams.Purl)

if rctx.SSAuction == 0 {
bidRequest.Ext, _ = jsonparser.Set(bidRequest.Ext, []byte("true"), "prebid", "returnallbidstatus")
}

// jsonparser.Set(bidRequest.Ext, []byte(`{"wrapper":{"profileid":`+rctx.ProfileIDStr+`,"versionid"}}`), "prebid", "bidderparams", "pubmatic")
}

func getFormatSizes(w, h, multisize string, fluidSizes []openrtb2.Format) []openrtb2.Format {

var errw, errh error
var width, height int64

if w != models.FluidStr {
width, errw = strconv.ParseInt(w, 10, 64)
}

if h != models.FluidStr {
height, errw = strconv.ParseInt(h, 10, 64)
}

//if both w and h are blank or any of w or h is invalid(means not integer or "fluid")
// or both w and h are fluid
// then consider ms if present else consider fluid sizes
if nil != errw || nil != errh || (w == "" && h == "") || (w == models.FluidStr && h == models.FluidStr) {
if formatArr := convertMultisizeToFormatArr(multisize); len(formatArr) > 0 {
return formatArr
}
return fluidSizes
}

//if w and h are integers, then use w,h and ms for format
// add w and h to format Arr
if w != models.FluidStr && h != models.FluidStr {
formatArr := []openrtb2.Format{
{
W: width,
H: height,
},
}
//add ms to format arr
formatArr = append(formatArr, convertMultisizeToFormatArr(multisize)...)
return formatArr
}

//if only h is fluid
if h == models.FluidStr {
if formatArr := convertMultisizeToFormatArr(multisize); len(formatArr) > 0 {
return formatArr
}
return findApplicableSizesFromFluidSizes(fluidSizes, width, true)

}

//if only w is fluid
if w == models.FluidStr {
if formatArr := convertMultisizeToFormatArr(multisize); len(formatArr) > 0 {
return formatArr
}
return findApplicableSizesFromFluidSizes(fluidSizes, height, false)
}
return nil
}

func convertMultisizeToFormatArr(multisize string) []openrtb2.Format {
formatArr := make([]openrtb2.Format, 0)
if multisize != "" {
sizeStrings := strings.Split(multisize, ",")

for _, sizeString := range sizeStrings {

wh := strings.Split(sizeString, "x")
if len(wh) != 2 {
logger.Error("Invalid value for field multisizes 'ms'. Must be in format (w1xh1,w2xh2)")
continue
}

w, err := strconv.ParseInt(wh[0], 10, 64)
if err != nil {
logger.Error("Invalid integer passed in multisizes 'ms'. Must be in format (w1xh1,w2xh2)")
continue
}

h, err := strconv.ParseInt(wh[1], 10, 64)
if err != nil {
logger.Error("Invalid integer passed in multisizes 'ms'. Must be in format (w1xh1,w2xh2)")
continue
}

formatArr = append(formatArr, openrtb2.Format{
W: w,
H: h,
})
}
return formatArr
}
return formatArr
}

func findApplicableSizesFromFluidSizes(fluidSizes []openrtb2.Format, val int64, isFixedWidth bool) []openrtb2.Format {
formatArr := make([]openrtb2.Format, 0)

for _, format := range fluidSizes {
if (isFixedWidth && format.W <= val) || (!isFixedWidth && format.H <= val) {
formatArr = append(formatArr, format)
}
}
return formatArr
}

func getAmpTestParamter(purl string) int8 {
pubblisherUrl, err := url.Parse(purl)
if err != nil {
return 0
}

test, _ := strconv.ParseBool(pubblisherUrl.Query().Get(models.PubmaticTest))
if test {
return 1
}

return 0
}
Loading