-
Notifications
You must be signed in to change notification settings - Fork 769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modularity: Make request wrapper accessible in bidder request hook #3096
Changes from 5 commits
79ac96c
cdc8f22
39f39d4
80daab8
64ca130
358c3b4
d841a8a
37a5e5a
c5a7249
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,9 @@ package hookstage | |
|
||
import ( | ||
"errors" | ||
"github.com/prebid/prebid-server/openrtb_ext" | ||
|
||
"github.com/prebid/openrtb/v19/adcom1" | ||
"github.com/prebid/openrtb/v19/openrtb2" | ||
) | ||
|
||
func (c *ChangeSet[T]) BidderRequest() ChangeSetBidderRequest[T] { | ||
|
@@ -31,10 +31,10 @@ func (c ChangeSetBidderRequest[T]) BApp() ChangeSetBApp[T] { | |
return ChangeSetBApp[T]{changeSetBidderRequest: c} | ||
} | ||
|
||
func (c ChangeSetBidderRequest[T]) castPayload(p T) (*openrtb2.BidRequest, error) { | ||
func (c ChangeSetBidderRequest[T]) castPayload(p T) (*openrtb_ext.RequestWrapper, error) { | ||
if payload, ok := any(p).(BidderRequestPayload); ok { | ||
if payload.BidRequest == nil { | ||
return nil, errors.New("empty BidRequest provided") | ||
return nil, errors.New("payload contains a nil bid request") | ||
} | ||
return payload.BidRequest, nil | ||
} | ||
|
@@ -47,9 +47,9 @@ type ChangeSetBAdv[T any] struct { | |
|
||
func (c ChangeSetBAdv[T]) Update(badv []string) { | ||
c.changeSetBidderRequest.changeSet.AddMutation(func(p T) (T, error) { | ||
bidRequest, err := c.changeSetBidderRequest.castPayload(p) | ||
bidRequestWrapper, err := c.changeSetBidderRequest.castPayload(p) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps the return value from |
||
if err == nil { | ||
bidRequest.BAdv = badv | ||
bidRequestWrapper.BAdv = badv | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I imagine it is guaranteed that if we got this far There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically auction and mutation functions should be never executed with nil bid request. req = &openrtb_ext.RequestWrapper{}
req.BidRequest = &openrtb2.BidRequest{} I added extra nil check in if payload.BidRequest == nil || payload.BidRequest.BidRequest == nil {...} |
||
} | ||
return p, err | ||
}, MutationUpdate, "bidrequest", "badv") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,5 +26,5 @@ type ProcessedAuctionRequest interface { | |
// ProcessedAuctionRequestPayload consists of the openrtb_ext.RequestWrapper object. | ||
// Hooks are allowed to modify openrtb_ext.RequestWrapper using mutations. | ||
type ProcessedAuctionRequestPayload struct { | ||
RequestWrapper *openrtb_ext.RequestWrapper | ||
BidRequest *openrtb_ext.RequestWrapper | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think naming There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Request Wrapper is an internal concept for optimization. I don't find the Bid Request misleading, since the RequestWrapper embeds the BidRequest it acts as a drop-in replacement with enhanced functionality. Would it be better to name this simply Request instead of BidRequest? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I prefer it being named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,11 @@ func handleBidderRequestHook( | |
cfg config, | ||
payload hookstage.BidderRequestPayload, | ||
) (result hookstage.HookResult[hookstage.BidderRequestPayload], err error) { | ||
if payload.BidRequest == nil { | ||
return result, hookexecution.NewFailure("empty BidRequest provided") | ||
if payload.BidRequest == nil || payload.BidRequest.BidRequest == nil { | ||
return result, hookexecution.NewFailure("empty input provided") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about we use the same error message we now use in the mutation code: |
||
} | ||
|
||
mediaTypes := mediaTypesFrom(payload.BidRequest) | ||
mediaTypes := mediaTypesFrom(payload.BidRequest.BidRequest) | ||
changeSet := hookstage.ChangeSet[hookstage.BidderRequestPayload]{} | ||
blockingAttributes := blockingAttributes{} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a variable name other than
brw
we could use? I'd prefer something likereqWrapper
for clarity, but if you preferbrw
I'm fine to keep it like this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed to
request
, similar to other renames