mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
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.
This commit is contained in:
parent
0cb0d0aaae
commit
a236608554
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user