1 SUB WWWHDR(WORD F.FILE) %TITLE "WWWHDR" %IDENT "X0.8" ! http server - output the header of a www response ! (c) 2012 by Johnny Billquist ! ! X0.0 2012-04-12 Johnny Billquist ! Initial coding ! ! X0.1 2012-08-17 Johnny Billquist ! New version, as redirects have been implemented, along ! with PUBLIC.LNK nesting files. ! ! X0.2 2012-11-26 Johnny Billquist ! Changed QT library interface. ! ! X0.3 2016-02-11 Johnny Billquist ! Added Content-Length: header ! ! X0.4 2016-03-11 Johnny Billquist ! Bygfix. We should not use content-length in combination ! with chunked. So we remove chunking, and drop connection ! at end of transfer, so we can give length. This also ! in fact improves transfer rates. ! ! X0.5 2016-03-17 Johnny Billquist ! Added timestamp compares. ! ! X0.6 2016-05-12 Johnny Billquist ! Bugfix. CGI output at HTTP 1.0 should not be ! chunked. It was accidentally always set as chunked. ! ! X0.7 13-Oct-2017 Johnny Billquist ! Skip sending keep-alive header. Many crawlers ! process it wrong, closing down active connection ! after that time, instead of just applying it to ! idle connections. ! ! X0.8 13-Oct-2017 Johnny Billquist ! Revert X0.7. Seems the problem is something else ! than the crawlers disconnecting. %INCLUDE "WWW.INC" %INCLUDE "LB:[1,1]BQTLIB.B2S" DECLARE WORD F.NOBODY F.NOBODY = 0 KAF = "close" UNLESS F.KAF COMPARE = 0 UNLESS STATVAL = 200 SELECT COMPARE CASE 1 IF CMPQT(STRQT(C.DATE),FTS) > -1 THEN STATVAL = 304 STATTXT = "Not modified" F.SKIP = 1 END IF CASE 2 IF CMPQT(STRQT(C.DATE),FTS) < 1 THEN STATVAL = 412 STATTXT = "Precondition failed" F.SKIP = 1 END IF CASE ELSE END SELECT F.NOBODY = 1 IF (STATVAL/100 = 1) OR & STATVAL=204 OR & STATVAL=304 F.BODY=0 IF F.NOBODY F.CHUNK=1 IF F.SKIP OR (F.FILE=0 AND F.CGI=0) OR (F.CGI AND F.KAF) F.CHUNK=0 UNLESS F.V11 CALL WWWLOG(STATVAL,"") PRINT #WWWFIL USING "'E ### 'E",TRM$(RVER),STATVAL,TRM$(STATTXT) PRINT #WWWFIL,"Date: ";QTSTR("",32+64+128) PRINT #WWWFIL,"Server: ";TRM$(SRV) PRINT #WWWFIL,"Transfer-Encoding: chunked" IF F.CHUNK AND F.NOBODY=0 PRINT #WWWFIL,"Content-Length:";FSIZ UNLESS F.CHUNK OR F.NOBODY OR & F.CGI PRINT #WWWFIL,"Last-Modified: ";QTSTR(FTS,64+128) IF F.FILE PRINT #WWWFIL,"Connection: ";TRM$(KAF) PRINT #WWWFIL,"Keep-Alive: timeout="+NUM1$(TMO)+", max=100" IF F.KAF END SUB