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/hgGenome/hgGenome.c src/hg/hgGenome/hgGenome.c index fb4a0d00044..291599ec094 100644 --- src/hg/hgGenome/hgGenome.c +++ src/hg/hgGenome/hgGenome.c @@ -522,31 +522,31 @@ { /* Default case - start fancy web page. */ if (cgiVarExists(hggPsOutput)) handlePostscript(conn); else mainPage(conn); } cartRemovePrefix(cart, hggDo); } void hggDoUsualHttp() /* Wrap html page dispatcher with code that writes out * HTTP header and write cart back to database. */ { cartWriteCookie(cart, hUserCookie()); -printf("Content-Type:text/html\r\n\r\n"); +cgiPrintContentType("text/html"); /* Dispatch other pages, that actually want to write HTML. */ cartWarnCatcher(dispatchPage, cart, cartEarlyWarningHandler); cartCheckout(&cart); } void dispatchLocation() /* When this is called no output has been written at all. We * look at command variables in cart and figure out if we just * are going write an HTTP location line, which happens when we * want to invoke say the genome browser or gene sorter without * another intermediate page. If we need to do more than that * then we call hggDoUsualHttp. */ {