* Haunt serves some resources mistakenly as text/plain
@ 2017-12-16 20:36 sirgazil
2017-12-21 13:25 ` Ludovic Courtès
0 siblings, 1 reply; 3+ messages in thread
From: sirgazil @ 2017-12-16 20:36 UTC (permalink / raw)
To: guile-user
Hi Dave, Guile,
I found this bug about a year ago, but I don't think I can fix it
myself, so I'm posting this here hoping that David or Haunt users can
check if they can reproduce the error, and maybe patch Haunt.
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).
Steps to reproduce:
1. Download a test directory
(https://bitbucket.org/sirgazil/dnd/downloads/haunt-dots-site.tar.gz).
It contains two test pages:
haunt-dots-site
├── hello.es.html
└── hello.html
2. Open a REPL and serve the contents of that directory:
$ guile
scheme@(guile-user)> (use-modules (haunt serve web-server))
scheme@(guile-user)> (serve "/path/to/haunt-dots-site")
You shouldn't see any output here, but the server is running.
3. Visit http://localhost:8080/hello.html. You should see a page
displaying the text "Hello Haunt!".
4. Visit http://localhost:8080/hello.es.html. You see the HTML code
instead of the expected message "¡Hola Haunt!".
--
https://sirgazil.bitbucket.io/
^ permalink raw reply [flat|nested] 3+ messages in thread
* 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
* Re: Haunt serves some resources mistakenly as text/plain
2017-12-21 13:25 ` Ludovic Courtès
@ 2017-12-21 13:53 ` Thompson, David
0 siblings, 0 replies; 3+ messages in thread
From: Thompson, David @ 2017-12-21 13:53 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: Guile User
Hey Ludo and sirgazil,
On Thu, Dec 21, 2017 at 8:25 AM, Ludovic Courtès <ludo@gnu.org> wrote:
> 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? :-)
Thanks for finding and fixing this bug! Both patches applied!
- Dave
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-12-21 13:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).