Coder Social home page Coder Social logo

elli's People

Contributors

andreashasse avatar chrisavl avatar eproxus avatar hukl avatar hungryblank avatar istr avatar kaos avatar knutin avatar mkrogemann avatar mmzeeman avatar phuesler avatar sthadka avatar tsloughter avatar zambal avatar zampino avatar zazaian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

elli's Issues

elli_http:chunk_loop/1 cannot match message {tcp_closed, Socket} in its receive block

Around line https://github.com/knutin/elli/blob/master/src/elli_http.erl#L258
we have

...
chunk_loop(Socket) ->
    receive
        {tcp_closed, Socket} ->
            {error, client_closed};
....

Where Socket is a tuple of type

-type socket() :: {plain, inet:socket()} | {ssl, ssl:sslsocket()}.

but the message being received is of the form { tcp_closed, X:socket()}.

The fix is easy, I can provide a pr.

I found this while sketching an Elixir Plug Adapter for Elli, does anyone knows if an "official" adapter
is under development.

Cheers,
Andrea

Empty project compilation on Linux precise32

Hi,

I just begin to learn Erlang and I would like to work on a web API. After some searches I decided to use Elli but I am stucked at the first step. ๐Ÿ˜ฌ

mkdir <projectname>
cd <projectname>
rebar create-app appid=<projectname>
# rebar config file creation
rebar get-deps
rebar compile
# BIM! Failure

I work on a vagrant VM (Linux precise32) to not pollute my laptop and I have the following error:

 rebar compile
==> Entering directory `~/deps/elli'
==> elli (compile)
src/elli_handler.erl:4: syntax error before: '::'
src/elli_handler.erl:6: syntax error before: '::'

Although I wanted to keep my laptop clean, I tried to build the project on OSX and it worked fine.

Ubuntu version of Erlang: R14B04
OSX version of Erlang: R16B02

richer (?) handle_event()

i wonder if handle_event() could be used as emergency handler, meaning if one returns outta there {403, [], <<>>} it should result in 403 error sent to the client. returning none could mean we've coped with event and want nothing, stop to drop the process etc.
what do you think?

elli_middleware: how to pass info

Hi!

I'd like to make a cookie session middleware which extracts info from request headers in preprocess/2, allows it to be used in handle/2 and honors changes to session in postprocess/3.

Wonder if there is some recommended way to pass info from handle/2 to postprocess/3 other than using a special response body kinda {with_options, Res, Options} and analyse this case in postprocess/3?
Also, how do we attach additional info to Req in preprocess/2?

TIA,
--Vladimir

close chunk on empty data..!?

Consider this example:

elli_request:send_chunk(Ref, [Data || Data <- generator(), filter(Data)])

if all the data gets filtered out, the chunk gets closed.

I propose to fix elli_http:chunk_loop/1 to simply ignore empty chunks, and only close the chunk on a 'chunk_close' request.

... I realized most of this while writing this issue.. so I'll just go ahead and post a pull request for this, for your consideration :)

Better 4xx, 5xx responses

Elli could include a body in the 4xx and 5xx responses which contains a unique reference to that request. This reference could also be included in any log messages, for later correlation.

URL Hash not included in Request Data Structure

The URL hash fragment is not included in the request structure.

e.g.

curl localhost:3000/hello?a=b#c

When displaying the Request using elli_request:to_proplist(Req) on the request_complete event handler:

[{method,'GET'},
      {path,[<<"hello">>]},
      {args,[{<<"a">>,<<"b">>}]},
      {raw_path,<<"/hello?a=b">>},
      {version,{1,1}},
      {headers,[{<<"Accept">>,<<"*/*">>},
                {<<"Host">>,<<"localhost:3000">>},
                {<<"User-Agent">>,<<"curl/7.38.0">>}]},
      {body,<<>>},
      {pid,<0.37.0>},
      {socket,{plain,#Port<0.824>}},
      {callback,{elli_hello_http,undefined}}

Document events

Events like elli_startup, request_complete, client_closed should be documented.

when run "make utest", meet crash.

root@iZ11vpvnl7yZ:~/elli# make eunit
./rebar eunit skip_deps=true
==> elli (eunit)
Compiled src/elli_handler.erl
Compiled test/elli_http_tests.erl
test/elli_ssl_tests.erl:58: Warning: function body/1 is unused
test/elli_ssl_tests.erl:61: Warning: function headers/1 is unused
Compiled test/elli_ssl_tests.erl
Compiled test/elli_handover_tests.erl
Compiled test/elli_middleware_tests.erl
Compiled test/elli_tests.erl
Compiled src/elli.erl
Compiled src/elli_test.erl
Compiled src/elli_tcp.erl
Compiled src/elli_middleware_compress.erl
Compiled src/elli_util.erl
Compiled src/elli_example_callback_handover.erl
Compiled src/elli_middleware.erl
Compiled src/elli_example_middleware.erl
Compiled src/elli_example_callback.erl
Compiled src/elli_request.erl
Compiled src/elli_http.erl
elli_tests: register_test...*skipped*
undefined
*unexpected termination of test process*
::{{badmatch,{error,eaddrinuse}},
   [{elli,init,1,[{file,"src/elli.erl"},{line,111}]},
    {gen_server,init_it,6,[{file,"gen_server.erl"},{line,304}]},
    {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]}

=======================================================
  Failed: 0.  Skipped: 0.  Passed: 54.
One or more tests were cancelled.
Cover analysis: /root/elli/.eunit/index.html

=INFO REPORT==== 25-Oct-2016::12:30:37 ===
    application: inets
    exited: stopped
    type: temporary
ERROR: One or more eunit tests failed.
ERROR: eunit failed while processing /root/elli: rebar_abort
make: *** [eunit] Error 1
root@iZ11vpvnl7yZ:~/elli# 

So i want know how to run unittest for elli?

Error reporting, in console

I am not getting any exception/error reporting in my console when using the following startup command line...

$ rebar compile && erl -pa deps/*/ebin ebin

I have also tried including application:start(sasl) and -s start_sasl but not getting stack traces and exception information.

Sorry if this is an obvious issue, but I have searched far and wide and also googled a fair bit. Thanks in advance for any help with this issue.

Can you help me with the "multipart/form-data" Content-Type

I get this binary string in request and need to convert it to JSON Format

<<"--48940923NODERESLTER3890457293\r\nContent-Disposition: form-data; name=\"CallSid\"\r\n\r\n4025beb07e1faac824c6b2f9e22e0b5f\r\n--48940923NODERESLTER3890457293\r\nContent-Disposition: form-data; name=\"Status\"\r\n\r\nfailed\r\n--48940923NODERESLTER3890457293\r\nContent-Disposition: form-data; name=\"DateUpdated\"\r\n\r\n2016-11-07 16:01:40\r\n--48940923NODERESLTER3890457293--\r\n">>

Adding Content-Length when serving file

Right now we expect the handlers to set the correct content length for file based responses. Can we add Content-Length header by reading it ( read_file_info/1) instead of the handler doing it every time ?

Thanks

Runtime error on exit

Thanks for posting this code. It looks very useful.

Hope you don't mind me creating an issue for this simple problem, but others might land here while Googling for this error.

The code built fine and the test of the sample callback worked as advertised, but I get this error on exit. It's probably because I did a q() instead of stopping the process started with start_link()?

Eshell V5.9.1 (abort with ^G)
1> {ok, Pid} = elli:start_link([{callback, elli_example_callback}, {port, 3000}]).
{ok,<0.33.0>}
2> q().
ok
3> (no error logger present) error: "Error in process <0.33.0> with exit value: {badarg,[{gen_event,send,2,[{file,"gen_event.erl"},{line,219}]},{proc_lib,exit_p,2,[{file,"proc_lib.erl"},{line,247}]}]}\n"

Content-Length: foobar chokes

Elli chokes on incoming Content-Length: being not stringified integer, and response is never sent. I believe it should respond with 400 to bad input. What do you think?

Large file uploads

Is it possible to handle large file uploads in middleware, i.e. stream the body to disk instead of keeping it in memory ?

elli_test's limitations should be documented

I think elli_test is a valuable tool, but it could be a lot clearer what its use cases and limitations are. These hurdles should be documented to save folks time.

For instance, middleware like elli_date doesn't work if you use elli_test:call more than once, since the elli_startup event is signaled more than once, and elli_date's elli_startup handler is not idempotent (it tries and fails to instantiate ets twice).

Since elli_test:call calls the handler method directly, the returned Body list is not flattened (as shown in the hello iolist example). Tests need to match the handler's exact output rather than what you'd expect to receive through a full request to the running server.

Along the same lines, tests can only check against the headers set directly in the handler, and not any additional headers you'd expect from a full request.

Maybe these bits are obvious to others, but I spent some time figuring out elli_test was not a drop-in replacement for setting up and tearing down the server (as shown in elli's own test suite).

Publishing 1.0.5 to hex

I don't know if you published Elli to hex or not but we need to get 1.0.5 published.

Additionally, who ever did publish 1.0.4 had rebar3_hex in the plugins list of elli and not in the global list ~/.config/rebar3/rebar.config which means any project that depends on elli ends up fetching that plugin for no reason.

So if it was you who published, or if the person who did sees this :), it would be great to get 1.0.5 added and to not have rebar3_hex in the plugins list.

Content-Length header is duplicated if set via UserHeader

If you provide the Content-Length header via the user headers for a response, the content length will be duplicated in the response header.

Example:

Typical handle for elli:

handle('GET',[], Req) ->
    TrackingPixelData = <<71,73,70,56,57,97,1,0,1,0,128,1,0,0,0,0,255,255,255,33,
                         249,4,1,0,0,1,0,44,0,0,0,0,1,0,1,0,0,2,2,76,1,0,59>>,
    {ok, [{<<"Connection">>, <<"close">>}, {<<"Content-Length">>,<<"43">>}, {<<"Content-Type">>, <<"image/gif">>}],
     TrackingPixelData};

Response Header:

prompt> curl -v "http://localhost:3000/?sdasda"
* About to connect() to localhost port 3000 (#0)
*   Trying ::1...
* Connection refused
*   Trying 127.0.0.1...
* connected
* Connected to localhost (127.0.0.1) port 3000 (#0)
> GET /?sdasda HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:3000
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Length: 43
< Connection: close
< Content-Lengthd: 43
< Content-Type: image/gif
< 
* Closing connection #0
GIF89a????!?,L;

This happens because of this line and this line.

It would seem to be a trival issue but this causes some Amazon ELBs to fall-over and send out a 502 Bad Gateway. In our case, heroku dynos were responding with 200 but the dynos responses were causing the ELBs to fall over, in turn, sending out a 502.

Help: Failing to add middleware

Sorry for asking for help in a ticket, I couldn't see anywhere else to ask :( Yet more apologies if it's obvious, my first erlang app ...

I'm trying to add some cors headers to all requests going through my API. My cors_middleware.erl looks like

-module(cors_middleware).
-export([postprocess/3]).

postprocess(_Req, {ResponseCode, Headers, Body}, _Args) ->
    {ResponseCode, cors_headers() ++ Headers, Body}.

cors_headers() ->
    [{<<"Access-Control-Allow-Origin">>, <<"*">>},
    {<<"access-control-allow-methods">>, <<"GET,HEAD,POST,DELETE,OPTIONS,PUT">>},
    {<<"access-control-allow-headers">>, <<"Content-type">>}].

and my supervisor as follows (munged from the README and the elli_middleware.erl doc.

init([]) ->
    Config = [{mods, [{cors_middleware, []}]}],
    ElliConfig = [{callback, eric_callback},
                  {callback_args, Config},
                  {port, 3000}],

    ElliSpec = {
        eric,
        {elli, start_link, [ElliConfig]},
        permanent,
        5000,
        worker,
        [elli]},

    {ok, { {one_for_one, 5, 10}, [ElliSpec]} }.

Yes, my app is called eric. Whilst all my callbacks work, the middleware doesn't seem to get executed :(

Content-Type: in response

What's the recommended practice of supplying the subj when serving static content? Do we have any helper? Unless, do we want one in the core?
TIA,
--Vladimir

Keepalive currently looks broken

As it seems, keepalive is broken since ee6afb4

$ ab -n 1000 -c 1 -k http://localhost:8080/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
apr_socket_recv: Connection reset by peer (104)
Total of 2 requests completed

My last known good commit was initially 4d6ca5a, above commit was found to be the breaking one in a git-bisect session. To reproduce use git://github.com/martinrehfeld/elli-example.git

./rebar clean compile && ./bin/start_console 

Normalize headers

#req.headers should be lower-cased, imho, to ease pattern matching. what do you think?

max_body_size logic rigid

wonder if it is feasible to allow custom behaviour on maximum body size violation? right now there's no means to report that to the client.
i believe 413 code will be better, 406 or 422 would also be nice.

Elli doesn't send 100 Continue if expectation in request headers

When testing our client (based on libcurl) against elli I noticed that it sends an "Expect: 100-continue" header in the next request if it gets a 401 response from the server on the previous request using the same connection.

libcurl expects a 100 Continue response from the server and it will wait a short time (1 second in this case) before sending the body increasing the latency of the request.

Pull request #101 makes sure elli sends a 100 Continue response if the expectation header is in the client request.

The pull request does this regardless of HTTP version. It should really only do it for HTTP/1.1 but I don't know if any HTTP/1.0 will send the continue-100 header.

No 1.0.2 tag

I see the commit tagging it, but there's no git tag, is this intentional?

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.