* Re: Haunt serves some resources mistakenly as text/plain
2017-12-16 20:36 Haunt serves some resources mistakenly as text/plain sirgazil
@ 2017-12-21 13:25 ` Ludovic Courtès
2017-12-21 13:53 ` Thompson, David
0 siblings, 1 reply; 3+ messages in thread
From: Ludovic Courtès @ 2017-12-21 13:25 UTC (permalink / raw)
To: sirgazil, David Thompson; +Cc: Guile User
[-- Attachment #1: Type: text/plain, Size: 727 bytes --]
Hi there!
sirgazil <sirgazil@zoho.com> skribis:
> When you create resources in Haunt whose URL paths contain dots beside
> the dot before a file extension, it seems Haunt's web server will
> always serve them as "text/plain". So, in the case of HTML pages, for
> example, when you visit them in the Web browser, the browser won't
> render the HTML, but display the HTML markup instead (within a PRE
> element in a browser-generated HTML page).
I noticed that too.
The first patch attached fixes it (previously (file-extension
"hello.es.html") would return "es.html", which has no associated MIME
type). The second one is nice to have.
Dave, could you consider applying them? :-)
Cheers,
Ludo’.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-serve-Fix-file-extension-so-that-the-right-MIME-type.patch --]
[-- Type: text/x-patch, Size: 1464 bytes --]
From 2526692ad80b78538cd37043bf20db2407b7a150 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <ludo@gnu.org>
Date: Thu, 21 Dec 2017 14:16:14 +0100
Subject: [PATCH 1/2] serve: Fix 'file-extension' so that the right MIME type
is chosen.
Reported by sirgazil at
<https://lists.gnu.org/archive/html/guile-user/2017-12/msg00070.html>.
* haunt/serve/mime-types.scm (%file-ext-regexp): Remove.
(file-extension): Rewrite using 'string-rindex'.
---
haunt/serve/mime-types.scm | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/haunt/serve/mime-types.scm b/haunt/serve/mime-types.scm
index 4c9c0f1..c625dd5 100644
--- a/haunt/serve/mime-types.scm
+++ b/haunt/serve/mime-types.scm
@@ -539,16 +539,10 @@
("vrml" . x-world/x-vrml)
("wrl" . x-world/x-vrml))))
-(define %file-ext-regexp
- (make-regexp "(\\.(.*)|[~%])$"))
-
-(define (file-extension file-name)
- "Return the file extension for FILE-NAME, or #f if one is not
-found."
- (and=> (regexp-exec %file-ext-regexp file-name)
- (lambda (match)
- (or (match:substring match 2)
- (match:substring match 1)))))
+(define (file-extension file)
+ "Return the extension of FILE or #f if there is none."
+ (let ((dot (string-rindex file #\.)))
+ (and dot (substring file (+ 1 dot) (string-length file)))))
(define (mime-type file-name)
"Guess the MIME type for FILE-NAME based upon its file extension."
--
2.15.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-guix-Switch-to-Guile-2.2.patch --]
[-- Type: text/x-patch, Size: 685 bytes --]
From 9c3dec45907dc731e655201e19da2a6fb1b72680 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <ludo@gnu.org>
Date: Thu, 21 Dec 2017 14:19:50 +0100
Subject: [PATCH 2/2] guix: Switch to Guile 2.2.
* guix.scm <inputs>: Switch to GUILE-2.2.
---
guix.scm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/guix.scm b/guix.scm
index d9f8f44..32b548a 100644
--- a/guix.scm
+++ b/guix.scm
@@ -61,7 +61,7 @@
("pkg-config" ,pkg-config)
("texinfo" ,texinfo)))
(inputs
- `(("guile" ,guile-2.0)))
+ `(("guile" ,guile-2.2)))
(propagated-inputs
`(("guile-commonmark" ,guile-commonmark)
("guile-reader" ,guile-reader)))
--
2.15.1
^ permalink raw reply related [flat|nested] 3+ messages in thread