-
Notifications
You must be signed in to change notification settings - Fork 744
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
Fix panic observed in setSiteImplicitly function #3053
Conversation
Fixes #3052 |
endpoints/openrtb2/auction.go
Outdated
@@ -1972,6 +1973,9 @@ func setSiteImplicitly(httpReq *http.Request, r *openrtb_ext.RequestWrapper) { | |||
} | |||
|
|||
if referrerCandidate != "" { | |||
if r.Site == nil { |
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.
There's another way that I think this check can be made that could improve the flow of the overall function:
I think you can pull this check to the beginning of the function, which will then allow the other r.Site
nil checks to be removed.
So the overall function would maybe look something like this:
func setSiteImplicitly(httpReq *http.Request, r *openrtb_ext.RequestWrapper) {
if r.Site == nil {
r.Site = &openrtb2.Site{}
}
referrerCandidate := httpReq.Referer()
if referrerCandidate == "" && r.Site.Page != "" {
referrerCandidate = r.Site.Page // If http referer is disabled and thus has empty value - use site.page instead
}
if referrerCandidate != "" {
setSitePageIfEmpty(r.Site, referrerCandidate)
if parsedUrl, err := url.Parse(referrerCandidate); err == nil {
setSiteDomainIfEmpty(r.Site, parsedUrl.Host)
if publisherDomain, err := publicsuffix.EffectiveTLDPlusOne(parsedUrl.Host); err == nil {
setSitePublisherDomainIfEmpty(r.Site, publisherDomain)
}
}
}
if siteExt, err := r.GetSiteExt(); err == nil && siteExt.GetAmp() == nil {
siteExt.SetAmp(¬Amp)
}
}
What do you think about 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.
@AlexBVolcy
Setting it at the top of function will change the existing behaviour of function, will provide the wrong message in bid-response.
Example -
Moving the condition to top breaks the TestJsonSampleRequests
when request does not contain both site and app object.
Test: TestJsonSampleRequests/Asserts_we_return_400s_on_requests_that_are_not_supposed_to_pass_validation#49
Actual: Invalid request: request.site should include at least one of request.site.id or request.site.page.
Expected: Invalid request: request.site or request.app must be defined, but not both.
Filename: sample-requests/invalid-whole/no-site-or-app.json
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.
@AlexBVolcy what is your suggestion ? should we move it to top or keep it as it is ?
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.
I think it is good to move it to the top. Since this is only called when app
is nil, we know we always want to have a site object by the time we are done. So might as well make sure we have one at the top, and then we don't have to check for the remainder of the function.
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.
okay, moved the nil-check at the top.
Also, modified the error-message in no-site-or-app.json
file
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.
@ashishshinde-pubm Apologies for the late reply, but yes I agree with @hhhjort, thank you for moving it.
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.
LGTM
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.
LGTM
No description provided.