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
79
80
81
82
83
84





85
86
87
88
89
90
91
92
        rather than call chroot() at startup.  This is less secure and slower
        and should be generally avoided -- however it may be necessary to do.
        In these cases the executable may be compiled with the
        FILED_FAKE_CHROOT C preprocessor macro defined and instead of calling
        chroot() all HTTP requests will have the root suffix specified as the
        argument to the "-r" or "--root" option prepended to them.






   6. MIME Types (MIMETYPES)
	For single-file convenience "filed" compiles the mapping of file
	extensions (the string in the filename following its last dot ("."))
	into the executable.  This mapping comes from a file in the format of
		type1   type1_extension1 type1_extension2...
		type2   type2_extension1 type2_extension2...
		...
	However it may not be desirable to include this mapping, or it may be







>
>
>
>
>
|







78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
        rather than call chroot() at startup.  This is less secure and slower
        and should be generally avoided -- however it may be necessary to do.
        In these cases the executable may be compiled with the
        FILED_FAKE_CHROOT C preprocessor macro defined and instead of calling
        chroot() all HTTP requests will have the root suffix specified as the
        argument to the "-r" or "--root" option prepended to them.

   6. Differing "index.html" handling (CFLAGS, -DFILED_DONT_REDIRECT_DIRECTORIES=1)
        Normally "filed" redirects users who request a directory to the
        index.html file in that directory so that no memory allocations are
        required;  This option lets the server generate the new path.

   7. MIME Types (MIMETYPES)
	For single-file convenience "filed" compiles the mapping of file
	extensions (the string in the filename following its last dot ("."))
	into the executable.  This mapping comes from a file in the format of
		type1   type1_extension1 type1_extension2...
		type2   type2_extension1 type2_extension2...
		...
	However it may not be desirable to include this mapping, or it may be

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

1207
1208
1209
1210
1211
1212
1213

1214
1215
1216
1217
1218
1219
1220
1221
1222

	fclose(fp);

	return;
}

/* Return a redirect to index.html */

static void filed_redirect_index(FILE *fp, const char *date_current, const char *path, struct filed_log_entry *log) {
	int http_code = 301;
	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",
		http_code,
		date_current,
		date_current,
		"index.html"
	);








>

|







1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223

	fclose(fp);

	return;
}

/* Return a redirect to index.html */
#ifndef FILED_DONT_REDIRECT_DIRECTORIES
static void filed_redirect_index(FILE *fp, const char *date_current, const char *path, struct filed_log_entry *log) {
	int http_code = 302;
	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",
		http_code,
		date_current,
		date_current,
		"index.html"
	);

1232
1233
1234
1235
1236
1237
1238

1239
1240
1241
1242
1243
1244
1245
	fclose(fp);

	return;

	/* Currently unused: path */
	path = path;
}


/* Convert an enum representing the "Connection" header value to a string */
static const char *filed_connection_str(int connection_value) {
	switch (connection_value) {
		case FILED_CONNECTION_CLOSE:
			return("close");
		case FILED_CONNECTION_KEEP_ALIVE:







>







1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
	fclose(fp);

	return;

	/* Currently unused: path */
	path = path;
}
#endif

/* Convert an enum representing the "Connection" header value to a string */
static const char *filed_connection_str(int connection_value) {
	switch (connection_value) {
		case FILED_CONNECTION_CLOSE:
			return("close");
		case FILED_CONNECTION_KEEP_ALIVE:
1293
1294
1295
1296
1297
1298
1299














1300
1301
1302

1303
1304
1305
1306
1307
1308
1309

	path = request->path;
	strcpy(log->buffer, path);
	log->method = request->method;

	/* If the requested path is a directory, redirect to index page */
	if (request->type == FILED_REQUEST_TYPE_DIRECTORY) {














		filed_redirect_index(fp, date_current, path, log);

		return(FILED_CONNECTION_CLOSE);

	}

	fileinfo = filed_open_file(path, &request->fileinfo, options);
	if (fileinfo == NULL) {
		filed_error_page(fp, date_current, 404, request->method, "open_failed", log);

		return(FILED_CONNECTION_CLOSE);







>
>
>
>
>
>
>
>
>
>
>
>
>
>



>







1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326

	path = request->path;
	strcpy(log->buffer, path);
	log->method = request->method;

	/* If the requested path is a directory, redirect to index page */
	if (request->type == FILED_REQUEST_TYPE_DIRECTORY) {
#ifdef FILED_DONT_REDIRECT_DIRECTORIES
		char localpath[8192];
		int snprintf_ret;

		snprintf_ret = snprintf(localpath, sizeof(localpath), "%s/index.html", path);

		if (snprintf_ret <= 0 || snprintf_ret > (sizeof(localpath) - 1)) {
			filed_error_page(fp, date_current, 500, request->method, "path_format", log);

			return(FILED_CONNECTION_CLOSE);
		}

		path = localpath;
#else
		filed_redirect_index(fp, date_current, path, log);

		return(FILED_CONNECTION_CLOSE);
#endif
	}

	fileinfo = filed_open_file(path, &request->fileinfo, options);
	if (fileinfo == NULL) {
		filed_error_page(fp, date_current, 404, request->method, "open_failed", log);

		return(FILED_CONNECTION_CLOSE);