Check-in [cb54ba2b24]
Overview
Comment:Added support for serving out a /index.html if / is requested.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:cb54ba2b24cb88b9c10b9befe040f16b18debade
User & Date: rkeene on 2014-02-08 05:27:02
Other Links: manifest | tags
Context
2014-02-08
05:33
Updated to send correct mime type for served index.html page check-in: d78a7b98bf user: rkeene tags: trunk
05:27
Added support for serving out a /index.html if / is requested. check-in: cb54ba2b24 user: rkeene tags: trunk
03:55
Added README check-in: ab9592633a user: rkeene tags: trunk
Changes

Modified filed.c from [5e70bdaf5f] to [a1c7c3882e].

   371    371   
   372    372   	return(FILED_DEFAULT_TYPE);
   373    373   }
   374    374   
   375    375   /* Open a file and return file information */
   376    376   static struct filed_fileinfo *filed_open_file(const char *path, struct filed_fileinfo *buffer) {
   377    377   	struct filed_fileinfo *cache;
          378  +	const char *open_path;
   378    379   	unsigned int cache_idx;
   379    380   	off_t len;
   380    381   	int fd;
   381    382   
   382    383   	cache_idx = filed_hash((const unsigned char *) path, filed_fileinfo_fdcache_size);
   383    384   
   384    385   	cache = &filed_fileinfo_fdcache[cache_idx];
................................................................................
   388    389   	pthread_mutex_lock(&cache->mutex);
   389    390   
   390    391   	filed_log_msg_debug("Completed locking mutex for idx: %lu", (unsigned long) cache_idx);
   391    392   
   392    393   	if (strcmp(path, cache->path) != 0) {
   393    394   		filed_log_msg_debug("Cache miss for idx: %lu: OLD \"%s\", NEW \"%s\"", (unsigned long) cache_idx, cache->path, path);
   394    395   
   395         -		fd = open(path, O_RDONLY | O_LARGEFILE);
          396  +		if (path[0] == '\0' || (path[0] == '/' && path[1] == '\0')) {
          397  +			open_path = "/index.html";
          398  +		} else {
          399  +			open_path = path;
          400  +		}
          401  +
          402  +		fd = open(open_path, O_RDONLY | O_LARGEFILE);
   396    403   		if (fd < 0) {
   397    404   			pthread_mutex_unlock(&cache->mutex);
   398    405   
   399    406   			return(NULL);
   400    407   		}
   401    408   
   402    409   		free(cache->path);
................................................................................
   555    562   	fd = fd;
   556    563   }
   557    564   
   558    565   /* Return an error page */
   559    566   static void filed_error_page(FILE *fp, const char *date_current, int error_number) {
   560    567   	char *error_string = "<html><head><title>ERROR</title></head><body>Unable to process request</body></html>";
   561    568   
   562         -	fprintf(fp, "HTTP/1.1 %i OK\r\nDate: %s\r\nServer: filed\r\nLast-Modified: %s\r\nContent-Length: %llu\r\nContent-Type: %s\r\nConnection: close\r\n\r\n%s",
          569  +	fprintf(fp, "HTTP/1.1 %i Not OK\r\nDate: %s\r\nServer: filed\r\nLast-Modified: %s\r\nContent-Length: %llu\r\nContent-Type: %s\r\nConnection: close\r\n\r\n%s",
   563    570   		error_number,
   564    571   		date_current,
   565    572   		date_current,
   566    573   		(unsigned long long) strlen(error_string),
   567    574   		"text/html",
   568    575   		error_string
   569    576   	);