cb99f0b11bdeee5dfa76064d38b6410da0f4a709 max Thu Sep 10 00:55:21 2026 -0700 Centralize CGI Content-Type printing in one cgiPrintContentType() helper Around 90 places across the tree hand-rolled the CGI response header, each with its own spelling: "Content-Type:" or "Content-type:", \n or \r\n, and the terminating blank line written as part of the same string, as a separate puts("\n") (which emits two newlines, so a stray blank line led the body) or as printf("\r\n\r\n") (two blank lines). A handful forgot the terminator entirely and relied on a following header to supply it. cgiPrintContentType() in lib/cheapcgi.c now writes the Content-Type line and the blank line that ends the header. Header lines are not ordered, so the callers that also send Status, Set-Cookie, Content-Disposition, Content-Length or X-Sendfile write those first and call this last to close the header; that keeps it to a single helper rather than a print-the-line / end-the-header pair that a caller can half-use. cart.c's existing httpHeaders list already worked this way. Only the CGI response path is touched. The dyStringPrintf("Content-type: ...") calls that build outgoing HTTP *requests* (genomeSpace, oauthLogin, eapMetaSync, edwWebAuthLogin, ga4ghToBed) are unrelated and left alone. Also fills out the apiKey error message in botDelay.c to say where to create a key and that keys are server-specific. No behavior change on the wire beyond dropping those stray blank lines and adding the missing newline after Retry-After. diff --git src/hg/cirm/cdw/cdwGetMetadataAsFile/cdwGetMetadataAsFile.c src/hg/cirm/cdw/cdwGetMetadataAsFile/cdwGetMetadataAsFile.c index 6ba0d2bed0f..85335ddefb9 100644 --- src/hg/cirm/cdw/cdwGetMetadataAsFile/cdwGetMetadataAsFile.c +++ src/hg/cirm/cdw/cdwGetMetadataAsFile/cdwGetMetadataAsFile.c @@ -1,124 +1,124 @@ /* cdwGetMetadataAsFile - A CGI script that gets the metadata for a particular dataset as a file.. */ #include #include "common.h" #include "linefile.h" #include "hash.h" #include "options.h" #include "cheapcgi.h" #include "sqlSanity.h" #include "htmshell.h" #include "portable.h" #include "trashDir.h" #include "tagStorm.h" #include "cart.h" #include "cdw.h" #include "hdb.h" #include "hui.h" #include "cdw.h" #include "cdwValid.h" #include "web.h" #include "cdwLib.h" #include "wikiLink.h" #include "filePath.h" #include "obscure.h" #include "rql.h" typedef MYSQL_RES * STDCALL ResGetter(MYSQL *mysql); /* Global vars */ struct cart *cart; // User variables saved from click to click struct hash *oldVars; // Previous cart, before current round of CGI vars folded in struct cdwUser *user; // Our logged in user if any void usage() /* Explain usage and exit. */ { errAbort( "cdwGetMetadataAsFile - A CGI script that gets the metadata for a particular dataset as a file.\n" "usage:\n" " cdwGetMetadataAsFile XXX\n" "options:\n" " -xxx=XXX\n" ); } #ifdef OLD void setCdwUser(struct sqlConnection *conn) /* set the global variable 'user' based on the current cookie */ { char *userName = wikiLinkUserName(); // for debugging, accept the userName on the cgiSpoof command line // instead of a cookie if (hIsPrivateHost() && userName == NULL) userName = cgiOptionalString("userName"); if (userName != NULL) { /* Look up email vial hgCentral table */ struct sqlConnection *cc = hConnectCentral(); char query[512]; sqlSafef(query, sizeof(query), "select email from gbMembers where userName='%s'", userName); char *email = sqlQuickString(cc, query); hDisconnectCentral(&cc); user = cdwUserFromEmail(conn, email); } } #endif /* OLD */ void cdwGetMetadataAsFile(struct sqlConnection *conn) /* Determine the users's download format and generate a file that matches their * search criteria in the propper format */ { /* Get values from cart variables and make up an RQL query string out of fields, where, limit * clauses, */ /* Fields clause */ char *fieldsVar = "cdwQueryFields"; char *fields = cartUsualString(cart, fieldsVar, "*"); struct dyString *rqlQuery = dyStringCreate("select %s from files ", fields); /* Where clause */ char *whereVar = "cdwQueryWhere"; char *where = cartUsualString(cart, whereVar, ""); dyStringPrintf(rqlQuery, "where accession"); if (!isEmpty(where)) dyStringPrintf(rqlQuery, " and (%s)", where); /* Get the download format from the cart */ char *format = cartString(cart, "Download format"); /* Determine the users meta data access and generate a tagStorm tree of it. */ struct tagStorm *tags = cdwUserTagStorm(conn, user); /* Identify and print the meta data that matches the users search. */ cdwPrintMatchingStanzas(rqlQuery->string, 1000000, tags, format); } void localWebWrap(struct cart *theCart) /* We got the http stuff handled, and a cart. */ { cart = theCart; struct sqlConnection *conn = sqlConnect(cdwDatabase); -printf("Content-Type: text/plain\n\n"); +cgiPrintContentType("text/plain"); user = cdwCurrentUser(conn); cdwGetMetadataAsFile(conn); sqlDisconnect(&conn); } char *excludeVars[] = {"submit", NULL}; int main(int argc, char *argv[]) /* Process command line. */ { boolean isFromWeb = cgiIsOnWeb(); if (!isFromWeb && !cgiSpoof(&argc, argv)) usage(); oldVars = hashNew(0); cartEmptyShellNoContent(localWebWrap, hUserCookie(), excludeVars, oldVars); return 0; }