unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: sirgazil <sirgazil@zoho.com>, David Thompson <dthompson2@worcester.edu>
Cc: Guile User <guile-user@gnu.org>
Subject: Re: Haunt serves some resources mistakenly as text/plain
Date: Thu, 21 Dec 2017 14:25:19 +0100	[thread overview]
Message-ID: <87efno6wn4.fsf@gnu.org> (raw)
In-Reply-To: <7618df95-aba7-2e5b-6bb2-e6d6de427907@zoho.com> (sirgazil@zoho.com's message of "Sat, 16 Dec 2017 15:36:21 -0500")

[-- 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


  reply	other threads:[~2017-12-21 13:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-16 20:36 Haunt serves some resources mistakenly as text/plain sirgazil
2017-12-21 13:25 ` Ludovic Courtès [this message]
2017-12-21 13:53   ` Thompson, David

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87efno6wn4.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=dthompson2@worcester.edu \
    --cc=guile-user@gnu.org \
    --cc=sirgazil@zoho.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).