Moodle

Support If-Modified-Since in filelib.php

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: 1.9.4
  • Fix Version/s: DEV backlog
  • Component/s: Files API, Libraries
  • Labels:
    None
  • Difficulty:
    Easy
  • Affected Branches:
    MOODLE_19_STABLE

Description

Please note my comment http://tracker.moodle.org/browse/MDL-11434?focusedCommentId=66182&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#action_66182 on this http://tracker.moodle.org/browse/MDL-11434 issue.

Quote:
I'd like to bring the issue about If-Modified-Since/304 Support up again because i ran into trouble recently trying to download some courses with httrack (website copier).
I'd like to run httrack like this:

$ httrack -A100000 -s0 -%s -%v2 https://moodle.fhnw.ch/user/view.php?id=2593 -* +moodle.fhnw.ch/user/view.php?id=2593* +moodle.fhnw.ch/course/view.php?id=978 +moodle.fhnw.ch/course/view.php?id=850 +moodle.fhnw.ch/course/view.php?id=967 +moodle.fhnw.ch/course/view.php?id=984 +moodle.fhnw.ch/mod/resource/* +moodle.fhnw.ch/file.php/* +.jpg +.gif +*.png

then when tachers upload new files, i'd just run

$ httrack --update

which downloads (in theory) all changed and added content from the site. The problem is that httrack uses If-Modified-Since to find out if files have changed and filelib.php still doesnt handle this. So it sends the File again and httrack downloads it although the file has not changed.

It would be great if Chris Fryer's patch could be somehow pulled into the mainline moodle. I dont quiet understand Petr Skoda's argumentation against it. "[...] if we allow caching [...]": I think enabling a proper If-Modified-Since support wouldn't "allow caching" any more then is already allowed. You cannot enforce anyway, if you allow retrieval. And the normal response headers are not changed at all. If a file got updated, it will be downloaded as before. There is no reason the browser wouldn't request changed files any more!

So please make moodle support If-Modified-Since/304 to save bandwidth.

Greets

Patrick

Activity

Hide
Petr Škoda (skodak) added a comment -

if-modified-since will be probably supported in 2.0 in file.php, pluginfile.php etc, but website copiers definitely will not be and can not be supported, the reason is we are abusing GET requests for database modifications, so in fact we are actively prohibiting use of these tools

Show
Petr Škoda (skodak) added a comment - if-modified-since will be probably supported in 2.0 in file.php, pluginfile.php etc, but website copiers definitely will not be and can not be supported, the reason is we are abusing GET requests for database modifications, so in fact we are actively prohibiting use of these tools
Hide
Patrick Pfeifer added a comment -

Ok, I don't have a deep understanding of the inner workings but I can't quiet understand why me retrieving a file from my course should trigger a database modification and how that might interfere with a proper response to a "if-modified-since" header. The method is still GET.... Maybe moodle records a timestamp when users are retrieving files - so why not record that anyway and send a 304 response.

Why are you "prohibiting" website copiers?

Show
Patrick Pfeifer added a comment - Ok, I don't have a deep understanding of the inner workings but I can't quiet understand why me retrieving a file from my course should trigger a database modification and how that might interfere with a proper response to a "if-modified-since" header. The method is still GET.... Maybe moodle records a timestamp when users are retrieving files - so why not record that anyway and send a 304 response. Why are you "prohibiting" website copiers?
Hide
Petr Škoda (skodak) added a comment -

As I said moodle wrongly uses GET requests instead of proper POST requests in some places, so using of web site copiers and preloaders asks for trouble - if you do that with guest account it may work, but once you try that as a real user it is a disaster.

Show
Petr Škoda (skodak) added a comment - As I said moodle wrongly uses GET requests instead of proper POST requests in some places, so using of web site copiers and preloaders asks for trouble - if you do that with guest account it may work, but once you try that as a real user it is a disaster.
Hide
Patrick Pfeifer added a comment -

I see, right. Sureley, website copier might have some problem. Especially if used in a wrong way (with default options). But I think I'm not "overdoing" it. I actually just want my scripts locally available without beeing forced to download and save each and every file with the browser. Teachers sometimes put one files per lesson/week and this adds up to a lot of files if you attend 8 courses during 18 weeks - one would defenitley want to automate the downloading - so if there was another solution I really wouldn't mind as well.

BUT: actually I'm not asking for "website copier support" here. Only for propper If-Modified-Since handling. And I still can't see a real reason for rejecting Chris Freyr's 9 lines of code that would enable it. I can't find any database modification in the code path of retrieving a file (file.php -> filelib.php:send_file -> filelib.php:readfile_chunked -> done).

So again, please, why not, it won't do no harm, add:

$gmtlastmodified = gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT';
header('Last-Modified: '. $gmtlastmodified);

if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
if (strtotime($gmtlastmodified) <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { header('HTTP/1.0 304 Not Modified'); header('Cache-control: must-revalidate'); exit (0); }
}

I might actually miss some point as well. Sorry for the noise in that case...

Show
Patrick Pfeifer added a comment - I see, right. Sureley, website copier might have some problem. Especially if used in a wrong way (with default options). But I think I'm not "overdoing" it. I actually just want my scripts locally available without beeing forced to download and save each and every file with the browser. Teachers sometimes put one files per lesson/week and this adds up to a lot of files if you attend 8 courses during 18 weeks - one would defenitley want to automate the downloading - so if there was another solution I really wouldn't mind as well. BUT: actually I'm not asking for "website copier support" here. Only for propper If-Modified-Since handling. And I still can't see a real reason for rejecting Chris Freyr's 9 lines of code that would enable it. I can't find any database modification in the code path of retrieving a file (file.php -> filelib.php:send_file -> filelib.php:readfile_chunked -> done). So again, please, why not, it won't do no harm, add: $gmtlastmodified = gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT'; header('Last-Modified: '. $gmtlastmodified); if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { if (strtotime($gmtlastmodified) <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { header('HTTP/1.0 304 Not Modified'); header('Cache-control: must-revalidate'); exit (0); } } I might actually miss some point as well. Sorry for the noise in that case...
Hide
Patrick Pfeifer added a comment -

Another $_SERVER['HTTP_IF_MODIFIED_SINCE'] handler routine is actually already since long, it seems, doing a very nice job in serving pictures in pix/smartpix.php - so why not in filelib.php as well - where is the difference?

Show
Patrick Pfeifer added a comment - Another $_SERVER['HTTP_IF_MODIFIED_SINCE'] handler routine is actually already since long, it seems, doing a very nice job in serving pictures in pix/smartpix.php - so why not in filelib.php as well - where is the difference?
Hide
Patrick Pfeifer added a comment -

So I'm using this now since quiet a long time without any problems:

httrack --update -s0 -A100000 -%s -%v2 https://moodle.fhnw.ch/user/view.php?id=2593 -* \
+moodle.fhnw.ch/user/view.php?id=2593* \
+moodle.fhnw.ch/mod/resource/* \
+moodle.fhnw.ch/file.php/* \
+.jpg +.gif +*.png \
+moodle.fhnw.ch/course/view.php?id=978 \
....

As a real user! No "desaster" at all. Maybe you'd like to check the httrack homepage and docs once to get convinced that it's quiet sophisticated: www.httrack.com - and NOT just another brute-force website copier. As I said: it's working like a charm, EXCEPT that i have to enable "update hacks" (%s) to make it work with moodle. This makes httrack not rely on the server response to the If-Modified-Since request and cut the connection as soon as it becomes very likely that the server is lying about the file modification time and trying to send us the same file again: after recieving the "Content-Length" header, if the local and remote file sizees are equal, it just drops the socket... ;/ ... which I find a bit unfriendly, but, as moodle just doesn't get it right, the only option.

Still hoping that this will get fixed once

Greets

Patrick

Show
Patrick Pfeifer added a comment - So I'm using this now since quiet a long time without any problems: httrack --update -s0 -A100000 -%s -%v2 https://moodle.fhnw.ch/user/view.php?id=2593 -* \ +moodle.fhnw.ch/user/view.php?id=2593* \ +moodle.fhnw.ch/mod/resource/* \ +moodle.fhnw.ch/file.php/* \ +.jpg +.gif +*.png \ +moodle.fhnw.ch/course/view.php?id=978 \ .... As a real user! No "desaster" at all. Maybe you'd like to check the httrack homepage and docs once to get convinced that it's quiet sophisticated: www.httrack.com - and NOT just another brute-force website copier. As I said: it's working like a charm, EXCEPT that i have to enable "update hacks" (%s) to make it work with moodle. This makes httrack not rely on the server response to the If-Modified-Since request and cut the connection as soon as it becomes very likely that the server is lying about the file modification time and trying to send us the same file again: after recieving the "Content-Length" header, if the local and remote file sizees are equal, it just drops the socket... ;/ ... which I find a bit unfriendly, but, as moodle just doesn't get it right, the only option. Still hoping that this will get fixed once Greets Patrick
Hide
Petr Škoda (skodak) added a comment -

1/ sorry, there is not going to be any support for mass downloading of moodle pages
2/ support $_SERVER['HTTP_IF_MODIFIED_SINCE'] will not be added to stable branch
3/ $_SERVER['HTTP_IF_MODIFIED_SINCE'] will be probably added into 2.0

Show
Petr Škoda (skodak) added a comment - 1/ sorry, there is not going to be any support for mass downloading of moodle pages 2/ support $_SERVER['HTTP_IF_MODIFIED_SINCE'] will not be added to stable branch 3/ $_SERVER['HTTP_IF_MODIFIED_SINCE'] will be probably added into 2.0
Hide
Patrick Pfeifer added a comment -

Ok, well... although I really can't figure out, what you like so much about this BUG, I'm glad to learn that my real issue of liking to automate the download of moodle pages and resources for local (mobile/offline) use is, as it seems, already being professionally worked on by the "Offline Moodle" project. See a very nice description here: http://moodle.org/mod/forum/discuss.php?d=71136 Here is their project page: http://hawk.aos.ecu.edu/moodle2/course/view.php?id=22 But it looks like the Project has some way to go stil...

Show
Patrick Pfeifer added a comment - Ok, well... although I really can't figure out, what you like so much about this BUG, I'm glad to learn that my real issue of liking to automate the download of moodle pages and resources for local (mobile/offline) use is, as it seems, already being professionally worked on by the "Offline Moodle" project. See a very nice description here: http://moodle.org/mod/forum/discuss.php?d=71136 Here is their project page: http://hawk.aos.ecu.edu/moodle2/course/view.php?id=22 But it looks like the Project has some way to go stil...
Hide
Petr Škoda (skodak) added a comment -

There is another project proposed for GSOC which involves Goodle Gears

Show
Petr Škoda (skodak) added a comment - There is another project proposed for GSOC which involves Goodle Gears
Hide
Martin Dougiamas added a comment -

Um, so is HTTP_IF_MODIFIED_SINCE implemented in Moodle 2.0 now?

Show
Martin Dougiamas added a comment - Um, so is HTTP_IF_MODIFIED_SINCE implemented in Moodle 2.0 now?
Hide
Petr Škoda (skodak) added a comment -

not yet

Show
Petr Škoda (skodak) added a comment - not yet
Hide
Michael de Raadt added a comment -

Thanks for reporting this issue.

We have detected that this issue has been inactive for over a year has been recorded as affecting versions that are no longer supported.

If you believe that this issue is still relevant to current versions (2.1 and beyond), please comment on the issue. Issues left inactive for a further month will be closed.

Michael d;

lqjjLKA0p6

Show
Michael de Raadt added a comment - Thanks for reporting this issue. We have detected that this issue has been inactive for over a year has been recorded as affecting versions that are no longer supported. If you believe that this issue is still relevant to current versions (2.1 and beyond), please comment on the issue. Issues left inactive for a further month will be closed. Michael d; lqjjLKA0p6
Hide
Patrick Pfeifer added a comment - - edited

The issue is still unresolved in the latest version.

Show
Patrick Pfeifer added a comment - - edited The issue is still unresolved in the latest version.

People

Dates

  • Created:
    Updated: