Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Make use resource_file_readonly use sendfile when available #342

Closed
wants to merge 7 commits into from

4 participants

@hce
hce commented

This also fixes the Issue #319 on systems where sendfile is available in erlang (No matter if sendfile is supported by the underlying OS). The issue will continue to exist on erlang systems that do not have the file:sendfile function available.

Requires the webzmachine sendfile patch to work.

Hans-Christi... added some commits
Hans-Christian Espérer Added an option to allow the site owner to moderate/review comments 254cc51
Hans-Christian Espérer Log the user agent and IP address for each comment 9805670
Hans-Christian Espérer Display a confirmation dialog first when deleting comments 3eb87ee
Hans-Christian Espérer Merge branch 'master' of github.com:hce/zotonic 5119882
Hans-Christian Espérer Merge branch 'master' of https://github.com/zotonic/zotonic e26f006
Hans-Christian Espérer Add support for sendfile.
This patch needs the updated version of webzmachine to work. It is made backwards compatible by checking each time if file:sendfile exists.
8326b27
Hans-Christian Espérer Properly return filesize for static files in all sendfile cases c6c9b1f
@mworrell

The user_agent value should be escaped before echo-ing it in the html.
It can contain any kind of data (including quotes and extra html).

@mworrell

I think you need to add your name & copyright here (and as well above the license below).

@mworrell
Owner

I see that we have already merged the comment changes.
I fixed the escape issue in 3834a3c

@arjan
Owner

It would be nice to have this functionality, but this pull request is a bit cluttered with other commits. Can you create a new topic branch on the current master and rebase the relevant commits from this pull request there?

@hce

I'm a bit busy ATM, but will do so as soon as possible!

@mworrell
Owner

I stumbled over this when we were checking an nginx problem:

http://www.vanpattenmedia.com/2012/a-tale-of-stale-content/

Basically sendfile and virtualisation are not friends.
So the use of sendfile needs to be configurable.

@arjan
Owner

agreed.
But it's good to have anyway. Lessens the load on the vm.

@kaos
Owner

What has happened with this pull request... ?
All commits point to the zotonic/zotonic repo, none to hce/zotonic.
That's OK for those commits that actually are merged in I suppose, but none of the sendfile changes are...
And btw, how did the last commit (c6c9b1f) "Properly return filesize..." end up in the pull request? It's not in hce's sendfile branch.
I've spent an hour trying to figure this out, to no avail. It seems that there are commits dangling on the github server not reachable by any refs I know about.

@arjan
Owner

This is very weird indeed. The commits are not in the main zotonic repo, I just checked.

@hce if you still want this included, can you make a new topic branch and create a new pull request?

@arjan arjan closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 3, 2012
  1. Added an option to allow the site owner to moderate/review comments

    Hans-Christian Espérer authored
  2. Log the user agent and IP address for each comment

    Hans-Christian Espérer authored
  3. Display a confirmation dialog first when deleting comments

    Hans-Christian Espérer authored
Commits on Jun 5, 2012
  1. Merge branch 'master' of github.com:hce/zotonic

    Hans-Christian Espérer authored
  2. Merge branch 'master' of https://github.com/zotonic/zotonic

    Hans-Christian Espérer authored
  3. Add support for sendfile.

    Hans-Christian Espérer authored
    This patch needs the updated version of webzmachine to work. It is made backwards compatible by checking each time if file:sendfile exists.
Commits on Jun 8, 2012
  1. Properly return filesize for static files in all sendfile cases

    Hans-Christian Espérer authored
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 7 deletions.
  1. +23 −7 modules/mod_base/resources/resource_file_readonly.erl
View
30 modules/mod_base/resources/resource_file_readonly.erl
@@ -173,16 +173,32 @@ provide_content(ReqData, Context) ->
true ->
{ok, Device} = file:open(z_context:get(fullpath, Context), [read,raw,binary]),
FileSize = z_context:get(file_size, Context),
- { {stream, read_chunk(0, FileSize, Device)},
+ Body = case lists:member({sendfile, 5}, file:module_info(functions)) of
+ true ->
+ {sendfile, Device};
+ false ->
+ {stream, read_chunk(0, FileSize, Device)}
+ end,
+ { Body,
wrq:set_resp_header("Content-Length", integer_to_list(FileSize), RD1),
z_context:set(use_cache, false, Context) };
_ ->
- {ok, Data} = file:read_file(z_context:get(fullpath, Context)),
- Body = case z_context:get(encode_data, Context, false) of
- true -> encode_data(Data);
- false -> Data
- end,
- {Body, RD1, z_context:set(body, Body, Context)}
+ case lists:member({sendfile, 5}, file:module_info(functions)) of
+ true ->
+ {ok, Device} = file:open(z_context:get(fullpath, Context), [read,raw,binary]),
+ Body = {sendfile, Device},
+ FileSize = filelib:file_size(z_context:get(fullpath, Context)),
+ {Body,
+ wrq:set_resp_header("Content-Length", integer_to_list(FileSize), RD1),
+ z_context:set(use_cache, false, Context)};
+ false ->
+ {ok, Data} = file:read_file(z_context:get(fullpath, Context)),
+ Body = case z_context:get(encode_data, Context, false) of
+ true -> encode_data(Data);
+ false -> Data
+ end,
+ {Body, RD1, z_context:set(use_cache, false, Context)}
+ end
end;
Body ->
{Body, RD1, Context}
Something went wrong with that request. Please try again.