801905c20d758a520abff2e0b8a269ceef3cce0c larrym Thu Sep 8 10:21:15 2011 -0700 more work on return image via URL (redmine 4888) diff --git src/hg/hgTracks/hgTracks.c src/hg/hgTracks/hgTracks.c index 5c5916b..90ce5b7 100644 --- src/hg/hgTracks/hgTracks.c +++ src/hg/hgTracks/hgTracks.c @@ -2539,33 +2539,52 @@ if(rulerClickHeight) { jsonHashAddNumber(jsonForClient, "rulerClickHeight", rulerClickHeight); } if(newWinWidth) { jsonHashAddNumber(jsonForClient, "newWinWidth", newWinWidth); } /* Save out picture and tell html file about it. */ if(hvgSide != hvg) hvGfxClose(&hvgSide); hvGfxClose(&hvg); #ifdef SUPPORT_CONTENT_TYPE -// following is (currently dead) experimental code to bypass hgml and return png's directly - see redmine 4888 -if(sameString(cartUsualString(cart, "hgt.contentType", "html"), "png")) +char *type = cartUsualString(cart, "hgt.contentType", "html"); +if(sameString(type, "jsonp")) + { + struct jsonHashElement *json = newJsonHash(newHash(8)); + + printf("Content-Type: application/json\n\n"); + jsonHashAddString(json, "track", cartString(cart, "hgt.trackNameFilter")); + jsonHashAddNumber(json, "height", pixHeight); + jsonHashAddNumber(json, "width", pixWidth); + jsonHashAddString(json, "src", gifTn.forHtml); + printf("%s(", cartString(cart, "jsonp")); + hPrintEnable(); + jsonPrint((struct jsonElement *) json, NULL, 0); + hPrintDisable(); + printf(")\n"); + return; + } +else if(sameString(type, "png")) { + // following is (currently dead) experimental code to bypass hgml and return png's directly - see redmine 4888 + printf("Content-Disposition: filename=hgTracks.png\nContent-Type: image/png\n\n"); + char buf[4096]; FILE *fd = fopen(gifTn.forCgi, "r"); if(fd == NULL) // fail some other way (e.g. HTTP 500)? errAbort("Couldn't open png for reading"); while(TRUE) { size_t n = fread(buf, 1, sizeof(buf), fd); if(n) fwrite(buf, 1, n, stdout); else break; } fclose(fd); unlink(gifTn.forCgi);