Git Product home page Git Product logo

meowmeow's Introduction

MeowMeow webserver (formerly Ghost WebServer)

Erlang CI Publish Docker image Tests

Abstract

This is simple web server written in plain erlang.

Erlang version

Erlang/OTP 23 is required to run this server. Erlang/OTP 24 is reccommended.

Running

Debug mode

The best way to debug the program is just to do as following:

$ cd src/
$ erlc *.erl && erl; rm -rf ./*.beam # This will rebuild everything from scratch, so there would be no problems with cached files
...
Eshell V11.2  (abort with ^G)
1> server:start().

Before using this approach don't forget to create configuration files:

$ cp -r configs/ /etc/MeowMeow/ # Porbably you will need root(i.e. sudo)

Production mode

Compile using rebar3:

$ rebar3 as prod release

Then you need to create configs in /etc/MeowMeow/. After this you can run server:

$ ./_build/prod/rel/MeowMeow/bin/MeowMeow <desired mode of running>

If you need help on modes of running just execute script with no arguments to get help.

Using

Put your files in /var/www/ directory they will be served statically. Currently FastCGI support available for serving files wich are not static.

Configuring

IMPORTANT NOTICE: In current version syntax errors in config are NOT checked, so misconfiguration may lead to fatal errors.

Server

Server configuration is stored in /etc/MeowMeow/meow.conf. The syntax is as follows:

Directive1 Args
Directive2 Args

Current version support following directives:

  • LogLevel <<LEVEL>> set logging level from 0 to 4(0 -- log nothing,4 -- log everything)
  • KeepAlive <<MS>> default connection keep-alive time in milliseconds
  • ListenPort <<PORT>> port where to listen for connections
  • ListenHost <<HOSTNAME/IP>> hostname to listen on
  • DocDir <<DIRECTORY>> directory with files to serve

Routes

To configure routes you need to edit /etc/MeowMeow/routes.conf. The syntax is as follows:

Route <wildcard pattern> 
 Directive1 Args 
 Directive2 Args
 Host <wildcard pattern>
  Directive3 Args
 End
End

Route defines pattern of request paths for which directives would be applied. Additionally directives can be applied by Host header(as in an example above). Directives are applied in order as they added in the config file. The directives currently supported by server:

  • Abort <<CODE>> - stop processing request and send HTTP/1.1 status code <<CODE>> to client
  • No-Content - sends HTTP/1.1 204 No Content to client
  • Disallow - sends HTTP/1.1 403 Forbidden to client
  • Set-Header <<HEADER>> <<VALUE>> - sets response header <<HEADER>> to <<VALUE>>
  • ExecFCGI <<FILE>> <<FCGI_HOST>> <<FCGI_PORT>> <<FCGI_TIMEOUT>> - asks FastCGI running on <<FCGI_HOST>>:<<FCGI_PORT>> to execute <<FILE>> with timeout of <<FCGI_TIMEOUT>> ms
  • Set-Code <<CODE>> sets status code for a response.
  • Send-File <<PATH>> sends file as a response.

You can see an example of routing rules configuration here

Credits

  • erl_fastcgi - Copyright 2017, Marcelo Gornstein [email protected] (Apache-2.0 license).
    Changes introduced(file: src/erl_fastcgi.erl):
    • Added logging integrated with MeowMeow webserver
    • Added handling of errors when FastCGI server is down

Code copyrighting

The code copyrightings defined in some of the files in src/ directory are not legal advice and purposed for internal use only. All code, except mentioned in Credits section, is licensed under MIT license(See LICENSE for more information)

meowmeow's People

Contributors

0xf104a avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

meowmeow's Issues

[rules engine] `Default` rule cleans header

Describe the bug
When Default rule is used the headers are cleaned, and only Connection is sent. Thise leads to lack of Content-length header and so browser failing to finalize request correctly.

To Reproduce
In config apply Default rule to some route. Request this route through any client.

Expected behavior
The header MUST NOT be cleaned when using Default rule

OS & client (please complete the following information):

  • OS: Any
  • Client: Any
  • Client options(if applicable): N/A
  • Version: Any

GET parameters are not recognized

Server tries to handle get parameters as a file name, i.e. for /foo/bar?a=b it tries to find a file bar?a=b. Server should split get params and attach them to request record instead of attaching it to filename.

[rules engine] Some clients seem to be not to provide `Host` header

Exception:

Error in process <0.495.0> on node 'MeowMeow@e28340418539' with exit value:
{{badkey,"Host"},
 [{erlang,map_get,
          ["Host",
           #{body => [],http_ver => <<"HTTP/1.0">>,method => <<"GET">>,
             route => <<"/nice%20ports%2C/Tri%6Eity.txt%2ebak">>,
             "body" => <<>>}],
          [{error_info,#{module => erl_erts_errors}}]},
  {access,get_rules_checked,4,[{file,"/buildroot/src/access.erl"},{line,79}]},
  {handle,handle,2,[{file,"/buildroot/src/handle.erl"},{line,184}]},
  {handle,handler,3,[{file,"/buildroot/src/handle.erl"},{line,251}]}]}

The following should be investigated:

  • Whether this is allowed in HTTP/1.0
    • If so whether do we need to support it
  • Definitely handle it by returning 400 Bad request

[rules engine] Incorrect handling of absent `Hosts` header

Describe the bug
When client does HTTP/1.0 request to server with Hosts handling configured the exception on server occurs.

To Reproduce
Any HTTP/1.0 request without Hosts header to MeowMeow server where Hosts handling is configured.

Expected behavior
No exception should occur.

OS & client (please complete the following information):
Unknown

Logs

=ERROR REPORT==== 9-Jul-2021::06:28:11.395303 ===
Error in process <0.1905.0> on node 'MeowMeow@ef6b9abe815b' with exit value:
{{badmatch,ok},
 [{handle,do_rules,2,[{file,"/buildroot/src/handle.erl"},{line,76}]},
  {handle,handle,2,[{file,"/buildroot/src/handle.erl"},{line,198}]},
  {handle,handler,3,[{file,"/buildroot/src/handle.erl"},{line,272}]}]}

[logging] [optimization] Logger as separate process

The webserver produces a lot of debug messages which make request handling slower. As the code grows the amount of messages which are sent to logs also grows. So it might be beneficial in future to separate logging in another process in order to deliver response as fast as possible.

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.