9684047874667451e47229f16b5c9eab60286850 braney Sat Apr 11 12:15:39 2015 -0700 change mirror redirect to be opt-in. diff --git src/hg/hgGateway/hgGateway.c src/hg/hgGateway/hgGateway.c index 9a548fa..330bce8 100644 --- src/hg/hgGateway/hgGateway.c +++ src/hg/hgGateway/hgGateway.c @@ -240,30 +240,32 @@ printf("\n", clade); else printf("\n", "mammal"); printf("\n", organism); printf("\n", db); puts("
"); } void doMiddle(struct cart *theCart) /* Set up pretty web display and save cart in global. */ { char *scientificName = NULL; cart = theCart; +if(cgiIsOnWeb()) + checkForGeoMirrorRedirect(cart); getDbGenomeClade(cart, &db, &organism, &clade, oldVars); if (! hDbIsActive(db)) { db = hDefaultDb(); organism = hGenome(db); clade = hClade(organism); } scientificName = hScientificName(db); if (hIsGsidServer()) cartWebStart(theCart, db, "GSID %s Sequence View (UCSC Genome Browser) Gateway \n", organism); else { char buffer[128]; /* tell html routines *not* to escape htmlOut strings*/ @@ -278,91 +280,31 @@ } cartWebStart(theCart, db, "%s %s%s Gateway\n", trackHubSkipHubName(organism), buffer, hBrowserName()); htmlDoEscape(); } cartFlushHubWarnings(); hgGateway(); // TODO REMOVE AFTER AUTOUPGRADE COMPLETE: (added 2014-03-09) if (dyUpgradeError) warn("%s", dyUpgradeError->string); cartWebEnd(); } -static void checkForGeoMirrorRedirect() -{ -// Implement Geo/IP based redirection -// -// NOTE that we want to redirect people as quickly as possible, so for efficiency purposes, this code is designed to be -// called from main BEFORE the cart is loaded (so we only use CGI parameters and/or cookies). - -char *thisNodeStr = geoMirrorNode(); -if (thisNodeStr) - { - char *redirectCookie = findCookieData("redirect"); - char *redirect = cgiOptionalString("redirect"); - - //fprintf(stderr, "GALT redirectCookie=%s redirect=%s\n", - //redirectCookie, redirect); fflush(stderr); // DEBUG REMOVE - - if (redirect == NULL && redirectCookie == NULL) - { - int thisNode = sqlUnsigned(thisNodeStr); - struct sqlConnection *centralConn = hConnectCentral(); - char *ipStr = cgiRemoteAddr(); - int node = defaultNode(centralConn, ipStr); - - // get location of redirect node - if (thisNode != node) - { - char *geoSuffix = cfgOptionDefault("browser.geoSuffix",""); - char query[1056]; - sqlSafef(query, sizeof query, "select domain from gbNode%s where node = %d", geoSuffix, node); - char *newDomain = sqlQuickString(centralConn, query); - //fprintf(stderr, "GALT newDomain=%s\n", newDomain); fflush(stderr); // DEBUG REMOVE - char *oldDomain = cgiServerName(); - char *port = cgiServerPort(); - char *uri = cgiRequestUri(); - char *sep = strchr(uri, '?') ? "&" : "?"; - int newUriSize = strlen(uri) + 1024; - char *newUri = needMem(newUriSize); - safef(newUri, newUriSize, "http%s://%s:%s%s%sredirect=auto&source=%s", - cgiServerHttpsIsOn() ? "s" : "", newDomain, port, uri, sep, oldDomain); - struct dyString *dy = dyStringNew(256); - dyStringPrintf(dy, - "HTTP/1.1 302 found: \n" - "Content-Type: text/html; charset=iso-8859-1\n" - "Connection: close\n" - "Location: %s\n" - "\n" - "Redirecting to closer site\n" - "%s\n" - , newUri , newUri, newUri); - //fprintf(stderr, "GALT redirect response:\n%s", dy->string); fflush(stderr); // DEBUG REMOVE - puts(dyStringContents(dy)); - exit(0); - } - hDisconnectCentral(¢ralConn); - } - } -} - char *excludeVars[] = {NULL}; int main(int argc, char *argv[]) /* Process command line. */ { long enteredMainTime = clock1000(); oldVars = hashNew(10); cgiSpoof(&argc, argv); setUdcCacheDir(); -if(cgiIsOnWeb()) - checkForGeoMirrorRedirect(); cartEmptyShell(doMiddle, hUserCookie(), excludeVars, oldVars); cgiExitTime("hgGateway", enteredMainTime); return 0; }