Documentation Source Text

Check-in [452b6e3c75]
Login

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

Overview
Comment:Improvements to the althttpd logic that redirects to the base document when there are surplus pathname elements in the request URI.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 452b6e3c756102d72431baa49e2f8049fb483189
User & Date: drh 2013-12-16 17:01:37.757
Context
2013-12-16
20:13
Add an extra column to the logfile output from althttpd. The 16th column gives the number of characters in the request URI that contribute to the script name. This is useful with substr() in doing queries against specific CGI scripts. (check-in: faec8e5df4 user: drh tags: trunk)
17:01
Improvements to the althttpd logic that redirects to the base document when there are surplus pathname elements in the request URI. (check-in: 452b6e3c75 user: drh tags: trunk)
14:39
When serving static content that has extra elements on the end of the URI, return a 301 to redirect to the base document, so that relative hyperlinks in the document will be correct. (check-in: 1682f2225f user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to misc/althttpd.c.
867
868
869
870
871
872
873









874
875
876
877
878
879
880
/* 2x */   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,
/* 3x */   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,
/* 4x */   0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
/* 5x */   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  1,
/* 6x */   0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
/* 7x */   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  1,  0,
};










/*
** This routine processes a single HTTP request on standard input and
** sends the reply to standard output.  If the argument is 1 it means
** that we are should close the socket without processing additional
** HTTP requests after the current request finishes.  0 means we are
** allowed to keep the connection open and to process additional requests.







>
>
>
>
>
>
>
>
>







867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
/* 2x */   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,
/* 3x */   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,
/* 4x */   0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
/* 5x */   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  1,
/* 6x */   0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
/* 7x */   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  1,  0,
};

/*
** Count the number of "/" characters in a string.
*/
static int countSlashes(const char *z){
  int n = 0;
  while( *z ) if( *(z++)=='/' ) n++;
  return n;
}

/*
** This routine processes a single HTTP request on standard input and
** sends the reply to standard output.  If the argument is 1 it means
** that we are should close the socket without processing additional
** HTTP requests after the current request finishes.  0 means we are
** allowed to keep the connection open and to process additional requests.
1005
1006
1007
1008
1009
1010
1011
1012


1013
1014
1015
1016
1017
1018
1019
    }
  }

  /* Disallow referring from certain clients */
  if( zAgent ){
    if( strstr(zAgent, "Windows_9")!=0
     || strstr(zAgent, "Download_Master")!=0
     || strstr(zAgent, "_Ezooms/")!=0


    ){
      Forbidden();
    }
  }
#if 0
  if( zReferer ){
    static const char *azDisallow[] = {







|
>
>







1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
    }
  }

  /* Disallow referring from certain clients */
  if( zAgent ){
    if( strstr(zAgent, "Windows_9")!=0
     || strstr(zAgent, "Download_Master")!=0
     || strstr(zAgent, "Ezooms/")!=0
   /*|| strstr(zAgent, "bingbot")!=0*/
     || strstr(zAgent, "AhrefsBot")!=0
    ){
      Forbidden();
    }
  }
#if 0
  if( zReferer ){
    static const char *azDisallow[] = {
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
    */
    if( useTimeout ) alarm(60*5);
    while( (c = getc(in))!=EOF ){
      putc(c,stdout);
      nOut++;
    }
    fclose(in);
  }else if( zScript[lenFile-1]!=0 ){
    /* The URI refers to a non-executable file so it is static content.  But
    /* there are extra terms in the URI past the end of the content.  We need
    ** to redirected to that relative URLs in the content will be right. */
    StartResponse("301 Moved Permanently");
    if( zServerPort==0 || zServerPort[0]==0 || strcmp(zServerPort,"80")==0 ){
      nOut += printf("Location: %s://%s%s\r\n",
                     zHttp, zServerName, zFile+1);
    }else{
      nOut += printf("Location: %s://%s:%s%s\r\n",
                     zHttp, zServerName, zServerPort, zFile+1);
    }
    nOut += printf("Content-length: 0\r\n");
    nOut += printf("\r\n");
    MakeLogEntry(0);
    fflush(stdout);
  }else{
    /* If it isn't executable then it







|






|


|







1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
    */
    if( useTimeout ) alarm(60*5);
    while( (c = getc(in))!=EOF ){
      putc(c,stdout);
      nOut++;
    }
    fclose(in);
  }else if( countSlashes(zRealScript)!=countSlashes(zScript) ){
    /* The URI refers to a non-executable file so it is static content.  But
    /* there are extra terms in the URI past the end of the content.  We need
    ** to redirected to that relative URLs in the content will be right. */
    StartResponse("301 Moved Permanently");
    if( zServerPort==0 || zServerPort[0]==0 || strcmp(zServerPort,"80")==0 ){
      nOut += printf("Location: %s://%s%s\r\n",
                     zHttp, zServerName, zRealScript);
    }else{
      nOut += printf("Location: %s://%s:%s%s\r\n",
                     zHttp, zServerName, zServerPort, zRealScript);
    }
    nOut += printf("Content-length: 0\r\n");
    nOut += printf("\r\n");
    MakeLogEntry(0);
    fflush(stdout);
  }else{
    /* If it isn't executable then it