Dolda2000 GitWeb
/
ashd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
85059e8
)
Try to add default charset for text/* types in sendfile.
author
Fredrik Tolf
<fredrik@dolda2000.com>
Sun, 29 Aug 2010 14:40:33 +0000
(16:40 +0200)
committer
Fredrik Tolf
<fredrik@dolda2000.com>
Sun, 29 Aug 2010 14:40:33 +0000
(16:40 +0200)
src/sendfile.c
patch
|
blob
|
blame
|
history
diff --git
a/src/sendfile.c
b/src/sendfile.c
index
ce422e2
..
fbf5f1b
100644
(file)
--- a/
src/sendfile.c
+++ b/
src/sendfile.c
@@
-26,6
+26,8
@@
#include <stdint.h>
#include <time.h>
#include <magic.h>
#include <stdint.h>
#include <time.h>
#include <magic.h>
+#include <locale.h>
+#include <langinfo.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
@@
-108,6
+110,15
@@
static const char *getmimetype(char *file, struct stat *sb)
return("application/octet-stream");
}
return("application/octet-stream");
}
+/* XXX: This could be made far better and check for other attributes
+ * and stuff, but not now. */
+static const char *ckctype(const char *ctype)
+{
+ if(!strncmp(ctype, "text/", 5) && (strchr(ctype, ';') == NULL))
+ return(sprintf2("%s; charset=%s", ctype, nl_langinfo(CODESET)));
+ return(ctype);
+}
+
static void checkcache(char *file, struct stat *sb)
{
char *hdr;
static void checkcache(char *file, struct stat *sb)
{
char *hdr;
@@
-136,6
+147,7
@@
int main(int argc, char **argv)
int fd;
const char *contype;
int fd;
const char *contype;
+ setlocale(LC_ALL, "");
contype = NULL;
while((c = getopt(argc, argv, "c:")) >= 0) {
switch(c) {
contype = NULL;
while((c = getopt(argc, argv, "c:")) >= 0) {
switch(c) {
@@
-167,6
+179,7
@@
int main(int argc, char **argv)
}
if(contype == NULL)
contype = getmimetype(file, &sb);
}
if(contype == NULL)
contype = getmimetype(file, &sb);
+ contype = ckctype(contype);
checkcache(file, &sb);
checkcache(file, &sb);