Ori.livneh has submitted this change and it was merged. Change subject: Emit GeoIP cookie using dedicated Set-Cookie header ......................................................................
Emit GeoIP cookie using dedicated Set-Cookie header If multiple Set-Cookie headers are set, VRT_GetHdr will only get the first, but VRT_SetHdr will clobber all of them. Varnish provides no facility for combining multiple instances of a particular header. We hack around that by creating a header with a unique name ("Xet-Cookie"), and then changing the name to "Set-Cookie", exploiting the fact that Varnish lays out the complete header (name and value) as a contiguous block of memory. Change-Id: I1cf419a845a89eb5b46faafe881e145e7c52ea1c --- M templates/varnish/geoip.inc.vcl.erb 1 file changed, 12 insertions(+), 8 deletions(-) Approvals: Ori.livneh: Verified; Looks good to me, approved jenkins-bot: Verified diff --git a/templates/varnish/geoip.inc.vcl.erb b/templates/varnish/geoip.inc.vcl.erb index 380008b..9f7942f 100644 --- a/templates/varnish/geoip.inc.vcl.erb +++ b/templates/varnish/geoip.inc.vcl.erb @@ -135,7 +135,7 @@ sub geoip_cookie { C{ GeoIPRecord *record; - char *set_cookie_header; + char *geo_header; const char *cookie_out = NULL; char cookie_buf[255]; @@ -166,13 +166,17 @@ } if (cookie_out) { - set_cookie_header = VRT_GetHdr(sp, HDR_RESP, "\013set-cookie:"); - if (set_cookie_header == NULL) { - // New header - VRT_SetHdr(sp, HDR_RESP, "\013Set-Cookie:", cookie_out, vrt_magic_string_end); - } else { - // Append to existing header - VRT_SetHdr(sp, HDR_RESP, "\013Set-Cookie:", set_cookie_header, "; ", cookie_out, vrt_magic_string_end); + /* + * If multiple Set-Cookie headers are set, VRT_GetHdr will only get the first, + * but VRT_SetHdr will clobber all of them. Varnish provides no facility for + * combining multiple instances of a particular header. We hack around that + * by creating a header with a unique name ("Xet-Cookie"), and then changing + * the name to "Set-Cookie". + */ + VRT_SetHdr(sp, HDR_RESP, "\013Xet-Cookie:", cookie_out, vrt_magic_string_end); + geo_header = VRT_GetHdr(sp, HDR_RESP, "\013Xet-Cookie:"); + if (geo_header != NULL && strncmp(geo_header - 12, "Xet-Cookie: ", 12) == 0) { + *(geo_header - 12) = 'S'; } } }C -- To view, visit https://gerrit.wikimedia.org/r/117375 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I1cf419a845a89eb5b46faafe881e145e7c52ea1c Gerrit-PatchSet: 3 Gerrit-Project: operations/puppet Gerrit-Branch: production Gerrit-Owner: Ori.livneh <o...@wikimedia.org> Gerrit-Reviewer: BBlack <bbl...@wikimedia.org> Gerrit-Reviewer: Faidon Liambotis <fai...@wikimedia.org> Gerrit-Reviewer: Ori.livneh <o...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits