GithubHelp home page GithubHelp logo

elli-lib / elli_fileserve Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chrisavl/elli_fileserve

0.0 0.0 4.0 203 KB

Development has moved to elli_static.

Home Page: https://github.com/elli-lib/elli_static

Erlang 100.00%

elli_fileserve's People

Contributors

andreashasse avatar arobson avatar chrisavl avatar kaos avatar yurrriq avatar

Watchers

 avatar  avatar  avatar  avatar

elli_fileserve's Issues

if-modified-since header support

If the header if-modified-since exists in the request and the file has not been modified since that time a 304 should be returned.

Double content length

I get double Content-Length headers when using the master branch. E.g.:

$ http get localhost:8000/js/app.js

http: error: InvalidHeader: Content-Length contained multiple unmatching values(307288, 0)

Tracing shows this result:

GET /js/app.js HTTP/1.1
Host: localhost:8000
User-Agent: HTTPie/0.9.8
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive

HTTP/1.1 206 Partial Content
Connection: Keep-Alive
Content-Length: 307288
Content-Type: application/javascript; charset=utf-8
Content-Length: 0
Content-Range: bytes 0--1/307288

...(contents of the JS-file)...

If I debug using the request_complete event as follows:

handle_event(request_complete, [_Req, _Code, _Headers, _Body, {_Timings, _Sizes}], _Args) ->
    io:format("~p ~p ~p ~p~n", [_Code, _Headers, _Body, _Sizes]),
    ok;

I get the following output:

200 [{<<"Connection">>,<<"Keep-Alive">>},
     {"Content-Length",307288},
     {"Content-Type",
      [97,112,112,108,105,99,97,116,105,111,110,47,106,97,118,97,115,99,114,
       105,112,116,59,32,99,104,97,114,115,101,116,61|<<"utf-8">>]}] <<>> [{resp_headers,
                                                                            186},
                                                                           {file,
                                                                            307288}]

Here I only see the headers set by elli_fileserve but somewhere a Content-Length: 0 header is added (and the response transformed to a 206 Partial Content as well.

This is the configuration and supervisor:

-module(myapp_sup).

-behaviour(supervisor).

% API
-export([start_link/0]).

% Supervisor callbacks
-export([init/1]).

-define(NAME, ?MODULE).

%--- API ----------------------------------------------------------------------

start_link() ->
    supervisor:start_link({local, ?NAME}, ?MODULE, []).

%--- Supervisor callbacks -----------------------------------------------------

init([]) ->
    ElliOpts = [
        {callback, elli_middleware},
        {callback_args, [{mods, [
            {elli_fileserve, [
                {path, static("js")},
                {prefix, <<"/js">>},
                {charset, <<"utf-8">>},
                {default, <<"index.html">>}
            ]}
        ]}]},
        {port, 8000}
    ],
    Elli = {
        myapp_http,
        {elli, start_link, [ElliOpts]},
        permanent,
        5000,
        worker,
        [elli]
    },
    {ok, {{one_for_all, 0, 1}, [Elli]}}.


static(Path) ->
    iolist_to_binary(filename:join([code:priv_dir(myapp), "static", Path])).

Not sure if this is a bug in elli_fileserve or Elli itself.

Custom 404.html

It should be possible to define the response for a 404 to be other than simply File Not Found, one might want to return a 404 html page for example.

Add LICENSE

Reach out to @chrisavl, add LICENSE and the appropriate Hex metadata in src/elli_fileserve.app.src.

etag support

Files served should send an etag header with them. And if the etag sent in the request is the same as the current file a 304 should be returned.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.