Welcome to hi-nginx.com

可靠、强劲、稳定的 Web 服务器和 Application 服务器

Download

关于

它既是 web 服务器,也是 application 服务器。

它是 NGINX 的超集。

它性能强劲,易于开发,部署方便。

它支持多种语言混合开发 web 应用:

  • C++
  • Python
  • Lua
  • Java
  • PHP
  • Javascript
  • jsr-223 JVM language

压力测试

ab image

语言

cpp


#include "servlet.hpp"
namespace hi{
class hello : public servlet {
    public:

        void handler(request& req, response& res) {
            res.headers.find("Content-Type")->second = "text/plain;charset=UTF-8";
            res.content = "hello,world";
            res.status = 200;
        }

    };
}

extern "C" hi::servlet* create() {
    return new hi::hello();
}

extern "C" void destroy(hi::servlet* p) {
    delete p;
}
                        

python


data='{client},{method},{uri},{user_agent},{param}'.format(client=hi_req.client(),method=hi_req.method(),uri=hi_req.uri(),user_agent=hi_req.user_agent(),param=hi_req.param())
hi_res.header('Content-Type','text/plain;charset=UTF-8')
hi_res.content(data)
hi_res.status(200)
或者使用 hi.py框架:

from hi import hi
app =hi()

@app.route(r'^/test/?$',['GET','POST'])
@app.route(r"^/$",['GET'])
def hello_world(req,res,param):
    res.header('Content-Type','text/plain;charset=utf-8')
    res.content('hello,world')
    res.status(200)

@app.route(r"^/client/?$",['GET','POST'])
def client(req,res,param):
    res.content('{}<br>{}<br>{}<br>{}<br>{}'.format(req.client(),req.method(),req.uri(),req.user_agent(),req.param()))
    res.status(200)

@app.route(r"^/hello/(?P<who>\w+)?$",['GET'])
def hello(req,res,param):
    res.content('{}={}'.format('who',param['who']))
    res.status(200)



if __name__ == '__main__':
    app.run(hi_req,hi_res)

lua


local data=string.format('%s,%s,%s,%s,%s',hi_req:client(),hi_req:method(),hi_req:uri(),hi_req:user_agent(),hi_req:param())
hi_res:header('Content-Type','text/plain;charset=UTF-8')
hi_res:content(data)
hi_res:status(200)

java


package hi;

public class hello implements hi.servlet {

    public hello() {

    }

    public void handler(hi.request req, hi.response res) {
        res.headers.get("Content-Type").set(0, "text/plain;charset=UTF-8");
        res.status = 200;
        res.content = "hello,world";

    }
}

php



require_once 'hi/servlet.php';
require_once 'hi/route.php';

class index implements \hi\servlet {

    public function handler(\hi\request $req, \hi\response $res) {
        $app = \hi\route::get_instance();
        $app->add('{^/$}', array('GET'), function ($rq, $rs, &$param) {
            $rs->content = 'hello,world';
            $rs->status = 200;
        });
        
        $app->add('{^/who/(?P<name>\w+)/?$}', array('GET'), function ($rq, $rs, &$param) {
            $rs->content = 'hello,'.$param['name'];
            $rs->status = 200;
        });

        $app->add('{^/phpinfo/?$}', array('GET'), function($rq, $rs, &$param) {
            ob_start();
            phpinfo();
            $rs->content = ob_get_contents();
            $rs->status = 200;
            ob_end_clean();
        });
        $app->run($req, $res);
    }

}

javascript


if (typeof (Mustache) == 'undefined') {
    load('https://cdn.bootcss.com/mustache.js/2.3.0/mustache.min.js')
}


var list = java.util.Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
var template = "{{#list}}* {{.}}\n{{/list}}"
var key = 'test', output
if (hi_req.cache.containsKey(key)) {
    output = hi_req.cache.get(key)
} else {
    output = Mustache.render(template, {'list': JSON.parse(list.toString())})
    hi_res.cache.put(key, output)
}
hi_res.headers.get('Content-Type').set(0, 'text/plain;charset=UTF-8')
hi_res.content = output
hi_res.status = 200;

groovy


    def coll = ["Groovy", "Java", "Javascript"]
    hi_res.content=coll.toString()
    hi_res.status=200    

博客

我信奉尼采和爱因斯坦。

https://blog.hi-nginx.com

联系

pangpang@hi-nginx.com