Althttpd

Changes On Branch enable-atomics
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch enable-atomics Excluding Merge-Ins

This is equivalent to a diff from 0310001ae1 to 3496e47091

2022-09-26
16:57
Add the COOP and COEP HTTP reply headers if the --enable-sab command-line option is used. "sab" stands for "SharedArrayBuffer". ... (check-in: 85b7ee71fa user: drh tags: trunk)
16:55
Disable COOP and COEP by default. Enable only when the --enable-sab option appears on the command-line. ... (Closed-Leaf check-in: 3496e47091 user: drh tags: enable-atomics)
2022-08-29
11:20
Preserve the URL query string in the log. ... (check-in: 211d538804 user: drh tags: enable-atomics)
2022-08-12
18:17
Merge the --popup enhancement from trunk. ... (check-in: 823a1d985d user: drh tags: enable-atomics)
17:23
Add documentation of the --page and --popup options to the main page. ... (check-in: 0310001ae1 user: drh tags: trunk)
13:33
Add the --popup command-line option. ... (check-in: a66384d35c user: drh tags: trunk)

Changes to Makefile.
1
2


3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
10
11


+
+







default: althttpd althttpsd 
VERSION_NUMBER = 2.0
CC=cc
CFLAGS=-Os -Wall -Wextra

manifest:
	@if which fossil > /dev/null; then \
		fossil update --nosync current; \
	else \
	  echo "fossil binary not found. Version hash/time might be incorrect."
	fi
17
18
19
20
21
22
23
24

25
26
27
28

29
30
31
32

33
34
35
36

37
38
39
40
19
20
21
22
23
24
25

26
27
28
29

30
31
32
33

34
35
36
37

38
39
40
41








-
+



-
+



-
+



-
+



-
	time=`sed -n 2p manifest | cut -d' ' -f2`; \
	{ echo -n "ALTHTTPD_VERSION=\""; \
		echo '$(VERSION_NUMBER)' "[$$hash] [$$time]\""; \
	} > $@

althttpd:	althttpd.c version
	@flags="`cat version`"; set -x; \
	cc "-D$$flags" -Os -Wall -Wextra -o althttpd althttpd.c
	$(CC) $(CFLAGS) "-D$$flags" -o althttpd althttpd.c

althttpsd:	althttpd.c version
	@flags="`cat version`"; set -x; \
	cc "-D$$flags" -Os -Wall -Wextra -fPIC -o althttpsd -DENABLE_TLS althttpd.c -lssl -lcrypto
	$(CC) $(CFLAGS) "-D$$flags" -fPIC -o althttpsd -DENABLE_TLS althttpd.c -lssl -lcrypto

static-althttpd:	althttpd.c version
	@flags="`cat version`"; set -x; \
	cc "-D$$flags" -Os -Wall -Wextra -static -o althttpd althttpd.c
	$(CC) $(CFLAGS) "-D$$flags" -static -o althttpd althttpd.c

static-althttpsd:	althttpd.c version
	@flags="`cat version`"; set -x; \
	cc "-D$$flags" -Os -Wall -Wextra -static -fPIC -o althttpsd -DENABLE_TLS althttpd.c -lssl -lcrypto -lpthread -ldl
	$(CC) $(CFLAGS) "-D$$flags" -static -fPIC -o althttpsd -DENABLE_TLS althttpd.c -lssl -lcrypto -lpthread -ldl

clean:	
	rm -f althttpd althttpsd version

Changes to althttpd.c.
168
169
170
171
172
173
174






175
176
177
178
179
180
181
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187







+
+
+
+
+
+







**
**  --max-cpu SEC    Maximum number of seconds of CPU time allowed per
**                   HTTP connection.  Default 30 (build option:
**                   -DMAX_CPU=integer). 0 means no limit.
**
**  --debug BOOLEAN  Disables input timeouts.  This is useful for debugging
**                   when inputs are being typed in manually.
**
**  --enable-sab     Add new lines to the HTTP reply header that are
**                   prerequisites for SharedArrayBuffer.  These are the lines:
**                     Cross-Origin-Embedder-Policy: require-corp
**                     Cross-Origin-Opener-Policy: same-origin
**        
**
** Additional command-line options available when compiling with ENABLE_TLS:
**
**  --cert FILE      The TLS certificate, the "fullchain.pem" file
**
**  --pkey FILE      The TLS private key, the "privkey.pem" file.  May be
**                   omitted if the --cert file is the concatenation of
422
423
424
425
426
427
428


429
430
431
432
433
434
435
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443







+
+







static struct rusage priorChild; /* Previously report CHILD time */
static int mxAge = 120;          /* Cache-control max-age */
static char *default_path = "/bin:/usr/bin";  /* Default PATH variable */
static char *zScgi = 0;          /* Value of the SCGI env variable */
static int rangeStart = 0;       /* Start of a Range: request */
static int rangeEnd = 0;         /* End of a Range: request */
static int maxCpu = MAX_CPU;     /* Maximum CPU time per process */
static int enableSAB = 0;        /* Add reply header to enable
                                 ** SharedArrayBuffer */

/* Forward reference */
static void Malfunction(int errNo, const char *zFormat, ...);



#ifdef ENABLE_TLS
695
696
697
698
699
700
701

702
703
704
705
706
707
708
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717







+








    if( zScript==0 ) zScript = "";
    if( zRealScript==0 ) zRealScript = "";
    if( zRemoteAddr==0 ) zRemoteAddr = "";
    if( zHttpHost==0 ) zHttpHost = "";
    if( zReferer==0 ) zReferer = "";
    if( zAgent==0 ) zAgent = "";
    if( zQuerySuffix==0 ) zQuerySuffix = "";
    gettimeofday(&now, 0);
    pTm = localtime(&now.tv_sec);
    strftime(zDate, sizeof(zDate), "%Y-%m-%d %H:%M:%S", pTm);
    sz = strftime(zExpLogFile, sizeof(zExpLogFile), zLogFile, pTm);
    if( sz>0 && sz<sizeof(zExpLogFile)-2 ){
      zFilename = zExpLogFile;
    }else{
735
736
737
738
739
740
741
742

743
744

745
746
747
748
749
750
751
744
745
746
747
748
749
750

751
752
753
754
755
756
757
758
759
760
761







-
+


+







      ** (13) Request number for same TCP/IP connection
      ** (14) User agent
      ** (15) Remote user
      ** (16) Bytes of URL that correspond to the SCRIPT_NAME
      ** (17) Line number in source file
      */
      fprintf(log,
        "%s,%s,\"%s://%s%s\",\"%s\","
        "%s,%s,\"%s://%s%s%s\",\"%s\","
           "%s,%d,%d,%lld,%lld,%lld,%lld,%lld,%d,\"%s\",\"%s\",%d,%d\n",
        zDate, zRemoteAddr, zHttpScheme, Escape(zHttpHost), Escape(zScript),
        Escape(zQuerySuffix),
        Escape(zReferer), zReplyStatus, nIn, nOut,
        tvms(&self.ru_utime) - tvms(&priorSelf.ru_utime),
        tvms(&self.ru_stime) - tvms(&priorSelf.ru_stime),
        tvms(&children.ru_utime) - tvms(&priorChild.ru_utime),
        tvms(&children.ru_stime) - tvms(&priorChild.ru_stime),
        tvms(&now) - tvms(&beginTime),
        nRequest, Escape(zAgent), Escape(zRM),
2154
2155
2156
2157
2158
2159
2160






2161
2162
2163
2164
2165
2166
2167
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183







+
+
+
+
+
+







                    rangeStart, rangeEnd, (int)pStat->st_size);
    pStat->st_size = rangeEnd + 1 - rangeStart;
  }else{
    StartResponse("200 OK");
    rangeStart = 0;
  }
  nOut += DateTag("Last-Modified", pStat->st_mtime);
  if( enableSAB ){
    /* The following two HTTP reply headers are required if javascript
    ** is to make use of SharedArrayBuffer */
    nOut += althttpd_printf("Cross-Origin-Opener-Policy: same-origin\r\n");
    nOut += althttpd_printf("Cross-Origin-Embedder-Policy: require-corp\r\n");
  }
  nOut += althttpd_printf("Cache-Control: max-age=%d\r\n", mxAge);
  nOut += althttpd_printf("ETag: \"%s\"\r\n", zETag);
  nOut += althttpd_printf("Content-type: %s%s\r\n",zContentType,
                          bAddCharset ? "; charset=utf-8" : "");
  if( zEncoding ){
    nOut += althttpd_printf("Content-encoding: %s\r\n", zEncoding);
  }
3414
3415
3416
3417
3418
3419
3420



3421
3422
3423
3424
3425
3426
3427
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446







+
+
+







    }else
    if( strcmp(z,"-max-cpu")==0 ){
      maxCpu = atoi(zArg);
    }else
    if( strcmp(z,"-loopback")==0 ){
      bLocalhost = 1;
      nTerm = 1;
    }else
    if( strcmp(z,"-enable-sab")==0 ){
      enableSAB = 1;
    }else
    if( strcmp(z,"-page")==0 ){
      zPage = zArg;
      bLocalhost = 1;
      if( mnPort==0 ){
        mnPort = 8080;
        mxPort = 8100;