From a2366085546356481fc3f7cd0ea75f9d261d4fe3 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sun, 29 Jan 2006 14:27:14 +0100 Subject: [PATCH] Do not set the content type for FSP files Simplify commit 8d4f44f2f16d51e147df1dde7355d5da85a41115, in particular detecting MIME types for files. It is more consistent to do it the way it was already done by the session/download code. Instead, write a NUL byte to stderr when getting FSP files and only set cache->content_type when the header string is non-empty. Additionally it also moves close(stderr) after the fsp_error() in the file handling part of do_fsp() so the error message is shown with the correct type. --- src/mime/mime.c | 6 ----- src/mime/mime.h | 3 --- src/protocol/fsp/fsp.c | 50 ++++++++++++++---------------------------- 3 files changed, 17 insertions(+), 42 deletions(-) diff --git a/src/mime/mime.c b/src/mime/mime.c index bbeca78b3..373729110 100644 --- a/src/mime/mime.c +++ b/src/mime/mime.c @@ -224,12 +224,6 @@ get_cache_header_content_type(struct cache_entry *cached) return NULL; } -unsigned char * -get_default_content_type(void) -{ - return get_default_mime_type(); -} - unsigned char * get_content_type(struct cache_entry *cached) { diff --git a/src/mime/mime.h b/src/mime/mime.h index 8584ee4f1..779ed3b82 100644 --- a/src/mime/mime.h +++ b/src/mime/mime.h @@ -20,9 +20,6 @@ extern struct module mime_module; * scanning the uri for extensions. */ unsigned char *get_content_type(struct cache_entry *cached); -/* Default mime type */ -unsigned char *get_default_content_type(void); - /* Guess content type by looking at configurations of the given @extension */ unsigned char *get_extension_content_type(unsigned char *extension); diff --git a/src/protocol/fsp/fsp.c b/src/protocol/fsp/fsp.c index 4696657ce..b8f0f3892 100644 --- a/src/protocol/fsp/fsp.c +++ b/src/protocol/fsp/fsp.c @@ -27,7 +27,6 @@ #include "intl/gettext/libintl.h" #include "main/module.h" #include "main/select.h" -#include "mime/mime.h" #include "network/connection.h" #include "network/socket.h" #include "osdep/osdep.h" @@ -180,31 +179,6 @@ end: exit(0); } -static unsigned char * -get_content_type_uri(struct uri *uri) -{ - unsigned char *extension = get_extension_from_uri(uri); - - if (extension) { - unsigned char *ctype; - /* XXX: A little hack for making extension handling case - * insensitive. We could probably do it better by making - * guess_encoding() case independent the real problem however - * is with default (via option system) and mimetypes resolving - * doing that option and hash lookup will not be easy to - * convert. --jonas */ - convert_to_lowercase(extension, strlen(extension)); - - ctype = get_extension_content_type(extension); - if (ctype && *ctype) { - return ctype; - } - } - - return get_default_content_type(); - -} - #define READ_SIZE 4096 static void @@ -229,13 +203,18 @@ do_fsp(struct connection *conn) FSP_FILE *file = fsp_fopen(ses, data, "r"); int r; - fprintf(stderr, "%s", get_content_type_uri(uri)); - fclose(stderr); if (!file) fsp_error("fsp_fopen error."); + /* Use the default way to find the MIME type, so write an + * 'empty' name, since something needs to be written in order + * to avoid socket errors. */ + fprintf(stderr, "%c", '\0'); + fclose(stderr); + while ((r = fsp_fread(buf, 1, READ_SIZE, file)) > 0) fwrite(buf, 1, r, stdout); + fsp_fclose(file); fsp_close_session(ses); exit(0); @@ -273,7 +252,6 @@ fsp_got_data(struct socket *socket, struct read_buffer *rb) static void fsp_got_header(struct socket *socket, struct read_buffer *rb) { - int len = rb->length; struct connection *conn = socket->conn; struct read_buffer *buf; @@ -285,10 +263,16 @@ fsp_got_header(struct socket *socket, struct read_buffer *rb) return; } socket->state = SOCKET_END_ONCLOSE; - if (len <= 0) goto end; - rb->data[len] = '\0'; - mem_free_set(&conn->cached->content_type, stracpy(rb->data)); -end: + + if (rb->length > 0) { + unsigned char *ctype = memacpy(rb->data, rb->length); + + if (ctype && *ctype) + mem_free_set(&conn->cached->content_type, ctype); + else + mem_free_if(ctype); + } + buf = alloc_read_buffer(conn->data_socket); if (!buf) { close(socket->fd);