Check-in [879cdc86ce]
Overview
Comment:Added support for not redirecting to index.html
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:879cdc86ce0d1912c18a19b140bbbbb267a67e4d
User & Date: rkeene on 2018-05-03 20:08:05
Other Links: manifest | tags
Context
2020-03-31
14:30
Integrated remove-c11-atomics changes check-in: 7ee2e833d2 user: rkeene tags: trunk
13:41
Merged in trunk check-in: 1c1d95a764 user: rkeene tags: remove-c11-atomics
2018-05-03
20:08
Added support for not redirecting to index.html check-in: 879cdc86ce user: rkeene tags: trunk
2016-09-22
19:30
Post-release version increment check-in: f3418e68d2 user: rkeene tags: trunk
Changes

Modified README from [8ec76224c9] to [e85e320923].

    78     78           rather than call chroot() at startup.  This is less secure and slower
    79     79           and should be generally avoided -- however it may be necessary to do.
    80     80           In these cases the executable may be compiled with the
    81     81           FILED_FAKE_CHROOT C preprocessor macro defined and instead of calling
    82     82           chroot() all HTTP requests will have the root suffix specified as the
    83     83           argument to the "-r" or "--root" option prepended to them.
    84     84   
    85         -   6. MIME Types (MIMETYPES)
           85  +   6. Differing "index.html" handling (CFLAGS, -DFILED_DONT_REDIRECT_DIRECTORIES=1)
           86  +        Normally "filed" redirects users who request a directory to the
           87  +        index.html file in that directory so that no memory allocations are
           88  +        required;  This option lets the server generate the new path.
           89  +
           90  +   7. MIME Types (MIMETYPES)
    86     91   	For single-file convenience "filed" compiles the mapping of file
    87     92   	extensions (the string in the filename following its last dot ("."))
    88     93   	into the executable.  This mapping comes from a file in the format of
    89     94   		type1   type1_extension1 type1_extension2...
    90     95   		type2   type2_extension1 type2_extension2...
    91     96   		...
    92     97   	However it may not be desirable to include this mapping, or it may be

Modified filed.c from [8f507e1315] to [b6a9efc107].

  1207   1207   
  1208   1208   	fclose(fp);
  1209   1209   
  1210   1210   	return;
  1211   1211   }
  1212   1212   
  1213   1213   /* Return a redirect to index.html */
         1214  +#ifndef FILED_DONT_REDIRECT_DIRECTORIES
  1214   1215   static void filed_redirect_index(FILE *fp, const char *date_current, const char *path, struct filed_log_entry *log) {
  1215         -	int http_code = 301;
         1216  +	int http_code = 302;
  1216   1217   	fprintf(fp, "HTTP/1.1 %i OK\r\nDate: %s\r\nServer: filed\r\nLast-Modified: %s\r\nContent-Length: 0\r\nConnection: close\r\nLocation: %s\r\n\r\n",
  1217   1218   		http_code,
  1218   1219   		date_current,
  1219   1220   		date_current,
  1220   1221   		"index.html"
  1221   1222   	);
  1222   1223   
................................................................................
  1232   1233   	fclose(fp);
  1233   1234   
  1234   1235   	return;
  1235   1236   
  1236   1237   	/* Currently unused: path */
  1237   1238   	path = path;
  1238   1239   }
         1240  +#endif
  1239   1241   
  1240   1242   /* Convert an enum representing the "Connection" header value to a string */
  1241   1243   static const char *filed_connection_str(int connection_value) {
  1242   1244   	switch (connection_value) {
  1243   1245   		case FILED_CONNECTION_CLOSE:
  1244   1246   			return("close");
  1245   1247   		case FILED_CONNECTION_KEEP_ALIVE:
................................................................................
  1293   1295   
  1294   1296   	path = request->path;
  1295   1297   	strcpy(log->buffer, path);
  1296   1298   	log->method = request->method;
  1297   1299   
  1298   1300   	/* If the requested path is a directory, redirect to index page */
  1299   1301   	if (request->type == FILED_REQUEST_TYPE_DIRECTORY) {
         1302  +#ifdef FILED_DONT_REDIRECT_DIRECTORIES
         1303  +		char localpath[8192];
         1304  +		int snprintf_ret;
         1305  +
         1306  +		snprintf_ret = snprintf(localpath, sizeof(localpath), "%s/index.html", path);
         1307  +
         1308  +		if (snprintf_ret <= 0 || snprintf_ret > (sizeof(localpath) - 1)) {
         1309  +			filed_error_page(fp, date_current, 500, request->method, "path_format", log);
         1310  +
         1311  +			return(FILED_CONNECTION_CLOSE);
         1312  +		}
         1313  +
         1314  +		path = localpath;
         1315  +#else
  1300   1316   		filed_redirect_index(fp, date_current, path, log);
  1301   1317   
  1302   1318   		return(FILED_CONNECTION_CLOSE);
         1319  +#endif
  1303   1320   	}
  1304   1321   
  1305   1322   	fileinfo = filed_open_file(path, &request->fileinfo, options);
  1306   1323   	if (fileinfo == NULL) {
  1307   1324   		filed_error_page(fp, date_current, 404, request->method, "open_failed", log);
  1308   1325   
  1309   1326   		return(FILED_CONNECTION_CLOSE);