netguy204 / imp.el

Impatient html mode. See your changes in the browser as you type
http://www.youtube.com/watch?v=QV6XVyXjBO8
137 stars 28 forks source link

403 Forbidden when there're several same filename's files #33

Open slegetank opened 7 years ago

slegetank commented 7 years ago

I have 2 test.html in different dirs: testjs/test.html test/test.html

When I access them using impatient-mode, the server responses with " **Forbidden

The requested URL is forbidden.

error: Buffer testjs is private or doesn't exist.** ".

skeeto commented 7 years ago

This looks like an encoding issue with slashes in the buffer name. They're being treated as a delimiter in the URL rather than part of the buffer name.

avit commented 6 years ago

Also seeing a related error with spaces in the buffer name (%20).

ferfebles commented 6 years ago

Same problem when using uniquify to enforce unique buffer names, even with only one buffer, if you have this configuration:

  uniquify-buffer-name-style 'forward
  uniquify-min-dir-content 1

Because it uses at least one forward slash in the buffer name.

ferfebles commented 6 years ago

I've tried to use url-unhex-string in "defun httpd/imp/live" like this:

(defun httpd/imp/live (proc path _query req)
  "Serve up the shim that lets us watch a buffer change"
  (let* ((index (expand-file-name "index.html" imp-shim-root))
         (parts (cdr (split-string path "/")))
         (buffer-name (nth 2 parts))
         (file (httpd-clean-path (mapconcat 'identity (nthcdr 3 parts) "/")))
         (buffer (get-buffer (url-unhex-string buffer-name)))
         ;;(buffer (get-buffer buffer-name))
         (buffer-file (buffer-file-name buffer))
         (buffer-dir (and buffer-file (file-name-directory buffer-file))))

It 'solves' the 403 error, but the page keeps 'Loading content' forever.

netguy204 commented 6 years ago

I'm no longer the maintainer of impatient-mode.

Make sure you have the latest version from https://github.com/skeeto/impatient-mode (if you updated from MELPA then you do).

If you're running latest and still have the problem please pass it on to @skeeto's tracker.

On Mon, Jul 23, 2018 at 4:58 PM ferfebles notifications@github.com wrote:

Same problem when using uniquify to enforce unique buffer names, even with only one buffer if you use:

uniquify-buffer-name-style 'forward uniquify-min-dir-content 1

Because it uses at least one forward slash in the buffer name.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/netguy204/imp.el/issues/33#issuecomment-407198879, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEDogxZYCbzvREuJ8MZrw5Hq6u_xyVhks5uJjjogaJpZM4M-ojb .

titaniumbones commented 5 years ago

Does anyone have workarounds for this issue, or suggestions on how to fix? And @skeeto is this the right place stil for bug reports?

skeeto commented 5 years ago

This turned out to actually be a bug in simple-httpd, which was fixed in 1.5.0. Then impatient-mode needed to be adjusted in c9564bd, though this hasn't seen been included in a "stable" release of impatient-mode. If you're using simple-httpd 1.5.0 or later, and my master branch of impatient-mode, then this bug should no longer exist for you.

The best place to report bugs now is on my fork.

titaniumbones commented 5 years ago

Thx for the quick reply @skeeto.

Hmm. I have both installed from MELPA, and am seeing what I am pretty sure is the behaviour described in this bug. Tried switching to simple-httpd 1.5.0 from marmalade just to check; this didn't fix the issue. The slash seems to get changed to %2F in the url, but the buffer did not load (see screenshot below).

As a random hack, I tried modifying the way httpd/imp/live sets the value of buffer-name:

         (buffer-name (if  (> (length parts) 3)
                          (concat (nth 2 parts) "/" (nth 3 parts))
                                  (nth 2 parts)))

This seems to work some of the time, however, it breaks the loading of local css files. I end up with a URL like this for my index.html file: http://localhost:8888/imp/live/HabermasCode%2Findex.html/, and I get a 500 error when trying to load './style.css':

<!DOCTYPE html>
<html><head>
<title>500 Internal Error</title>
</head><body>
<h1>500 Internal Error</h1>
<p>Internal error when handling this request.</p>
<pre>error: (file-error Opening input file Not a directory /home/matt/src/HabermasCode/index.html/style.css)</pre>
</body></html>

I can't claim to know what's going on here, but if you have suggestions on how to keep trying to track down the bug please let me know. I rely on impatient-mode a lot (thank you!) but am in a situation where I have a whole lot of "index.html' and "style.css" files up at once when I'm marking student work; in this case it becomes quite difficult to use.

Also please let me know if you'd like me to move this bug to your repo. I htink issues are not enabled on https://github.com/skeeto/impatient-mode but I could addo ne one emacs-web-server.

Thanks! screenshot from 2019-01-17 20-19-28

titaniumbones commented 5 years ago

I odn't relly quite understand what's going on but it feels to me that imp-related-files isn't being constructed right. it seems like an additional index.html/ is being added onto the file paths for related resources. Not sure hwere that's happening or why :-/

Compro-Prasad commented 5 years ago

Isn't it better to archive this repo?