knutin / elli Goto Github PK
View Code? Open in Web Editor NEWSimple, robust and performant Erlang web server
License: MIT License
Simple, robust and performant Erlang web server
License: MIT License
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
Just curious, are you planning to support http2 in elli?
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 :)
Hi, For Post method, the payload is json format, just like:
{
"UserId":"5",
"Token":"b4f61c3e465847d481433d6c3ba086fb",
"MacList":[
{
"Mac":"98:7B:F3:5A:61:70"
}
]
}
So does elli support content-type is "application/json" for POST method?
Is it possible to handle large file uploads in middleware, i.e. stream the body to disk instead of keeping it in memory ?
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.
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.
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?
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?
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.
It would be nice if it just gave the data without parsing if the content type is json in the body_qs funciton
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 :(
Hi!
Wonder if it is feasible in addition to current Connect-style middleware to have a WSGI/JSGI-style middleware -- that is based upon partial function application, kinda https://github.com/creationix/moonslice-luv/blob/master/log.lua
TIA
wonder if we can employ erlyvideo/gen_http to pump http?
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
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"
#req.headers
should be lower-cased, imho, to ease pattern matching. what do you think?
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
While compiling
....../elli/src/elli_test.erl:18: type record(_) undefined
&
.....src/elli.erl:26: type record(_) undefined
Is it planned? In the core or as a middleware?
Elli starts inets
if you run application:ensure_all_started(elli)
, yet inets
isn't used anywhere.
and may they be thrown/disabled?
Or do I need to handle that manually or via middleware?
Ugh, github on android sucks. By accident created an issue.
Hi!
I'd like to implement serving ranges of file based on Range: request header.
Wonder if you could add signature from the subj to make partial sendfile.
TIA
I see the commit tagging it, but there's no git tag, is this intentional?
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">>
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.
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
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
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.
%status(449) -> <<"449 Retry With">>;
The 449 Retry With status code indicates that the request cannot be satisfied because insufficient information was provided by the client.
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}}
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.
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).
It should be possible to pass in an IP address to bind elli to a specific interface
Events like elli_startup
, request_complete
, client_closed
should be documented.
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
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?
https://github.com/elli-lib/elli_prometheus
If you could also add an example how how to configure OPTS passed to elli so you have both a middleware and "normal" callback handler, that would be great. It's not obvious to me how to pass multiple callback handlers in the options.
Thanks!
P.S. Blogged about elli here: http://markbucciarelli.com/2016-11-09_a_simple_erlang_application.html
Is it possible to use websockets and long lived connections for long-polling?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.