├── INSTALL ├── tests ├── __init__.py ├── badthread.py ├── werkzeug.py ├── rpc.py ├── refcount.py ├── cpubound_async.py ├── web3.py ├── slow.py ├── pump.py ├── sig.lua ├── logger.py ├── multiapp.txt ├── sleeping_async.py ├── sendchunked.py ├── runningthread.py ├── testpy3.py ├── cpubound_stackless.py ├── sharedarea.py ├── staticfile.py ├── sleepthreadasync.py ├── myadmin.py ├── testsignals.py ├── streamer.psgi ├── cpubound_green.py ├── fileserve_async.py ├── rpc.lua ├── gevent_spool.py ├── sleeping_green.py ├── spoolme.py ├── mako_ugreen.py ├── picazzo.py ├── grunter.py ├── badwrites.py ├── sigwait.py ├── mulefunc.py ├── threads.py ├── testgevent.py ├── iobound_async.py ├── iobound_green.py ├── signals.py ├── pgbound_async.py ├── Responder.pm ├── psycogreen_green.py ├── iobound_async_unix.py ├── psycopg2_green.py ├── templates │ └── queue.html └── queue.py ├── core ├── clang_fake.c ├── skel.c ├── clock.c ├── querystring.c ├── storage.c └── timebomb.c ├── examples ├── debug.ini ├── bootstrap5.py ├── bootstrap4.py ├── config2.ru ├── bootstrap2.py ├── simple_logger.py ├── bootstrap.py ├── fibers.yml ├── bootstrap3.py ├── uwsgirouter2.py ├── config2.lua ├── werkzeug_strict.yml ├── uwsgirouter5.py ├── sputnik.ws ├── zmqgevent.ini ├── config.lua ├── config.ru ├── welcome.ini ├── werkzeug.js ├── simple_app_wsgi2.py ├── uwsgirouter4.py ├── mojoapp.pl ├── mega.xml ├── protected.ini ├── staticfilesnmp.py ├── heavytest.ini ├── sites.xml ├── flaskpost.py ├── uwsgirouter3.py ├── multi.ini ├── xmlindex.ini ├── heavytest.py ├── werkzeug.yml ├── config17.ru ├── uwsgi.xml ├── multiapp.py ├── router.lua ├── mjpeg_stream.py ├── info_uwsgi.php ├── logic.ini ├── taskqueue.py ├── fibers.ru ├── simple_app.py ├── welcome3.py ├── multi.xml └── config30.ru ├── logo_uWSGI.png ├── plugins ├── ssi │ └── uwsgiplugin.py ├── carbon │ └── uwsgiplugin.py ├── cgi │ └── uwsgiplugin.py ├── dummy │ ├── uwsgiplugin.py │ └── dummy.c ├── echo │ ├── uwsgiplugin.py │ └── echo_plugin.c ├── msgpack │ └── uwsgiplugin.py ├── objc_gc │ ├── objc_gc.m │ └── uwsgiplugin.py ├── pam │ └── uwsgiplugin.py ├── ping │ └── uwsgiplugin.py ├── rpc │ └── uwsgiplugin.py ├── xattr │ └── uwsgiplugin.py ├── cache │ └── uwsgiplugin.py ├── dumbloop │ └── uwsgiplugin.py ├── logfile │ └── uwsgiplugin.py ├── logpipe │ ├── uwsgiplugin.py │ └── logpipe.c ├── nagios │ └── uwsgiplugin.py ├── notfound │ ├── uwsgiplugin.py │ └── notfound.c ├── rados │ └── uwsgiplugin.py ├── ugreen │ └── uwsgiplugin.py ├── zabbix │ └── uwsgiplugin.py ├── example │ ├── uwsgiplugin.py │ └── example_plugin.c ├── geoip │ └── uwsgiplugin.py ├── ldap │ └── uwsgiplugin.py ├── libffi │ └── uwsgiplugin.py ├── libtcc │ ├── uwsgiplugin.py │ └── libtcc.c ├── logcrypto │ └── uwsgiplugin.py ├── rrdtool │ └── uwsgiplugin.py ├── rsyslog │ └── uwsgiplugin.py ├── spooler │ └── uwsgiplugin.py ├── symcall │ └── uwsgiplugin.py ├── syslog │ └── uwsgiplugin.py ├── zergpool │ └── uwsgiplugin.py ├── logsocket │ └── uwsgiplugin.py ├── logzmq │ └── uwsgiplugin.py ├── matheval │ └── uwsgiplugin.py ├── redislog │ └── uwsgiplugin.py ├── router_hash │ └── uwsgiplugin.py ├── router_http │ └── uwsgiplugin.py ├── router_metrics │ └── uwsgiplugin.py ├── router_radius │ └── uwsgiplugin.py ├── signal │ ├── uwsgiplugin.py │ └── signal_plugin.c ├── curl_cron │ └── uwsgiplugin.py ├── exception_log │ └── uwsgiplugin.py ├── graylog2 │ └── uwsgiplugin.py ├── mongodblog │ └── uwsgiplugin.py ├── mongrel2 │ └── uwsgiplugin.py ├── router_cache │ └── uwsgiplugin.py ├── router_expires │ └── uwsgiplugin.py ├── router_redis │ └── uwsgiplugin.py ├── router_static │ └── uwsgiplugin.py ├── router_uwsgi │ └── uwsgiplugin.py ├── router_xmldir │ └── uwsgiplugin.py ├── sqlite3 │ └── uwsgiplugin.py ├── router_rewrite │ └── uwsgiplugin.py ├── transformation_gzip │ └── uwsgiplugin.py ├── tuntap │ └── uwsgiplugin.py ├── alarm_curl │ └── uwsgiplugin.py ├── cheaper_backlog2 │ └── uwsgiplugin.py ├── cheaper_busyness │ └── uwsgiplugin.py ├── clock_realtime │ ├── uwsgiplugin.py │ └── clock_realtime.c ├── cplusplus │ ├── uwsgiplugin.py │ ├── plugin.c │ └── base.cc ├── emperor_amqp │ └── uwsgiplugin.py ├── router_memcached │ └── uwsgiplugin.py ├── router_redirect │ └── uwsgiplugin.py ├── stats_pusher_file │ └── uwsgiplugin.py ├── stats_pusher_socket │ └── uwsgiplugin.py ├── stats_pusher_statsd │ └── uwsgiplugin.py ├── transformation_template │ ├── uwsgiplugin.py │ └── tt.c ├── transformation_tofile │ └── uwsgiplugin.py ├── clock_monotonic │ ├── uwsgiplugin.py │ └── clock_monotonic.c ├── emperor_zeromq │ └── uwsgiplugin.py ├── transformation_chunked │ ├── uwsgiplugin.py │ └── chunked.c ├── transformation_offload │ └── uwsgiplugin.py ├── transformation_toupper │ ├── uwsgiplugin.py │ └── toupper.c ├── alarm_xmpp │ ├── uwsgiplugin.py │ └── alarm_xmpp_plugin.c ├── corerouter │ └── uwsgiplugin.py ├── legion_cache_fetch │ └── uwsgiplugin.py ├── rawrouter │ └── uwsgiplugin.py ├── sslrouter │ └── uwsgiplugin.py ├── fastrouter │ └── uwsgiplugin.py ├── router_access │ └── uwsgiplugin.py ├── http │ └── uwsgiplugin.py ├── mongodb │ ├── plugin.c │ └── uwsgiplugin.py ├── xslt │ └── uwsgiplugin.py ├── webdav │ └── uwsgiplugin.py ├── airbrake │ └── uwsgiplugin.py ├── glusterfs │ └── uwsgiplugin.py ├── asyncio │ └── uwsgiplugin.py ├── php │ ├── common.h │ ├── uwsgiplugin.py │ └── session.c ├── pty │ └── uwsgiplugin.py ├── tornado │ └── uwsgiplugin.py ├── gevent │ └── uwsgiplugin.py ├── greenlet │ └── uwsgiplugin.py ├── router_spnego │ └── uwsgiplugin.py ├── stackless │ └── uwsgiplugin.py ├── router_basicauth │ └── uwsgiplugin.py ├── alarm_speech │ ├── uwsgiplugin.py │ └── alarm_speech.m ├── forkptyrouter │ └── uwsgiplugin.py ├── pyuwsgi │ └── uwsgiplugin.py ├── pypy │ ├── uwsgiplugin.py │ └── README ├── jwsgi │ └── uwsgiplugin.py ├── v8 │ ├── uwsgiplugin.py │ ├── v8_uwsgi.h │ └── plugin.c ├── servlet │ └── uwsgiplugin.py ├── emperor_pg │ └── uwsgiplugin.py ├── stats_pusher_mongodb │ ├── uwsgiplugin.py │ └── plugin.c ├── systemd_logger │ ├── uwsgiplugin.py │ └── systemd_logger.c ├── gccgo │ └── uwsgiplugin.py ├── psgi │ └── uwsgiplugin.py ├── gridfs │ ├── uwsgiplugin.py │ └── plugin.c ├── emperor_mongodb │ ├── uwsgiplugin.py │ └── plugin.c ├── mono │ └── uwsgiplugin.py ├── coroae │ └── uwsgiplugin.py ├── ring │ └── uwsgiplugin.py ├── python │ └── gil.c ├── lua │ └── uwsgiplugin.py ├── rack │ └── uwsgi_rack.h ├── fiber │ └── uwsgiplugin.py ├── rbthreads │ └── uwsgiplugin.py └── jvm │ └── uwsgi.java ├── bin └── uwsgi ├── t ├── sharedarea │ ├── bigranges.ini │ ├── sharedarea_incdec.ini │ ├── bigranges.py │ └── sharedarea_incdec.py ├── perl │ ├── test_hello.psgi │ ├── apps │ │ ├── env.psgi │ │ ├── input_with_offset.pl │ │ └── body-types.psgi │ ├── active_workers_signal.pl │ ├── test_sleepy.psgi │ ├── test_harakiri.psgi │ ├── run │ ├── test_post.psgi │ └── test_streaming.psgi ├── mono │ └── cache.aspx ├── python │ ├── manage_script_name │ │ ├── useless_app.py │ │ ├── manage_script_name_test.ini │ │ └── test_manage_script_name.py │ ├── testba.py │ ├── forcecl.py │ ├── spooler_priority │ │ ├── spooler_priority_constants.py │ │ ├── spooler_priority_test.ini │ │ └── spooler_priority_handler.py │ ├── spooler_decorators │ │ ├── spooler_decorator_test.ini │ │ ├── spooler_handlers.py │ │ └── spooler_decorator_tests.py │ └── spooler_handler.py ├── core │ ├── apps │ │ └── read_body_and_send.pl │ ├── read_body_and_send.pl │ └── url_sanitize.pl ├── xslt │ ├── routex.ini │ ├── cd.xml │ └── cd.xml.xslt ├── ring │ ├── config.ini │ ├── project.clj │ ├── src │ │ └── uwsgi │ │ │ └── ring │ │ │ └── tests │ │ │ ├── simple.clj │ │ │ ├── upload.clj │ │ │ ├── body.clj │ │ │ ├── app.clj │ │ │ └── basic.clj │ └── README.md ├── clojure │ └── myapp.clj ├── java │ └── rpc.java ├── webdav │ └── carddav.ini ├── lua │ └── basic.lua ├── cachebitmap.ini ├── spooler │ └── cheap.py ├── routing │ ├── limiter.ini │ └── errorlimiter.ini ├── cachetest.py ├── go │ ├── uploadtest.go │ ├── complextest.go │ └── cachetest.go └── pypy │ ├── t_continulet1.py │ └── t_continulet2.py ├── contrib ├── fdconf.pl ├── spoolqueue │ ├── producer.py │ ├── tasks.py │ └── tasksconsumer.py ├── upstart │ ├── emperor.conf │ └── uwsgi.conf ├── upython ├── pyuwsgi.py ├── xinetd_uwsgi ├── subscribe.pl ├── launchd │ ├── it.unbit.uwsgi.emperor.plist │ └── it.unbit.uwsgi.plist ├── cryptologger.rb ├── loadapp.pl ├── binder.pl ├── uwsgi.erl ├── securesubscribe.pl ├── graphite_uwsgi.py └── cgi_python.c ├── vhosttest ├── flask001 │ └── app1.py ├── flask003 │ └── app3.py ├── flask004 │ └── app4.py ├── flask005 │ └── app5.py ├── flask002 │ └── app2.py └── nginx.conf ├── uwsgi_main.c ├── README ├── vassals ├── cc.ini ├── broodlord.ini └── multi.xml ├── attach.py ├── Makefile ├── .gitignore ├── valgrind ├── README └── valgrind-generate-sups.sh ├── uwsgi.gemspec ├── install.sh ├── ext └── uwsgi │ └── extconf.rb ├── mongrel2-uwsgi.conf ├── lib └── sun_fixes.c └── CONTRIBUTORS /INSTALL: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /core/clang_fake.c: -------------------------------------------------------------------------------- 1 | int main() {} 2 | -------------------------------------------------------------------------------- /examples/debug.ini: -------------------------------------------------------------------------------- 1 | [uwsgi] 2 | show-config = true 3 | -------------------------------------------------------------------------------- /examples/bootstrap5.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | 3 | print uwsgi.extract("data://0") 4 | -------------------------------------------------------------------------------- /logo_uWSGI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clearlinux/uwsgi/master/logo_uWSGI.png -------------------------------------------------------------------------------- /tests/badthread.py: -------------------------------------------------------------------------------- 1 | def application(env, start_response): 2 | while 1: 3 | pass 4 | -------------------------------------------------------------------------------- /examples/bootstrap4.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import uwsgi 3 | 4 | sys.meta_path.insert(0, uwsgi.ZipImporter("data://0")) 5 | -------------------------------------------------------------------------------- /plugins/ssi/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'ssi' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['ssi'] 7 | -------------------------------------------------------------------------------- /examples/config2.ru: -------------------------------------------------------------------------------- 1 | require 'sinatra' 2 | 3 | get '/hi' do 4 | "Hello World" 5 | end 6 | 7 | run Sinatra::Application 8 | -------------------------------------------------------------------------------- /plugins/carbon/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'carbon' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['carbon'] 7 | -------------------------------------------------------------------------------- /plugins/cgi/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'cgi' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['cgi_plugin'] 7 | -------------------------------------------------------------------------------- /plugins/dummy/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'dummy' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['dummy'] 7 | -------------------------------------------------------------------------------- /plugins/echo/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'echo' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['echo_plugin'] 7 | -------------------------------------------------------------------------------- /plugins/msgpack/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'msgpack' 2 | CFLAGS = [] 3 | LDFLAGS = [] 4 | LIBS = [] 5 | GCC_LIST = ['msgpack'] 6 | -------------------------------------------------------------------------------- /plugins/objc_gc/objc_gc.m: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct uwsgi_plugin objc_gc_plugin = { 4 | .name = "objc_gc", 5 | }; 6 | -------------------------------------------------------------------------------- /plugins/pam/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'pam' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = ['-lpam'] 6 | GCC_LIST = ['pam'] 7 | -------------------------------------------------------------------------------- /plugins/ping/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'ping' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['ping_plugin'] 7 | -------------------------------------------------------------------------------- /plugins/rpc/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'rpc' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['rpc_plugin'] 7 | -------------------------------------------------------------------------------- /plugins/xattr/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'xattr' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['xattr'] 7 | -------------------------------------------------------------------------------- /examples/bootstrap2.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import uwsgi 3 | 4 | sys.meta_path.insert(0, uwsgi.SymbolsZipImporter("pygments_zip")) 5 | -------------------------------------------------------------------------------- /plugins/cache/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'cache' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | 7 | GCC_LIST = ['cache'] 8 | -------------------------------------------------------------------------------- /plugins/dumbloop/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'dumbloop' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['dumb'] 7 | -------------------------------------------------------------------------------- /plugins/logfile/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'logfile' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['logfile'] 7 | -------------------------------------------------------------------------------- /plugins/logpipe/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'logpipe' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['logpipe'] 7 | -------------------------------------------------------------------------------- /plugins/nagios/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'nagios' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | 7 | GCC_LIST = ['nagios'] 8 | -------------------------------------------------------------------------------- /plugins/notfound/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'notfound' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['notfound'] 7 | -------------------------------------------------------------------------------- /plugins/rados/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'rados' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = ['-lrados'] 6 | GCC_LIST = ['rados'] 7 | -------------------------------------------------------------------------------- /plugins/ugreen/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'ugreen' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | 7 | GCC_LIST = ['ugreen'] 8 | -------------------------------------------------------------------------------- /plugins/zabbix/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'zabbix' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | 7 | GCC_LIST = ['plugin'] 8 | -------------------------------------------------------------------------------- /bin/uwsgi: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | cmd = File.expand_path "#{File.dirname(__FILE__)}/../ext/uwsgi/uwsgi.ruby" 3 | 4 | exec(cmd, *ARGV) 5 | -------------------------------------------------------------------------------- /plugins/example/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'example' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['example_plugin'] 7 | -------------------------------------------------------------------------------- /plugins/geoip/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'geoip' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = ['-lGeoIP'] 6 | 7 | GCC_LIST = ['geoip'] 8 | -------------------------------------------------------------------------------- /plugins/ldap/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'ldap' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = ['-lldap'] 6 | 7 | GCC_LIST = ['ldap'] 8 | -------------------------------------------------------------------------------- /plugins/libffi/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'libffi' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = ['-lffi'] 6 | GCC_LIST = ['libffi'] 7 | -------------------------------------------------------------------------------- /plugins/libtcc/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'libtcc' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = ['-ltcc'] 6 | GCC_LIST = ['libtcc'] 7 | -------------------------------------------------------------------------------- /plugins/logcrypto/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'logcrypto' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['logcrypto'] 7 | -------------------------------------------------------------------------------- /plugins/objc_gc/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = "objc_gc" 2 | CFLAGS = ["-fobjc-gc"] 3 | LDFLAGS = [] 4 | LIBS = [] 5 | GCC_LIST = ['objc_gc.m'] 6 | -------------------------------------------------------------------------------- /plugins/rrdtool/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'rrdtool' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | 7 | GCC_LIST = ['rrdtool'] 8 | -------------------------------------------------------------------------------- /plugins/rsyslog/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'rsyslog' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['rsyslog_plugin'] 7 | -------------------------------------------------------------------------------- /plugins/spooler/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'spooler' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['spooler_plugin'] 7 | -------------------------------------------------------------------------------- /plugins/symcall/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'symcall' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['symcall_plugin'] 7 | -------------------------------------------------------------------------------- /plugins/syslog/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'syslog' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['syslog_plugin'] 7 | -------------------------------------------------------------------------------- /plugins/zergpool/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'zergpool' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | 7 | GCC_LIST = ['zergpool'] 8 | -------------------------------------------------------------------------------- /t/sharedarea/bigranges.ini: -------------------------------------------------------------------------------- 1 | [uwsgi] 2 | socket = /tmp/foo 3 | 4 | sharedarea = size=4300000000 5 | 6 | pyrun = t/sharedarea/%n.py 7 | -------------------------------------------------------------------------------- /t/sharedarea/sharedarea_incdec.ini: -------------------------------------------------------------------------------- 1 | [uwsgi] 2 | socket = /tmp/foo 3 | 4 | sharedarea = size=64 5 | 6 | pyrun = t/sharedarea/%n.py 7 | -------------------------------------------------------------------------------- /plugins/logsocket/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'logsocket' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['logsocket_plugin'] 7 | -------------------------------------------------------------------------------- /plugins/logzmq/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'logzmq' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = ['-lzmq'] 6 | 7 | GCC_LIST = ['plugin'] 8 | -------------------------------------------------------------------------------- /plugins/matheval/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'matheval' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = ['-lmatheval'] 6 | GCC_LIST = ['math'] 7 | -------------------------------------------------------------------------------- /plugins/redislog/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'redislog' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['redislog_plugin'] 7 | -------------------------------------------------------------------------------- /plugins/router_hash/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'router_hash' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['router_hash'] 7 | -------------------------------------------------------------------------------- /plugins/router_http/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'router_http' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['router_http'] 7 | -------------------------------------------------------------------------------- /plugins/router_metrics/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'router_metrics' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['plugin'] 7 | -------------------------------------------------------------------------------- /plugins/router_radius/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'router_radius' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['radius'] 7 | -------------------------------------------------------------------------------- /plugins/signal/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'signal' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | 7 | GCC_LIST = ['signal_plugin'] 8 | -------------------------------------------------------------------------------- /contrib/fdconf.pl: -------------------------------------------------------------------------------- 1 | use POSIX; 2 | 3 | open CONFIG,'welcome.ini'; 4 | 5 | dup2(fileno(CONFIG), 17); 6 | 7 | exec './uwsgi','--ini','fd://17'; 8 | -------------------------------------------------------------------------------- /plugins/curl_cron/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'curl_cron' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = ['-lcurl'] 6 | GCC_LIST = ['curl_cron'] 7 | -------------------------------------------------------------------------------- /plugins/exception_log/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'exception_log' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['exception_log'] 7 | -------------------------------------------------------------------------------- /plugins/graylog2/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'graylog2' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = ['-lz'] 6 | GCC_LIST = ['graylog2_plugin'] 7 | -------------------------------------------------------------------------------- /plugins/mongodblog/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'mongodblog' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['mongodblog_plugin'] 7 | -------------------------------------------------------------------------------- /plugins/mongrel2/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'mongrel2' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = ['-lzmq'] 6 | 7 | GCC_LIST = ['mongrel2'] 8 | -------------------------------------------------------------------------------- /plugins/router_cache/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'router_cache' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['router_cache'] 7 | -------------------------------------------------------------------------------- /plugins/router_expires/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'router_expires' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['expires'] 7 | -------------------------------------------------------------------------------- /plugins/router_redis/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'router_redis' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['router_redis'] 7 | -------------------------------------------------------------------------------- /plugins/router_static/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'router_static' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['router_static'] 7 | -------------------------------------------------------------------------------- /plugins/router_uwsgi/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'router_uwsgi' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['router_uwsgi'] 7 | -------------------------------------------------------------------------------- /plugins/router_xmldir/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'router_xmldir' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['router_xmldir'] 7 | -------------------------------------------------------------------------------- /plugins/sqlite3/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'sqlite3' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = ['-lsqlite3'] 6 | 7 | GCC_LIST = ['plugin'] 8 | -------------------------------------------------------------------------------- /plugins/router_rewrite/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'router_rewrite' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['router_rewrite'] 7 | -------------------------------------------------------------------------------- /plugins/transformation_gzip/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'transformation_gzip' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['gzip'] 7 | -------------------------------------------------------------------------------- /plugins/tuntap/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'tuntap' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['common', 'firewall', 'tuntap'] 7 | -------------------------------------------------------------------------------- /plugins/alarm_curl/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'alarm_curl' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = ['-lcurl'] 6 | GCC_LIST = ['alarm_curl_plugin'] 7 | -------------------------------------------------------------------------------- /plugins/cheaper_backlog2/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'cheaper_backlog2' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['cheaper_backlog2'] 7 | -------------------------------------------------------------------------------- /plugins/cheaper_busyness/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'cheaper_busyness' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['cheaper_busyness'] 7 | -------------------------------------------------------------------------------- /plugins/clock_realtime/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'clock_realtime' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = ['-lrt'] 6 | GCC_LIST = ['clock_realtime'] 7 | -------------------------------------------------------------------------------- /plugins/cplusplus/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'cplusplus' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = ['-lstdc++'] 6 | GCC_LIST = ['base.cc', 'plugin'] 7 | -------------------------------------------------------------------------------- /plugins/emperor_amqp/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'emperor_amqp' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | 7 | GCC_LIST = ['amqp', 'emperor_amqp'] 8 | -------------------------------------------------------------------------------- /plugins/router_memcached/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'router_memcached' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['router_memcached'] 7 | -------------------------------------------------------------------------------- /plugins/router_redirect/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'router_redirect' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['router_redirect'] 7 | -------------------------------------------------------------------------------- /plugins/stats_pusher_file/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'stats_pusher_file' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | 7 | GCC_LIST = ['plugin'] 8 | -------------------------------------------------------------------------------- /plugins/stats_pusher_socket/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'stats_pusher_socket' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | 7 | GCC_LIST = ['plugin'] 8 | -------------------------------------------------------------------------------- /plugins/stats_pusher_statsd/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'stats_pusher_statsd' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | 7 | GCC_LIST = ['plugin'] 8 | -------------------------------------------------------------------------------- /plugins/transformation_template/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'transformation_template' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['tt'] 7 | -------------------------------------------------------------------------------- /plugins/transformation_tofile/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'transformation_tofile' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['tofile'] 7 | -------------------------------------------------------------------------------- /t/perl/test_hello.psgi: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | 4 | sub { 5 | my $env = shift; 6 | 7 | return [200, [], [ "Hello, world!" ]]; 8 | } 9 | -------------------------------------------------------------------------------- /tests/werkzeug.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | 3 | print(uwsgi.opt) 4 | print(uwsgi.magic_table) 5 | from werkzeug.testapp import test_app as application # NOQA 6 | -------------------------------------------------------------------------------- /vhosttest/flask001/app1.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | app = Flask(__name__) 3 | 4 | 5 | @app.route("/") 6 | def hello(): 7 | return "Hello World!" 8 | -------------------------------------------------------------------------------- /plugins/clock_monotonic/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'clock_monotonic' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = ['-lrt'] 6 | GCC_LIST = ['clock_monotonic'] 7 | -------------------------------------------------------------------------------- /plugins/emperor_zeromq/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'emperor_zeromq' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = ['-lzmq'] 6 | 7 | GCC_LIST = ['emperor_zeromq'] 8 | -------------------------------------------------------------------------------- /plugins/transformation_chunked/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'transformation_chunked' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['chunked'] 7 | -------------------------------------------------------------------------------- /plugins/transformation_offload/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'transformation_offload' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['offload'] 7 | -------------------------------------------------------------------------------- /plugins/transformation_toupper/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'transformation_toupper' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | GCC_LIST = ['toupper'] 7 | -------------------------------------------------------------------------------- /vhosttest/flask003/app3.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | app = Flask(__name__) 3 | 4 | 5 | @app.route("/") 6 | def hello(): 7 | return "Hello World! app3" 8 | -------------------------------------------------------------------------------- /vhosttest/flask004/app4.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | app = Flask(__name__) 3 | 4 | 5 | @app.route("/") 6 | def hello(): 7 | return "Hello World! app4" 8 | -------------------------------------------------------------------------------- /vhosttest/flask005/app5.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | app = Flask(__name__) 3 | 4 | 5 | @app.route("/") 6 | def hello(): 7 | return "Hello World! app5" 8 | -------------------------------------------------------------------------------- /examples/simple_logger.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | 3 | 4 | def print_logs(ip, port, message): 5 | print(ip, port, message) 6 | 7 | uwsgi.udp_callable = print_logs 8 | -------------------------------------------------------------------------------- /plugins/alarm_xmpp/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'alarm_xmpp' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = ['-lgloox'] 6 | GCC_LIST = ['alarm_xmpp_plugin', 'gloox.cc'] 7 | -------------------------------------------------------------------------------- /plugins/corerouter/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'corerouter' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | 7 | GCC_LIST = ['cr_common', 'cr_map', 'corerouter'] 8 | -------------------------------------------------------------------------------- /plugins/legion_cache_fetch/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'legion_cache_fetch' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | 7 | GCC_LIST = ['legion_cache_fetch'] 8 | -------------------------------------------------------------------------------- /t/mono/cache.aspx: -------------------------------------------------------------------------------- 1 | <%@ language="C#"%> 2 | 3 | Hello 1
4 | <%= System.Text.Encoding.UTF8.GetString(uwsgi.api.CacheGet("/etc/passwd")) %>
5 | Hello 1
6 | -------------------------------------------------------------------------------- /uwsgi_main.c: -------------------------------------------------------------------------------- 1 | int uwsgi_init(int, char **, char **); 2 | 3 | int main(int argc, char *argv[], char **environ) { 4 | return uwsgi_init(argc, argv, environ); 5 | } 6 | -------------------------------------------------------------------------------- /vhosttest/flask002/app2.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | app = Flask(__name__) 3 | 4 | 5 | @app.route("/") 6 | def hello(): 7 | return "Hello World! app2 !!!" 8 | -------------------------------------------------------------------------------- /examples/bootstrap.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import uwsgi 3 | 4 | print("i am the bootstrap for uwsgi.SymbolsImporter") 5 | sys.meta_path.insert(0, uwsgi.SymbolsImporter()) 6 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | The uWSGI project 2 | 3 | For official documentation check: https://uwsgi-docs.readthedocs.org/en/latest/ 4 | 5 | For commercial support check: http://unbit.com/ 6 | -------------------------------------------------------------------------------- /examples/fibers.yml: -------------------------------------------------------------------------------- 1 | uwsgi: 2 | plugins: rack 3 | socket: 127.0.0.1:3031 4 | rack: fibers.ru 5 | post-buffering: 4096 6 | async: 10 7 | loop: fiber 8 | 9 | -------------------------------------------------------------------------------- /plugins/rawrouter/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'rawrouter' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | 7 | REQUIRES = ['corerouter'] 8 | 9 | GCC_LIST = ['rawrouter'] 10 | -------------------------------------------------------------------------------- /plugins/sslrouter/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'sslrouter' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | 7 | REQUIRES = ['corerouter'] 8 | 9 | GCC_LIST = ['sslrouter'] 10 | -------------------------------------------------------------------------------- /t/python/manage_script_name/useless_app.py: -------------------------------------------------------------------------------- 1 | def application(env, start_response): 2 | start_response('200 OK', [('Content-Type', 'text/html')]) 3 | return env['SCRIPT_NAME'] 4 | -------------------------------------------------------------------------------- /plugins/fastrouter/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'fastrouter' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | 7 | REQUIRES = ['corerouter'] 8 | 9 | GCC_LIST = ['fastrouter'] 10 | -------------------------------------------------------------------------------- /tests/rpc.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | 3 | 4 | def hello(): 5 | return "Hello World" 6 | 7 | print uwsgi.register_rpc("hello", hello) 8 | 9 | 10 | print uwsgi.rpc(None, "hello") 11 | -------------------------------------------------------------------------------- /plugins/router_access/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'router_access' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = ['-lwrap'] 6 | 7 | REQUIRES = [''] 8 | 9 | GCC_LIST = ['router_access'] 10 | -------------------------------------------------------------------------------- /plugins/http/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'http' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [] 6 | 7 | REQUIRES = ['corerouter'] 8 | 9 | GCC_LIST = ['http', 'keepalive', 'https', 'spdy3'] 10 | -------------------------------------------------------------------------------- /tests/refcount.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | def application(e, sr): 5 | sr('200 OK', [('Content-Type', 'text/html')]) 6 | print sys.gettotalrefcount() 7 | yield '%s' % sys.gettotalrefcount() 8 | -------------------------------------------------------------------------------- /t/core/apps/read_body_and_send.pl: -------------------------------------------------------------------------------- 1 | my $app = sub { 2 | my $env = shift; 3 | $env->{'psgi.input'}->read(my $body, $env->{CONTENT_LENGTH}); 4 | return [200, ['Content-Type' => 'x-application/binary'], [$body]]; 5 | }; 6 | -------------------------------------------------------------------------------- /examples/bootstrap3.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import uwsgi 3 | 4 | sys.meta_path.insert(0, uwsgi.SymbolsZipImporter("django_zip:djenv/lib/python2.6/site-packages")) 5 | sys.meta_path.insert(0, uwsgi.SymbolsZipImporter("djapp_zip")) 6 | -------------------------------------------------------------------------------- /examples/uwsgirouter2.py: -------------------------------------------------------------------------------- 1 | 2 | import uwsgi 3 | 4 | 5 | def application(e, s): 6 | 7 | for part in uwsgi.send_message("192.168.173.100:3032", 0, 0, e, 0, e['wsgi.input'].fileno(), uwsgi.cl()): 8 | yield part 9 | -------------------------------------------------------------------------------- /vassals/cc.ini: -------------------------------------------------------------------------------- 1 | [uwsgi] 2 | 3 | trac = trac.web.main 4 | id = myapp 5 | socket = /tmp/%(id).sock 6 | socket = :0 7 | env = TRAC_ENV=/opt/projects/%(id) 8 | module = %(trac):dispatch_request 9 | processes = 8 10 | master = true 11 | -------------------------------------------------------------------------------- /examples/config2.lua: -------------------------------------------------------------------------------- 1 | config = {} 2 | 3 | config[1] = { ['http-socket']=':9090' } 4 | config[2] = { ['env']='FOO=bar' } 5 | config[3] = { ['env']='TEST=topogigio' } 6 | config[4] = { ['module']='werkzeug.testapp:test_app' } 7 | 8 | return config 9 | -------------------------------------------------------------------------------- /examples/werkzeug_strict.yml: -------------------------------------------------------------------------------- 1 | # werkzeug test module via YAML 2 | uwsgi: 3 | module: werkzeug.testapp:test_app # a comment 4 | socket: :3032 # another comment 5 | master: 1 6 | processes: 8 # the number of processes 7 | memory-report: 1 8 | -------------------------------------------------------------------------------- /plugins/mongodb/plugin.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | 5 | a fake plugin used for preloading mongodb library when only available as static. 6 | 7 | */ 8 | 9 | struct uwsgi_plugin mongodb_plugin = { 10 | .name = "mongodb", 11 | }; 12 | -------------------------------------------------------------------------------- /t/perl/apps/env.psgi: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | 4 | sub { 5 | my $env = shift; 6 | 7 | my $body = join "\n", map "$_\n$env->{$_}", sort keys %$env; 8 | 9 | [ 200, [ 'Content-type' => 'text/plain' ], [$body] ]; 10 | }; 11 | -------------------------------------------------------------------------------- /t/xslt/routex.ini: -------------------------------------------------------------------------------- 1 | [uwsgi] 2 | http-socket = :9090 3 | plugin = xslt 4 | xml_storage = t/xslt 5 | route = /(.*)$ xslt:doc=%(xml_storage)/$1.xml,stylesheet=%(xml_storage)/$1.xml.xslt,content_type=text/html,params=foobar=test&agent=${HTTP_USER_AGENT} 6 | -------------------------------------------------------------------------------- /tests/cpubound_async.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | 4 | def application(env, start_response): 5 | start_response('200 OK', [('Content-Type', 'text/html')]) 6 | for i in range(1, 1000): 7 | yield "

%s at %s

" % (i, str(time.time())) 8 | -------------------------------------------------------------------------------- /t/python/testba.py: -------------------------------------------------------------------------------- 1 | import array 2 | 3 | 4 | def application(e, sr): 5 | sr('200 OK', [('Content-Type', 'text/html')]) 6 | a = array.array('b', [54, 55, 56, 57]) 7 | yield a 8 | yield bytearray(b'abcdef') 9 | yield b'ciao' 10 | -------------------------------------------------------------------------------- /examples/uwsgirouter5.py: -------------------------------------------------------------------------------- 1 | 2 | import uwsgi 3 | 4 | fd = uwsgi.connect("127.0.0.1:3033") 5 | 6 | 7 | def application(e, s): 8 | 9 | for part in uwsgi.send_message(fd, 0, 4, e, 30, e['wsgi.input'].fileno(), uwsgi.cl()): 10 | yield part 11 | -------------------------------------------------------------------------------- /plugins/xslt/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | NAME = 'xslt' 4 | 5 | CFLAGS = os.popen('xslt-config --cflags').read().rstrip().split() 6 | LDFLAGS = [] 7 | LIBS = os.popen('xslt-config --libs').read().rstrip().split() 8 | 9 | GCC_LIST = ['xslt'] 10 | -------------------------------------------------------------------------------- /attach.py: -------------------------------------------------------------------------------- 1 | import struct 2 | import sys 3 | import os 4 | 5 | filename = sys.argv[1] 6 | 7 | size = os.path.getsize(filename) 8 | 9 | f = open(filename, 'r') 10 | os.write(1, f.read()) 11 | f.close() 12 | 13 | os.write(1, (struct.pack(" 12 | 13 | -------------------------------------------------------------------------------- /plugins/pty/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | NAME = 'pty' 4 | 5 | uwsgi_os = os.uname()[0] 6 | 7 | CFLAGS = [] 8 | LDFLAGS = [] 9 | if uwsgi_os in ('Linux', 'FreeBSD', 'GNU', 'NetBSD', 'DragonFly'): 10 | LIBS = ['-lutil'] 11 | else: 12 | LIBS = [] 13 | GCC_LIST = ['pty'] 14 | -------------------------------------------------------------------------------- /plugins/tornado/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | from distutils import sysconfig 2 | 3 | NAME = 'tornado' 4 | 5 | CFLAGS = [ 6 | '-I' + sysconfig.get_python_inc(), 7 | '-I' + sysconfig.get_python_inc(plat_specific=True), 8 | ] 9 | LDFLAGS = [] 10 | LIBS = [] 11 | 12 | GCC_LIST = ['tornado'] 13 | -------------------------------------------------------------------------------- /tests/web3.py: -------------------------------------------------------------------------------- 1 | class AppClass(object): 2 | 3 | def __call__(self, environ): 4 | status = b'200 OK' 5 | headers = [(b'Content-type', b'text/plain')] 6 | body = [b'Hello world!\n'] 7 | return body, status, headers 8 | 9 | application = AppClass() 10 | -------------------------------------------------------------------------------- /plugins/gevent/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | from distutils import sysconfig 2 | 3 | NAME = 'gevent' 4 | 5 | CFLAGS = [ 6 | '-I' + sysconfig.get_python_inc(), 7 | '-I' + sysconfig.get_python_inc(plat_specific=True) 8 | ] 9 | LDFLAGS = [] 10 | LIBS = [] 11 | 12 | GCC_LIST = ['gevent', 'hooks'] 13 | -------------------------------------------------------------------------------- /plugins/greenlet/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | from distutils import sysconfig 2 | 3 | NAME = 'greenlet' 4 | 5 | CFLAGS = [ 6 | '-I' + sysconfig.get_python_inc(), 7 | '-I' + sysconfig.get_python_inc(plat_specific=True) 8 | ] 9 | LDFLAGS = [] 10 | LIBS = [] 11 | 12 | GCC_LIST = ['greenlet'] 13 | -------------------------------------------------------------------------------- /plugins/router_spnego/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | NAME = 'router_spnego' 4 | 5 | CFLAGS = os.popen('krb5-config --cflags gssapi').read().rstrip().split() 6 | LDFLAGS = [] 7 | LIBS = os.popen('krb5-config --libs gssapi').read().rstrip().split() 8 | 9 | GCC_LIST = ['router_spnego'] 10 | -------------------------------------------------------------------------------- /examples/config.ru: -------------------------------------------------------------------------------- 1 | require 'fiber' 2 | require 'sinatra' 3 | 4 | get '/hi' do 5 | 6 | class Response 7 | def each 8 | for i in 1..10 9 | yield "ciao
" 10 | Fiber.yield 11 | end 12 | end 13 | end 14 | 15 | Response.new 16 | end 17 | 18 | run Sinatra::Application 19 | -------------------------------------------------------------------------------- /examples/welcome.ini: -------------------------------------------------------------------------------- 1 | [uwsgi] 2 | socket = :$(PORT) 3 | socket = /tmp/uwsgi_welcome.socket 4 | vacuum = true 5 | appname = welcome 6 | module = %(appname) 7 | numproc = 4 8 | master = %(vacuum) 9 | processes = %(numproc) 10 | mount = /werkzeug=tests/werkzeug.py 11 | manage-script-name = true 12 | -------------------------------------------------------------------------------- /plugins/stackless/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | from distutils import sysconfig 2 | 3 | NAME = 'stackless' 4 | 5 | CFLAGS = [ 6 | '-I' + sysconfig.get_python_inc(), 7 | '-I' + sysconfig.get_python_inc(plat_specific=True), 8 | ] 9 | LDFLAGS = [] 10 | LIBS = [] 11 | 12 | GCC_LIST = ['stackless'] 13 | -------------------------------------------------------------------------------- /examples/werkzeug.js: -------------------------------------------------------------------------------- 1 | { 2 | "uwsgi": { 3 | "http": ":8080", 4 | "workers": 8, 5 | "module": "werkzeug.testapp:test_app", 6 | "master": true, 7 | "socket": [ "/tmp/uwsgi.sock", "127.0.0.1:3031", "@foobar" ], 8 | "pythonpath": [ "/foo", "/bar" ], 9 | "show-config": true 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/slow.py: -------------------------------------------------------------------------------- 1 | import time 2 | import uwsgi 3 | 4 | 5 | def application(e, s): 6 | print "locking" 7 | uwsgi.lock() 8 | print "locked" 9 | time.sleep(3) 10 | uwsgi.unlock() 11 | print "UN-locked" 12 | s('200 OK', [('Content-Type', 'text/html')]) 13 | return "slow" 14 | -------------------------------------------------------------------------------- /plugins/mongodb/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'mongodb' 2 | 3 | CFLAGS = [] 4 | LDFLAGS = [] 5 | LIBS = [ 6 | '-Wl,-whole-archive', 7 | '-lmongoclient', 8 | '-Wl,-no-whole-archive', 9 | '-lboost_thread', 10 | '-lboost_system', 11 | '-lboost_filesystem' 12 | ] 13 | GCC_LIST = ['plugin'] 14 | -------------------------------------------------------------------------------- /plugins/router_basicauth/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | NAME = 'router_basicauth' 4 | 5 | CFLAGS = [] 6 | LDFLAGS = [] 7 | LIBS = [] 8 | 9 | # osx and openbsd do not need libcrypt 10 | if os.uname()[0] not in ('Darwin', 'OpenBSD'): 11 | LIBS.append('-lcrypt') 12 | 13 | GCC_LIST = ['router_basicauth'] 14 | -------------------------------------------------------------------------------- /tests/pump.py: -------------------------------------------------------------------------------- 1 | def app(req): 2 | print(req) 3 | ret = { 4 | "status": 200, 5 | "headers": { 6 | "content_type": "text/html", 7 | "foo": ['bar0', 'bar1', 'bar2'] 8 | }, 9 | "body": "

Hello!

", 10 | } 11 | print(ret) 12 | return ret 13 | -------------------------------------------------------------------------------- /t/ring/config.ini: -------------------------------------------------------------------------------- 1 | [uwsgi] 2 | http-socket = :9090 3 | http-socket-modifier1 = 8 4 | http-socket-modifier2 = 1 5 | 6 | jvm-classpath = plugins/jvm/uwsgi.jar 7 | jvm-classpath = t/ring/target/uwsgi-ring-tests-0.0.1-standalone.jar 8 | 9 | jvm-class = uwsgi/ring/tests/app 10 | 11 | ring-app = uwsgi.ring.tests.app/app 12 | -------------------------------------------------------------------------------- /tests/sig.lua: -------------------------------------------------------------------------------- 1 | function hello_signal(sig, payload) 2 | 3 | print("i am Lua received signal " .. sig .. " with payload " .. payload) 4 | 5 | end 6 | 7 | uwsgi.register_signal(1, 1, hello_signal, "roberta") 8 | uwsgi.register_signal(2, 1, hello_signal, "serena") 9 | uwsgi.register_signal(3, 1, hello_signal, "alessandro") 10 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PYTHON := python 2 | 3 | all: 4 | $(PYTHON) uwsgiconfig.py --build $(PROFILE) 5 | 6 | clean: 7 | $(PYTHON) uwsgiconfig.py --clean 8 | 9 | check: 10 | $(PYTHON) uwsgiconfig.py --check 11 | 12 | plugin.%: 13 | $(PYTHON) uwsgiconfig.py --plugin plugins/$* $(PROFILE) 14 | 15 | %: 16 | $(PYTHON) uwsgiconfig.py --build $@ 17 | -------------------------------------------------------------------------------- /contrib/upstart/emperor.conf: -------------------------------------------------------------------------------- 1 | # uWSGI - Emperor 2 | # 3 | 4 | description "uWSGI Emperor" 5 | 6 | start on runlevel [2345] 7 | stop on runlevel [!2345] 8 | 9 | respawn 10 | 11 | env LOGTO=/tmp/uwsgi.log 12 | env BINPATH=/home/foo/uwsgi/uwsgi 13 | env VASSALS=/etc/uwsgi 14 | 15 | exec $BINPATH --emperor $VASSALS --logto $LOGTO 16 | -------------------------------------------------------------------------------- /plugins/alarm_speech/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | NAME = 'alarm_speech' 4 | 5 | uwsgi_os = os.uname()[0] 6 | 7 | LDFLAGS = [] 8 | if uwsgi_os == "Darwin": 9 | CFLAGS = [] 10 | LIBS = ['-framework appkit'] 11 | else: 12 | CFLAGS = ['-I /usr/include/GNUstep'] 13 | LIBS = [] 14 | 15 | GCC_LIST = ['alarm_speech.m'] 16 | -------------------------------------------------------------------------------- /t/python/manage_script_name/manage_script_name_test.ini: -------------------------------------------------------------------------------- 1 | [uwsgi] 2 | http-socket = :8080 3 | 4 | master = 1 5 | 6 | ; Three apps on three mountpoints 7 | wsgi-file = %d/useless_app.py 8 | 9 | mount = /foo=%d/useless_app.py 10 | mount = /foobis/=%d/useless_app.py 11 | mount = /footris/=%d/useless_app.py 12 | 13 | manage-script-name = 1 14 | -------------------------------------------------------------------------------- /plugins/dummy/dummy.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int dummy_request(struct wsgi_request *wsgi_req) { 4 | 5 | if (uwsgi_parse_vars(wsgi_req)) { 6 | return -1; 7 | } 8 | 9 | return UWSGI_OK; 10 | } 11 | 12 | struct uwsgi_plugin dummy_plugin = { 13 | .name = "dummy", 14 | .modifier1 = 0, 15 | .request = dummy_request, 16 | }; 17 | -------------------------------------------------------------------------------- /tests/logger.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | 3 | uwsgi.log("I am uWSGI %s" % uwsgi.version) 4 | 5 | 6 | def application(env, start_response): 7 | start_response('200 OK', [('Content-Type', 'text/html')]) 8 | uwsgi.log(str(env)) 9 | 10 | if env['PATH_INFO'] == '/logme': 11 | uwsgi.log_this_request() 12 | return "log written" 13 | -------------------------------------------------------------------------------- /tests/multiapp.txt: -------------------------------------------------------------------------------- 1 | - case 1 2 | 3 | single static app 4 | 5 | - case 2 6 | 7 | single static multiapp 8 | 9 | - case 3 10 | 11 | multi app static mountpoint 12 | 13 | - case 4 14 | 15 | dynamic apps with UWSGI_APPID 16 | 17 | - case 5 18 | 19 | dynamic apps with SCRIPT_NAME 20 | 21 | - case 6 22 | 23 | dynamic apps with vhost mode 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.py[co] 3 | *.class 4 | *.jar 5 | *~ 6 | *.so 7 | *.gox 8 | *.a 9 | *.dll 10 | *.key 11 | *.orig 12 | *.rej 13 | 14 | /uwsgi 15 | /uwsgibuild.* 16 | /core/config_py.c 17 | 18 | /t/ring/target 19 | 20 | core/dot_h.c 21 | 22 | +# coverity 23 | +/cov-int/ 24 | +uwsgi.tar.xz 25 | 26 | /build/ 27 | /dist/ 28 | /uWSGI.egg-info/ 29 | -------------------------------------------------------------------------------- /plugins/forkptyrouter/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | import os 2 | uwsgi_os = os.uname()[0] 3 | 4 | NAME = 'forkptyrouter' 5 | 6 | CFLAGS = [] 7 | LDFLAGS = [] 8 | if uwsgi_os in ('Linux', 'FreeBSD', 'GNU', 'NetBSD', 'DragonFly'): 9 | LIBS = ['-lutil'] 10 | else: 11 | LIBS = [] 12 | 13 | REQUIRES = ['corerouter'] 14 | 15 | GCC_LIST = ['forkptyrouter'] 16 | -------------------------------------------------------------------------------- /plugins/pyuwsgi/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | from distutils import sysconfig 2 | import os 3 | 4 | os.environ['UWSGI_PYTHON_NOLIB'] = '1' 5 | 6 | NAME = 'pyuwsgi' 7 | 8 | CFLAGS = [ 9 | '-I' + sysconfig.get_python_inc(), 10 | '-I' + sysconfig.get_python_inc(plat_specific=True), 11 | ] 12 | LDFLAGS = [] 13 | LIBS = [] 14 | 15 | GCC_LIST = ['pyuwsgi'] 16 | -------------------------------------------------------------------------------- /t/clojure/myapp.clj: -------------------------------------------------------------------------------- 1 | (ns myapp 2 | (import uwsgi) 3 | ) 4 | 5 | (defn handler [req] 6 | {:status 200 7 | :headers { "Content-Type" "text/html" , "Server" "uWSGI" } 8 | :body (str "

The requested uri is " (get req :uri) "

" "

reverse is " (uwsgi/rpc (into-array ["" "reverse" (get req :uri)])) "

" ) 9 | } 10 | ) 11 | -------------------------------------------------------------------------------- /t/ring/project.clj: -------------------------------------------------------------------------------- 1 | (defproject unbit/uwsgi-ring-tests "0.0.1" 2 | :description "uwsgi-ring-tests: test cases for uwsgi ring server" 3 | :dependencies [[org.clojure/clojure "1.4.0"] 4 | [compojure "1.1.5"] 5 | [ring/ring "1.1.0"]] 6 | 7 | :source-paths ["src"] 8 | 9 | :aot [uwsgi.ring.tests.app] 10 | ) 11 | -------------------------------------------------------------------------------- /contrib/upython: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | COMMAND=./uwsgi 4 | CONFIG_FILE= 5 | 6 | 7 | FIRST=0 8 | 9 | for ARG in $@;do 10 | if [ $FIRST -eq 0 ];then 11 | FIRST=1 12 | else 13 | ARGS="$ARGS $ARG" 14 | fi 15 | done 16 | 17 | export UWSGI_INHERIT=CONFIG_FILE 18 | export UWSGI_PYRUN=$1 19 | export UWSGI_PYARGV=$ARGS 20 | 21 | exec $COMMAND 22 | -------------------------------------------------------------------------------- /t/perl/active_workers_signal.pl: -------------------------------------------------------------------------------- 1 | #uwsgi --psgi t/perl/active_workers_signal.pl -s :3031 --perl-no-plack --timer "17 3" -p 8 --cheap --idle 10 2 | my $handler = sub { 3 | print "hello i am the signal handler on worker ".uwsgi::worker_id()."\n"; 4 | }; 5 | 6 | uwsgi::register_signal(17, 'active-workers', $handler); 7 | 8 | my $app = sub { 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /tests/sleeping_async.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | 3 | sleepvalue = 5 4 | 5 | 6 | def application(env, start_response): 7 | start_response('200 Ok', [('Content-type', 'text/html')]) 8 | yield uwsgi.async_sleep(sleepvalue) 9 | # print "TIMEOUT: ", env['x-wsgiorg.fdevent.timeout'] 10 | yield "

Hello World after %d seconds

" % sleepvalue 11 | -------------------------------------------------------------------------------- /plugins/pypy/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'pypy' 2 | 3 | LDFLAGS = [] 4 | LIBS = [] 5 | GCC_LIST = ['pypy_plugin'] 6 | BINARY_LIST = [ 7 | ('_uwsgi_pypy_setup', 'pypy_setup.py'), 8 | ] 9 | CFLAGS = [] 10 | try: 11 | import __pypy__ # NOQA 12 | import sys 13 | CFLAGS.append('-DUWSGI_PYPY_HOME="\\"%s\\""' % sys.prefix) 14 | except: 15 | pass 16 | -------------------------------------------------------------------------------- /t/perl/apps/input_with_offset.pl: -------------------------------------------------------------------------------- 1 | my $app = sub { 2 | my ($env) = @_; 3 | my $orig = $env->{QUERY_STRING}; 4 | if ($env->{CONTENT_LENGTH} > 0) { 5 | $env->{'psgi.input'}->read($orig, $env->{CONTENT_LENGTH}, $env->{HTTP_UWSGI_OFFSET}); 6 | } 7 | return [ 200, ['Content-Type' => 'text/plain'], [$orig."\n"]]; 8 | }; 9 | -------------------------------------------------------------------------------- /valgrind/README: -------------------------------------------------------------------------------- 1 | valgrind-generate-sups.sh 2 | ========================= 3 | 4 | This script can be used to generate valgrind suppression file. 5 | Valgrind will show a lot of python related errors, to filter them out You can: 6 | 7 | ./valgrind-generate-sups.sh > valgrind.suppression 8 | valgrind --tool=memcheck --suppressions=valgrind.suppression [ARGS] 9 | 10 | -------------------------------------------------------------------------------- /examples/simple_app_wsgi2.py: -------------------------------------------------------------------------------- 1 | 2 | def mygen(uri): 3 | for i in xrange(1, 100): 4 | yield "ciao %s
" % uri 5 | 6 | 7 | def application(env, start_response=None): 8 | return '200 OK', [('Content-Type', 'text/html')], "

This is the fastest homepage of the world !!!

" 9 | # return '200 OK', [('Content-Type', 'text/html')], mygen(env['PATH_INFO']) 10 | -------------------------------------------------------------------------------- /examples/uwsgirouter4.py: -------------------------------------------------------------------------------- 1 | 2 | import uwsgi 3 | 4 | 5 | def application(e, s): 6 | 7 | node = uwsgi.cluster_best_node() 8 | print node 9 | 10 | if not node: 11 | print "sorry node unavailable" 12 | raise StopIteration 13 | 14 | for part in uwsgi.send_message(node, 0, 0, e, 0, e['wsgi.input'].fileno(), uwsgi.cl()): 15 | yield part 16 | -------------------------------------------------------------------------------- /tests/sendchunked.py: -------------------------------------------------------------------------------- 1 | import socket 2 | import sys 3 | 4 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 5 | 6 | (addr, port) = sys.argv[1].split(':') 7 | s.connect((addr, int(port))) 8 | 9 | s.send("POST /send HTTP/1.1\r\n") 10 | s.send("Transfer-Encoding: chunked\r\n\r\n") 11 | 12 | while True: 13 | msg = raw_input("msg >> ") 14 | s.send("%X\r\n%s\r\n" % (len(msg), msg)) 15 | -------------------------------------------------------------------------------- /t/ring/src/uwsgi/ring/tests/simple.clj: -------------------------------------------------------------------------------- 1 | (ns uwsgi.ring.tests.simple 2 | (:use [compojure.core]) ) 3 | 4 | (defn hello [] "Hello, World!") 5 | 6 | (defn echo [msg] msg) 7 | 8 | (defn palindrome [msg] (clojure.string/reverse msg) ) 9 | 10 | (defroutes app-routes 11 | (GET "/hello" [] (hello) ) 12 | (GET "/echo" [msg] (echo msg) ) 13 | (GET "/palindrome" [msg] (palindrome msg) ) 14 | ) 15 | -------------------------------------------------------------------------------- /plugins/jwsgi/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'jwsgi' 2 | 3 | jvm_path = 'plugins/jvm' 4 | 5 | up = {} 6 | try: 7 | execfile('%s/uwsgiplugin.py' % jvm_path, up) 8 | except: 9 | f = open('%s/uwsgiplugin.py' % jvm_path) 10 | exec(f.read(), up) 11 | f.close() 12 | 13 | CFLAGS = up['CFLAGS'] 14 | CFLAGS.append('-I%s' % jvm_path) 15 | LDFLAGS = [] 16 | LIBS = [] 17 | GCC_LIST = ['jwsgi_plugin'] 18 | -------------------------------------------------------------------------------- /plugins/v8/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | NAME = 'v8' 4 | 5 | CFLAGS = ['-Wno-deprecated-declarations'] 6 | LDFLAGS = [] 7 | LIBS = ['-lstdc++', '-lv8'] 8 | engine = os.environ.get('UWSGICONFIG_V8_ENGINE', '') 9 | if engine == 'teajs': 10 | CFLAGS.append('-DUWSGI_V8_TEAJS -fexceptions') 11 | LIBS.append('-lteajs') 12 | GCC_LIST = ['plugin', 'v8_uwsgi.cc', 'v8_commonjs.cc', 'v8_jsgi.cc'] 13 | -------------------------------------------------------------------------------- /tests/runningthread.py: -------------------------------------------------------------------------------- 1 | from threading import Thread 2 | import time 3 | import uwsgi 4 | 5 | 6 | def mess(): 7 | while True: 8 | for i in xrange(0, 100): 9 | if uwsgi.ready(): 10 | uwsgi.signal(17) 11 | print(i) 12 | time.sleep(0.1) 13 | 14 | t = Thread(target=mess) 15 | t.daemon = True 16 | t.start() 17 | 18 | print("thread started") 19 | -------------------------------------------------------------------------------- /tests/testpy3.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | 3 | 4 | def app1(e, sr): 5 | print(e) 6 | sr('200 Ok', [('Content-Type', 'text/plain')]) 7 | return b'i Am a Python 3.x bytestring' 8 | 9 | 10 | def app2(e, sr): 11 | print(e) 12 | sr('404 Not Found', [('Content-Type', 'text/plain')]) 13 | return b'i Am a Python 3.x Not Found page' 14 | 15 | uwsgi.applications = {b'': app1, b'/test': app2} 16 | -------------------------------------------------------------------------------- /plugins/echo/echo_plugin.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern struct uwsgi_server uwsgi; 4 | 5 | static int uwsgi_echo_request(struct wsgi_request *wsgi_req) { 6 | 7 | return uwsgi_response_write_body_do(wsgi_req, wsgi_req->buffer, wsgi_req->len); 8 | } 9 | 10 | struct uwsgi_plugin echo_plugin = { 11 | 12 | .name = "echo", 13 | .modifier1 = 101, 14 | 15 | .request = uwsgi_echo_request, 16 | }; 17 | -------------------------------------------------------------------------------- /plugins/servlet/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | NAME = 'servlet' 2 | 3 | jvm_path = 'plugins/jvm' 4 | 5 | up = {} 6 | try: 7 | execfile('%s/uwsgiplugin.py' % jvm_path, up) 8 | except: 9 | f = open('%s/uwsgiplugin.py' % jvm_path) 10 | exec(f.read(), up) 11 | f.close() 12 | 13 | CFLAGS = up['CFLAGS'] 14 | CFLAGS.append('-I%s' % jvm_path) 15 | LDFLAGS = [] 16 | LIBS = [] 17 | GCC_LIST = ['servlet_plugin'] 18 | -------------------------------------------------------------------------------- /t/ring/README.md: -------------------------------------------------------------------------------- 1 | Ring Test Suite 2 | ================ 3 | 4 | how to build and run 5 | --------------------- 6 | 7 | * cd UWSGIROOT 8 | * cd t/ring 9 | * lein uberjar 10 | * cd ../.. 11 | * uwsgi t/ring/config.ini 12 | * open http://localhost:9090 in your browser 13 | 14 | run cases in jetty 15 | ------------------- 16 | 17 | * lein ring server 18 | * open http://localhost:3000 in your browser 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /tests/cpubound_stackless.py: -------------------------------------------------------------------------------- 1 | import time 2 | import stackless 3 | 4 | 5 | def application(env, start_response): 6 | start_response('200 OK', [('Content-Type', 'text/html')]) 7 | 8 | for i in range(1, 100000): 9 | yield "

%s at %s

\n" % (i, str(time.time())) 10 | # schedule every 2 11 | if i % 2 == 0: 12 | stackless.schedule() 13 | 14 | print "DONE AT %d" % i 15 | -------------------------------------------------------------------------------- /vassals/broodlord.ini: -------------------------------------------------------------------------------- 1 | [uwsgi] 2 | 3 | socket = :3031 4 | master = true 5 | vassal-sos-backlog = 10 6 | module = werkzeug.testapp:test_app 7 | processes = 1 8 | zerg-server = /tmp/broodlord.sock 9 | disable-logging = true 10 | 11 | 12 | [zerg] 13 | zerg = /tmp/broodlord.sock 14 | master = true 15 | module = werkzeug.testapp:test_app 16 | processes = 1 17 | disable-logging = true 18 | idle = 30 19 | die-on-idle = true 20 | -------------------------------------------------------------------------------- /contrib/pyuwsgi.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | import pyuwsgi 4 | 5 | orig_args = sys.argv 6 | orig_executable = sys.executable 7 | orig_args.insert(0, orig_executable) 8 | 9 | uwsgi_args = [] 10 | 11 | for arg in sys.argv[2:]: 12 | uwsgi_args.append(arg) 13 | 14 | # pyuwsgi.run('welcome.ini') 15 | pyuwsgi.run(uwsgi_args) 16 | 17 | # if you are here uWSGI has been reloaded 18 | os.execv(orig_executable, orig_args) 19 | -------------------------------------------------------------------------------- /plugins/emperor_pg/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | NAME = 'emperor_pg' 4 | 5 | CFLAGS = os.popen('pg_config --cflags').read().rstrip().split() 6 | CFLAGS.append('-I' + os.popen('pg_config --includedir').read().rstrip()) 7 | LDFLAGS = os.popen('pg_config --ldflags').read().rstrip().split() 8 | LIBS = [ 9 | '-L' + os.popen('pg_config --libdir').read().rstrip(), 10 | '-lpq' 11 | ] 12 | 13 | GCC_LIST = ['emperor_pg'] 14 | -------------------------------------------------------------------------------- /t/python/spooler_priority/spooler_priority_constants.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python2 2 | # coding = utf-8 3 | 4 | tasks = [ 5 | (101, "101"), 6 | (101, "101Bis"), 7 | (2, "2"), 8 | (1, "1"), 9 | (0, "0"), 10 | (None, "NoPriority") 11 | ] 12 | 13 | ordered_tasks = [ 14 | "0", 15 | "1", 16 | "2", 17 | "101", 18 | "101Bis", 19 | "NoPriority" 20 | ] 21 | 22 | LOGFILE = "/tmp/spoolerlog" 23 | -------------------------------------------------------------------------------- /contrib/upstart/uwsgi.conf: -------------------------------------------------------------------------------- 1 | # uWSGI - manage uWSGI application server 2 | # 3 | 4 | description "uWSGI" 5 | 6 | start on runlevel [2345] 7 | stop on runlevel [!2345] 8 | 9 | respawn 10 | 11 | env LOGTO=/tmp/uwsgi.log 12 | env BINPATH=/home/foo/uwsgi/uwsgi 13 | 14 | # --die-on-term is upstart friendly 15 | exec $BINPATH --die-on-term --socket :3033 --uid 1001 --gid 1001 --limit-as 256 -w simple_app --logto $LOGTO -M -p 4 16 | 17 | -------------------------------------------------------------------------------- /t/java/rpc.java: -------------------------------------------------------------------------------- 1 | public class rpc { 2 | public static Object[] application(java.util.HashMap env) { 3 | String rpc_out = uwsgi.rpc("", "reverse", (String) env.get("REQUEST_URI")); 4 | 5 | java.util.HashMap headers = new java.util.HashMap(); 6 | headers.put("Content-Type", "text/html"); 7 | 8 | Object[] response = { 200, headers, "

" + rpc_out + "

"}; 9 | return response; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/stats_pusher_mongodb/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | NAME = 'stats_pusher_mongodb' 4 | 5 | CFLAGS = [ 6 | '-I/usr/include/mongo', 7 | '-I/usr/local/include/mongo', 8 | ] 9 | LDFLAGS = [] 10 | 11 | LIBS = [] 12 | if 'UWSGI_MONGODB_NOLIB' not in os.environ: 13 | LIBS.append('-lmongoclient') 14 | LIBS.append('-lboost_thread') 15 | LIBS.append('-lboost_filesystem') 16 | 17 | GCC_LIST = ['plugin', 'stats_pusher_mongodb.cc'] 18 | -------------------------------------------------------------------------------- /plugins/stats_pusher_mongodb/plugin.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void stats_pusher_mongodb(struct uwsgi_stats_pusher_instance *, time_t, char *, size_t); 4 | 5 | static void stats_pusher_mongodb_init(void) { 6 | uwsgi_register_stats_pusher("mongodb", stats_pusher_mongodb); 7 | } 8 | 9 | struct uwsgi_plugin stats_pusher_mongodb_plugin = { 10 | 11 | .name = "stats_pusher_mongodb", 12 | .on_load = stats_pusher_mongodb_init, 13 | }; 14 | 15 | -------------------------------------------------------------------------------- /plugins/systemd_logger/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | NAME = 'systemd_logger' 4 | 5 | CFLAGS = os.popen('pkg-config --cflags libsystemd-journal').read().rstrip().split() 6 | CFLAGS += os.popen('pkg-config --cflags libsystemd').read().rstrip().split() 7 | LDFLAGS = [] 8 | LIBS = os.popen('pkg-config --libs libsystemd-journal').read().rstrip().split() 9 | LIBS += os.popen('pkg-config --libs libsystemd').read().rstrip().split() 10 | GCC_LIST = ['systemd_logger'] 11 | -------------------------------------------------------------------------------- /tests/sharedarea.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | 3 | uwsgi.sharedarea_writelong(173, 30) 4 | 5 | 6 | def application(e, sr): 7 | 8 | sr('200 Ok', [('Content-Type', 'text/html')]) 9 | 10 | uwsgi.sharedarea_write(17, e['REQUEST_URI']) 11 | 12 | uwsgi.sharedarea_inclong(173) 13 | uwsgi.sharedarea_inclong(173, 17) 14 | 15 | yield uwsgi.sharedarea_read(17, len(e['REQUEST_URI'])) 16 | yield "
" 17 | yield str(uwsgi.sharedarea_readlong(173)) 18 | -------------------------------------------------------------------------------- /tests/staticfile.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | content_type = 'image/png' 4 | filename = 'logo_uWSGI.png' 5 | 6 | try: 7 | filename = sys.argv[1] 8 | except: 9 | pass 10 | 11 | try: 12 | content_type = sys.argv[2] 13 | except: 14 | pass 15 | 16 | 17 | def application(environ, start_response): 18 | start_response('200 OK', [('Content-Type', content_type)]) 19 | fd = open(filename, 'r') 20 | yield environ['wsgi.file_wrapper'](fd, 32*1024) 21 | -------------------------------------------------------------------------------- /tests/sleepthreadasync.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | import threading 3 | import time 4 | 5 | 6 | def foo(): 7 | while True: 8 | time.sleep(1) 9 | print "ciao, sono un thread" 10 | 11 | t = threading.Thread(target=foo) 12 | t.daemon = True 13 | t.start() 14 | 15 | 16 | def application(e, s): 17 | s('200 OK', [('Content-Type', 'text/html')]) 18 | for i in range(0, 3): 19 | yield uwsgi.async_sleep(1) 20 | yield "iter: %d
" % i 21 | -------------------------------------------------------------------------------- /plugins/gccgo/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | NAME = 'gccgo' 4 | 5 | CFLAGS = ['-g'] 6 | LDFLAGS = [] 7 | LIBS = ['-lgo'] 8 | GCC_LIST = ['gccgo_plugin', 'uwsgi.go'] 9 | 10 | 11 | def post_build(config): 12 | if os.path.exists('plugins/gccgo/uwsgi.go.o'): 13 | if os.system("objcopy -j .go_export plugins/gccgo/uwsgi.go.o plugins/gccgo/uwsgi.gox") != 0: 14 | os._exit(1) 15 | print("*** uwsgi.gox available in %s/plugins/gccgo ***" % os.getcwd()) 16 | -------------------------------------------------------------------------------- /tests/myadmin.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | import struct 3 | import sys 4 | 5 | print sys.argv 6 | if len(sys.argv) == 3: 7 | chunks = uwsgi.send_message(sys.argv[1], 10, int(sys.argv[2]), '') 8 | 9 | pkt = '' 10 | 11 | for chunk in chunks: 12 | pkt += chunk 13 | 14 | print "%d = %d" % (int(sys.argv[2]), struct.unpack("I", pkt)[0]) 15 | elif len(sys.argv) == 4: 16 | uwsgi.send_message(sys.argv[1], 10, int(sys.argv[2]), struct.pack("I", int(sys.argv[3]))) 17 | -------------------------------------------------------------------------------- /contrib/xinetd_uwsgi: -------------------------------------------------------------------------------- 1 | service uwsgi 2 | { 3 | disable = no 4 | id = uwsgi-000 5 | type = UNLISTED 6 | socket_type = stream 7 | server = /root/uwsgi/uwsgi 8 | server_args = --chdir /root/uwsgi/ --module welcome --logto /tmp/uwsgi.log 9 | port = 3031 10 | bind = 127.0.0.1 11 | user = root 12 | wait = yes 13 | } 14 | 15 | -------------------------------------------------------------------------------- /tests/testsignals.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | 3 | # send a raw signal to register with file_monitor subsystem 4 | # uwsgi.signal(10, "/tmp/topolino") 5 | uwsgi.signal(10, "/tmp") 6 | # uwsgi.signal(10, "/root") 7 | 8 | # send a raw signal to register with timer subsystem 9 | uwsgi.signal(11, "3") 10 | uwsgi.signal(11, "4") 11 | uwsgi.signal(11, "8") 12 | 13 | 14 | def application(e, s): 15 | s('200 Ok', [('Content-Type', 'text/html')]) 16 | return "

Hello World

" 17 | -------------------------------------------------------------------------------- /examples/mojoapp.pl: -------------------------------------------------------------------------------- 1 | use Mojolicious::Lite; 2 | 3 | # / 4 | get '/' => 'index'; 5 | 6 | # /* 7 | get '/:groovy' => sub { 8 | my $self = shift; 9 | $self->render_text($self->param('groovy'), layout => 'funky'); 10 | }; 11 | 12 | app->start('psgi'); 13 | __DATA__ 14 | 15 | @@ index.html.ep 16 | % layout 'funky'; 17 | Yea baby! 18 | 19 | @@ layouts/funky.html.ep 20 | 21 | Funky! 22 | <%= content %> 23 | 24 | -------------------------------------------------------------------------------- /t/python/spooler_decorators/spooler_decorator_test.ini: -------------------------------------------------------------------------------- 1 | [uwsgi] 2 | socket = /tmp/temporary_socket 3 | 4 | ; Spooler! 5 | 6 | spooler-import = %d/spooler_handlers.py 7 | ; Specify the spooler 8 | spooler = $(SPOOLER_DIR) 9 | ; And the number of processes 10 | spooler-processes = 1 11 | ; Spooler ordered scanning (only works with "numbered" dirs) 12 | spooler-ordered = 1 13 | ; Spooler frequency 14 | spooler-frequency = 1 15 | 16 | pyrun = %d/spooler_decorator_tests.py 17 | master = 1 18 | 19 | -------------------------------------------------------------------------------- /tests/streamer.psgi: -------------------------------------------------------------------------------- 1 | sub streamer { 2 | my $responder = shift; 3 | 4 | my $writer = $responder->([ 200, [ 'Content-Type', 'text/html' ]]); 5 | 6 | my @chunks = ('One', 'Two', 'Three'); 7 | 8 | foreach(@chunks) { 9 | uwsgi::async_sleep(1); 10 | # something like $env->{'psgix.suspend'}(); ??? 11 | uwsgi::suspend(); 12 | $writer->write($_."
"); 13 | } 14 | 15 | $writer->close; 16 | 17 | } 18 | my $app = sub { 19 | 20 | my $env = shift; 21 | 22 | return \&streamer; 23 | }; 24 | -------------------------------------------------------------------------------- /plugins/cplusplus/plugin.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int uwsgi_cplusplus_init(void); 5 | int uwsgi_cplusplus_request(struct wsgi_request *); 6 | void uwsgi_cplusplus_after_request(struct wsgi_request *); 7 | 8 | struct uwsgi_plugin cplusplus_plugin = { 9 | 10 | .name = "cplusplus", 11 | .modifier1 = 250, 12 | .init = uwsgi_cplusplus_init, 13 | .request = uwsgi_cplusplus_request, 14 | .after_request = uwsgi_cplusplus_after_request, 15 | 16 | }; 17 | 18 | -------------------------------------------------------------------------------- /t/sharedarea/bigranges.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | import unittest 3 | 4 | class SharedareaTest(unittest.TestCase): 5 | 6 | def test_32(self): 7 | pos = 2L * (1024L ** 3) 8 | uwsgi.sharedarea_write32(0, pos, 17) 9 | self.assertEqual(uwsgi.sharedarea_read32(0, pos), 17) 10 | 11 | def test_64(self): 12 | pos = 2L * (1024L ** 3) 13 | uwsgi.sharedarea_write64(0, pos, 30) 14 | self.assertEqual(uwsgi.sharedarea_read64(0, pos), 30) 15 | 16 | unittest.main() 17 | -------------------------------------------------------------------------------- /tests/cpubound_green.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | import time 3 | 4 | 5 | def application(env, start_response): 6 | counter = 0 7 | start_response('200 OK', [('Content-Type', 'text/html')]) 8 | start_time = time.time() 9 | for i in range(1, 100000): 10 | uwsgi.suspend() 11 | # print every 100 12 | if i % 100 == 0: 13 | yield "

%d

\n" % i 14 | counter = counter + i 15 | 16 | yield "

%d cycles after %d

\n" % (counter, time.time() - start_time) 17 | -------------------------------------------------------------------------------- /examples/mega.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ciao 6 | ciao 7 | 8 | 9 | 10 | 11 | :3333 12 | trac.web.main:dispatch_request 13 | ciao 14 | TRAC_ENV=/root/uwsgi/utrac 15 | 16 | 17 | 18 | :4444 19 | trac.web.main:dispatch_request 20 | 21 | 22 | 23 | :3031 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /plugins/psgi/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | NAME = 'psgi' 4 | CFLAGS = os.popen('perl -MExtUtils::Embed -e ccopts').read().rstrip().split() 5 | LDFLAGS = os.popen('perl -MExtUtils::Embed -e ldopts').read().rstrip().split() 6 | LIBS = [] 7 | for lib in LDFLAGS: 8 | if lib.startswith('-l'): 9 | LIBS.append(lib) 10 | 11 | GCC_LIST = ['uwsgi_plmodule', 'psgi_loader', 'psgi_response', 'psgi_plugin'] 12 | 13 | for item in LDFLAGS: 14 | if item.endswith('DynaLoader.a'): 15 | GCC_LIST.append(item) 16 | -------------------------------------------------------------------------------- /t/python/spooler_priority/spooler_priority_test.ini: -------------------------------------------------------------------------------- 1 | [uwsgi] 2 | socket = /tmp/temporary-socket 3 | 4 | ; Specify the spooler 5 | spooler = %d/temporary_spooler 6 | ; Spooler handler 7 | spooler-import = %d/spooler_priority_handler.py 8 | ; And the number of processes 9 | spooler-processes = 1 10 | ; Spooler ordered scanning (only works with "numbered" dirs) 11 | spooler-ordered = 1 12 | ; Spooler scans folder each second 13 | spooler-frequency = 1 14 | 15 | pyrun = %d/spooler_priority_test.py 16 | master = 1 17 | 18 | -------------------------------------------------------------------------------- /tests/fileserve_async.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import mimetypes 3 | 4 | basedir = sys.argv[1] 5 | mimetypes.init() 6 | 7 | 8 | def application(environ, start_response): 9 | 10 | filename = basedir + environ['PATH_INFO'] 11 | (content_type, encoding) = mimetypes.guess_type(filename) 12 | if not content_type: 13 | content_type = 'text/plain' 14 | 15 | start_response('200 OK', [('Content-Type', content_type)]) 16 | fd = open(filename, 'r') 17 | yield environ['wsgi.file_wrapper'](fd, 32*1024) 18 | -------------------------------------------------------------------------------- /plugins/gridfs/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | NAME = 'gridfs' 4 | 5 | CFLAGS = ['-I/usr/include/mongo', '-I/usr/local/include/mongo', '-std=c++11', '-Wno-error'] 6 | LDFLAGS = [] 7 | 8 | LIBS = [] 9 | if 'UWSGI_MONGODB_NOLIB' not in os.environ: 10 | LIBS.append('-lmongoclient') 11 | LIBS.append('-lstdc++') 12 | LIBS.append('-lboost_thread') 13 | LIBS.append('-lboost_system') 14 | LIBS.append('-lboost_filesystem') 15 | LIBS.append('-lboost_regex') 16 | 17 | GCC_LIST = ['plugin', 'gridfs.cc'] 18 | -------------------------------------------------------------------------------- /tests/rpc.lua: -------------------------------------------------------------------------------- 1 | function hello() 2 | return "Hello i am Lua" 3 | end 4 | 5 | function hello2() 6 | return "Hello i am Lua [2]" 7 | end 8 | 9 | function hello3(arg1) 10 | return "Hello i am a Lua function with 1 arg "..arg1 11 | end 12 | 13 | function hello4(arg1, arg2) 14 | return "Hello i am a Lua function with 2 args "..arg1.." "..arg2 15 | end 16 | 17 | uwsgi.register_rpc("hello", hello) 18 | uwsgi.register_rpc("hello2", hello2) 19 | uwsgi.register_rpc("hello3", hello3) 20 | uwsgi.register_rpc("hello4", hello4) 21 | -------------------------------------------------------------------------------- /examples/protected.ini: -------------------------------------------------------------------------------- 1 | [uwsgi] 2 | 3 | http-socket = :9090 4 | 5 | route = ^/foo basicauth:foobar,kratos: 6 | 7 | ; a simple user:passowrd mapping 8 | route = .* basicauth:nether realm 3,serena:alessandro 9 | ; htpasswd-like real-time parsing 10 | route = .* basicauth:nether realm 2,.htpasswd 11 | ; user-only auth 12 | route = .* basicauth:nether realm 4,roberta: 13 | route = .* basicauth:nether realm 4, 14 | 15 | route = ^/bar basicauth:foobar,kratos: 16 | 17 | 18 | 19 | module = welcome 20 | processes = 4 21 | master = true 22 | -------------------------------------------------------------------------------- /t/webdav/carddav.ini: -------------------------------------------------------------------------------- 1 | #! uwsgi -S addressbook=./carddav carddav.ini 2 | [uwsgi] 3 | plugin = webdav 4 | 5 | http-socket = :9090 6 | http-socket-modifier1 = 35 7 | 8 | route-run = basicauth:CardDav uWSGI server,unbit:unbit 9 | 10 | webdav-add-option = addressbook 11 | webdav-principal-base = /principals/users/ 12 | 13 | webdav-add-prop-href = urn:ietf:params:xml:ns:carddav addressbook-home-set /principals/users/unbit 14 | webdav-add-rtype-collection-prop = urn:ietf:params:xml:ns:carddav addressbook 15 | webdav-mount = %(addressbook) 16 | 17 | -------------------------------------------------------------------------------- /tests/gevent_spool.py: -------------------------------------------------------------------------------- 1 | from uwsgidecorators import * 2 | import gevent 3 | 4 | 5 | @spool 6 | def longtask(*args): 7 | print args 8 | return uwsgi.SPOOL_OK 9 | 10 | 11 | def level2(): 12 | longtask.spool(foo='bar', test1='test2') 13 | 14 | 15 | def level1(): 16 | gevent.spawn(level2) 17 | 18 | 19 | def application(environ, start_response): 20 | start_response('200 OK', [('Content-Type', 'text/html')]) 21 | 22 | gevent.spawn(level1) 23 | 24 | for i in range(100): 25 | yield "counter: %d
" % i 26 | -------------------------------------------------------------------------------- /tests/sleeping_green.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | import time 3 | 4 | 5 | def application(env, start_response): 6 | sleepvalue = 5 7 | if 'QUERY_STRING' in env: 8 | if env['QUERY_STRING'] != '': 9 | sleepvalue = int(env['QUERY_STRING']) 10 | start_response('200 Ok', [('Content-type', 'text/html')]) 11 | start_at = time.time() 12 | uwsgi.green_sleep(sleepvalue) 13 | # print "TIMEOUT: ", env['x-wsgiorg.fdevent.timeout'] 14 | yield "

Hello World after %s seconds

" % str(time.time() - start_at) 15 | -------------------------------------------------------------------------------- /contrib/subscribe.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use IO::Socket::INET; 4 | 5 | my %items = {}; 6 | 7 | $items{'key'} = $ARGV[1]; 8 | $items{'address'} = $ARGV[2]; 9 | 10 | my $uwsgi_pkt = ''; 11 | 12 | foreach(keys %items) { 13 | $uwsgi_pkt .= pack('v', length($_)).$_.pack('v', length($items{$_})).$items{$_}; 14 | } 15 | 16 | my $udp = new IO::Socket::INET(PeerAddr => $ARGV[0], Proto => 'udp'); 17 | 18 | $udp->send(pack('CvC', 224, length($uwsgi_pkt), 0).$uwsgi_pkt); 19 | 20 | print ''.(length($uwsgi_pkt)+4).' bytes sent to '.$ARGV[0]."\n"; 21 | -------------------------------------------------------------------------------- /examples/staticfilesnmp.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | from os import path 3 | 4 | uwsgi.snmp_set_counter64(1, 0) # Number of requests 5 | uwsgi.snmp_set_counter64(2, 0) # Number of bytes 6 | 7 | 8 | def application(environ, start_response): 9 | size = path.getsize('logo_uWSGI.png') 10 | start_response('200 OK', [('Content-Type', 'image/png'), ('Content-Length', str(size))]) 11 | fd = open('logo_uWSGI.png', 'r') 12 | uwsgi.snmp_incr_counter64(1) 13 | uwsgi.snmp_incr_counter64(2, size) 14 | return environ['wsgi.file_wrapper'](fd, 4096) 15 | -------------------------------------------------------------------------------- /t/xslt/cd.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Quintessence 6 | Borknagar 7 | 8 | 9 | Torn Beyond Reason 10 | Woods Of Desolation 11 | 12 | 13 | Autumn Aurora 14 | Drudkh 15 | 16 | 17 | Om 18 | Negura Bunget 19 | 20 | 21 | Frostnacht 22 | Helrunar 23 | 24 | 25 | -------------------------------------------------------------------------------- /examples/heavytest.ini: -------------------------------------------------------------------------------- 1 | [uwsgi] 2 | 3 | master = true 4 | processes = 4 5 | threads = 8 6 | 7 | ; initialize 4 sockets with 4 different protocols 8 | socket = :3031 9 | socket = :3032 10 | socket = :3033 11 | socket = :3034 12 | 13 | socket-protocol = 0,uwsgi 14 | socket-protocol = 1,http 15 | socket-protocol = 2,fastcgi 16 | socket-protocol = 3,uwsgidump 17 | 18 | 19 | ; add a cache with 1000 items of 96k 20 | cache = 1000 21 | cache-blocksize = 98304 22 | 23 | 24 | log-micros = true 25 | 26 | module = heavytest 27 | mount = /cc=uwsgicc/__init__.py 28 | -------------------------------------------------------------------------------- /tests/spoolme.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | import time 3 | 4 | 5 | def slow_task(args): 6 | time.sleep(10) 7 | return uwsgi.SPOOL_OK 8 | 9 | uwsgi.spooler = slow_task 10 | 11 | 12 | def application(env, start_response): 13 | 14 | name = uwsgi.spool({ 15 | 'Hello': 'World', 16 | 'I am a': 'long running task' 17 | }) 18 | print("spooled as %s" % name) 19 | 20 | start_response('200 Ok', [ 21 | ('Content-Type', 'text/plain'), 22 | ('uWSGI-Status', 'spooled'), 23 | ]) 24 | 25 | return "task spooled" 26 | -------------------------------------------------------------------------------- /examples/sites.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | :3031 4 | 5 | 4 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | TRAC_ENV=/Users/roberto/uapps/utrac 15 | 16 | 17 | 18 | 19 | 20 | /Users/roberto/uwsgi/config.ru 21 | 22 | 23 | -------------------------------------------------------------------------------- /contrib/launchd/it.unbit.uwsgi.emperor.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Label 6 | it.unbit.uwsgi.emperor 7 | ProgramArguments 8 | 9 | /Users/roberta/uwsgi/uwsgi 10 | --emperor 11 | /Users/*/Library/uwsgi/*.{xml,ini,yml,yaml,js} 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/flaskpost.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, request 2 | app = Flask(__name__) 3 | app.debug = True 4 | 5 | 6 | @app.route('/') 7 | def hello_world(): 8 | return "
" 9 | 10 | 11 | @app.route('/upload', methods=['GET', 'POST']) 12 | def upload_file(): 13 | return str(len(request.form.get('pippo', 'boh'))) + request.form.get('pippo', 'boh') 14 | return request.files['ufile'].read() 15 | -------------------------------------------------------------------------------- /plugins/emperor_mongodb/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | NAME = 'emperor_mongodb' 4 | 5 | CFLAGS = [ 6 | '-I/usr/include/mongo', 7 | '-I/usr/local/include/mongo', 8 | '-std=c++11', 9 | '-Wno-error' 10 | ] 11 | LDFLAGS = [] 12 | 13 | LIBS = ['-lstdc++'] 14 | if 'UWSGI_MONGODB_NOLIB' not in os.environ: 15 | LIBS.append('-lmongoclient') 16 | LIBS.append('-lboost_thread') 17 | LIBS.append('-lboost_filesystem') 18 | LIBS.append('-lboost_system') 19 | LIBS.append('-lboost_regex') 20 | 21 | 22 | GCC_LIST = ['plugin', 'emperor_mongodb.cc'] 23 | -------------------------------------------------------------------------------- /valgrind/valgrind-generate-sups.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | gensup() { 5 | for SUP in Cond Free Leak Overlap Addr1 Addr2 Addr4 Addr8 Addr16 Value1 Value2 Value4 Value8 Value16 ; do 6 | echo " 7 | { 8 | Autogenerated $1 suppression 9 | Memcheck:${SUP} 10 | obj:$2 11 | } 12 | " 13 | done 14 | } 15 | 16 | 17 | while read SO ; do 18 | gensup libpython "$SO" 19 | done < <(find /usr/lib*/ -type f -name libpython*) 20 | 21 | 22 | while read SO ; do 23 | gensup python "$SO" 24 | done < <(find /usr/lib*/python*/ -type f -name \*.so) 25 | 26 | -------------------------------------------------------------------------------- /contrib/cryptologger.rb: -------------------------------------------------------------------------------- 1 | require 'socket' 2 | require 'openssl' 3 | 4 | secret = 'ciaociao' 5 | iv = '' 6 | address = '127.0.0.1' 7 | port = 1717 8 | algo = 'bf-cbc' 9 | 10 | s = UDPSocket.new 11 | s.bind(address, port) 12 | cipher = OpenSSL::Cipher.new(algo) 13 | cipher.decrypt 14 | cipher.key = secret + ("\0" * (cipher.key_len - secret.length)) 15 | cipher.iv = iv + ("0" * (cipher.iv_len - iv.length)) 16 | 17 | loop do 18 | msg, sender = s.recvfrom(8192) 19 | cipher.reset 20 | begin 21 | puts cipher.update(msg) + cipher.final 22 | rescue 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /contrib/loadapp.pl: -------------------------------------------------------------------------------- 1 | use IO::Socket::INET; 2 | 3 | my $s = IO::Socket::INET->new(PeerAddr => '127.0.0.1', PeerPort => $ARGV[0]); 4 | 5 | my $mountpoint = $ARGV[1]; 6 | my $app = $ARGV[2]; 7 | 8 | my $uwsgi_appid = pack('v', length('UWSGI_APPID')).'UWSGI_APPID'.pack('v', length($mountpoint)).$mountpoint; 9 | my $uwsgi_script = pack('v', length('UWSGI_SCRIPT')).'UWSGI_SCRIPT'.pack('v', length($app)).$app; 10 | 11 | $s->send(pack('CvC', 5, length($uwsgi_appid.$uwsgi_script),0).$uwsgi_appid.$uwsgi_script); 12 | 13 | while((my $cnt = $s->recv(my $buf, 4096))> 0) { 14 | print $buf; 15 | } 16 | -------------------------------------------------------------------------------- /tests/mako_ugreen.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | 3 | from mako.template import Template 4 | import time 5 | 6 | 7 | def application(env, start_response): 8 | start_response('200 OK', [('Content-Type', 'text/html')]) 9 | 10 | mytemplate = Template("

I am Mako at ${thetime}

") 11 | uwsgi.green_schedule() 12 | 13 | yield mytemplate.render(thetime=time.time()) 14 | 15 | for i in range(1, 100): 16 | mytemplate = Template("Iteration ${thei} at ${thetime}
") 17 | uwsgi.green_schedule() 18 | yield mytemplate.render(thei=i, thetime=time.time()) 19 | -------------------------------------------------------------------------------- /examples/uwsgirouter3.py: -------------------------------------------------------------------------------- 1 | 2 | import uwsgi 3 | 4 | current_node = 0 5 | 6 | 7 | def application(e, s): 8 | 9 | global current_node 10 | 11 | nodes = uwsgi.cluster_nodes() 12 | print nodes 13 | 14 | if len(nodes) == 0: 15 | print "no cluster node available" 16 | raise StopIteration 17 | 18 | if current_node >= len(nodes): 19 | current_node = 0 20 | 21 | node = nodes[current_node] 22 | 23 | for part in uwsgi.send_message(node, 0, 0, e, 0, e['wsgi.input'].fileno(), uwsgi.cl()): 24 | yield part 25 | 26 | current_node += 1 27 | -------------------------------------------------------------------------------- /examples/multi.ini: -------------------------------------------------------------------------------- 1 | [uwsgi] 2 | 3 | ; socket 0 4 | socket = :3033 5 | ; socket 1 6 | socket = :3034 7 | ; socket 2 8 | socket = pippo1.sock 9 | ; socket 3 10 | socket = pippo2.sock 11 | ; socket 4 12 | socket = 127.0.0.1:1717 13 | 14 | map-socket = 0:1,2,3,4 15 | map-socket = 1:4 16 | map-socket = 2:10 17 | map-socket = 3:5,6,9 18 | map-socket = 4:7,8,9 19 | 20 | 21 | vacuum = true 22 | memory-report = true 23 | master = true 24 | processes = 10 25 | ;mount = /app1=werkzeug.testapp:test_app 26 | ;mount = /app2=config:/Users/roberta/uwsgi/my.ini 27 | ;mount = /app3=pinaxsite/deploy/pinax.wsgi 28 | -------------------------------------------------------------------------------- /examples/xmlindex.ini: -------------------------------------------------------------------------------- 1 | [uwsgi] 2 | plugin = 0:notfound, router_xmldir, xslt 3 | http-socket = :8080 4 | 5 | docroot = . 6 | check-static = %(docroot) 7 | 8 | route-if = isdir:%(docroot)/${PATH_INFO} goto:index 9 | route-run = last: 10 | 11 | route-label = index 12 | ; uncomment to link CSS stylesheet /css/default.css 13 | ;route-run = toxslt:stylesheet=examples/xmlindex-html.xsl,params=stylesheet=/css/default.css,content_type=text/html 14 | ; use embedded CSS 15 | route-run = toxslt:stylesheet=examples/xmlindex-html.xsl,params=stylesheet=,content_type=text/html 16 | route-run = xmldir:%(docroot)/${PATH_INFO} 17 | 18 | -------------------------------------------------------------------------------- /t/lua/basic.lua: -------------------------------------------------------------------------------- 1 | function hello(wsapi_env) 2 | local headers = { ["Content-type"] = "text/html", ["set-cookie"] = {"foo=bar", "bar=baz"} } 3 | local function hello_text() 4 | coroutine.yield("") 5 | coroutine.yield("

Hello Wsapi!

") 6 | coroutine.yield("

PATH_INFO: " .. wsapi_env.PATH_INFO .. "

") 7 | coroutine.yield("

SCRIPT_NAME: " .. wsapi_env.SCRIPT_NAME .. "

") 8 | coroutine.yield("

QUERY_STRING: " .. wsapi_env.QUERY_STRING .. "

") 9 | coroutine.yield("") 10 | end 11 | return 200, headers, coroutine.wrap(hello_text) 12 | end 13 | 14 | return hello 15 | -------------------------------------------------------------------------------- /uwsgi.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |s| 2 | s.name = 'uwsgi' 3 | s.license = 'GPL-2' 4 | s.version = `python -c "import uwsgiconfig as uc; print uc.uwsgi_version"`.sub(/-dev-.*/,'') 5 | s.date = '2014-09-05' 6 | s.summary = "uWSGI" 7 | s.description = "The uWSGI server for Ruby/Rack" 8 | s.authors = ["Unbit"] 9 | s.email = 'info@unbit.it' 10 | s.extensions = ['ext/uwsgi/extconf.rb'] 11 | s.files = [] 12 | s.require_paths = ['.'] 13 | s.executables << 'uwsgi' 14 | s.homepage = 'http://projects.unbit.it/uwsgi' 15 | s.add_runtime_dependency 'rack' 16 | end 17 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | echo "*** uWSGI installer ***" 2 | if [ $# -ne 2 ] 3 | then 4 | echo "Usage: install.sh " 5 | exit 1 6 | fi 7 | 8 | if [ ${2:0:1} != "/" ] 9 | then 10 | echo "uWSGI binary path must be absolute !!!" 11 | exit 1 12 | fi 13 | 14 | echo "downloading latest uWSGI tarball..." 15 | curl -o uwsgi_latest_from_installer.tar.gz http://projects.unbit.it/downloads/uwsgi-latest.tar.gz 16 | mkdir uwsgi_latest_from_installer 17 | tar zvxC uwsgi_latest_from_installer --strip-components=1 -f uwsgi_latest_from_installer.tar.gz 18 | cd uwsgi_latest_from_installer 19 | UWSGI_PROFILE="$1" UWSGI_BIN_NAME="$2" make 20 | -------------------------------------------------------------------------------- /t/perl/test_sleepy.psgi: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | use Time::HiRes qw(usleep); 4 | 5 | sub { 6 | my $env = shift; 7 | 8 | die "PANIC: We are expecting to support psgix.cleanup" unless $env->{'psgix.cleanup'}; 9 | my $msleep = 2 * 1000 + int rand 7 * 1000; # 2..10ms 10 | my $csleep = 2 * 1000 + int rand 7 * 1000; # 2..10ms 11 | 12 | push @{$env->{'psgix.cleanup.handlers'}} => sub { usleep($csleep) }; 13 | usleep($msleep); 14 | 15 | return [ 16 | 200, 17 | [], 18 | [ "Responding. Slept $msleep us in the main phase, sleeping $csleep us in the cleanup phase" ], 19 | ]; 20 | } 21 | -------------------------------------------------------------------------------- /vassals/multi.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | app001 4 | 5 | starting dir is %v 6 | 7 | %v/../ 8 | 127.0.0.1 9 | 10 | %(localhost):3039 11 | /tmp/%(id).sock2 12 | 13 | 4 14 | werkzeug.testapp:test_app 15 | 16 | 17 | 18 | 19 | 20 | 21 | %(cpus) 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /contrib/launchd/it.unbit.uwsgi.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Label 6 | it.unbit.uwsgi 7 | ProgramArguments 8 | 9 | /Users/roberta/uwsgi/uwsgi 10 | --socket 11 | :3032 12 | --module 13 | welcome 14 | --master 15 | --die-on-term 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /examples/heavytest.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | import werkzeug.testapp 3 | 4 | uwsgi.cache_set("/cache/get", "HTTP 1.1 200 OK\r\nContent-Type: text/html\r\n\r\n

I am the uWSGI cache

") 5 | 6 | 7 | def app001(env, start_response): 8 | start_response('200 OK', [('Content-Type', 'text/html')]) 9 | return "PATH_INFO=%s" % env['PATH_INFO'] 10 | 11 | 12 | def app002(env, start_response): 13 | start_response('200 OK', [('Content-Type', 'text/html')]) 14 | return "requests: %d" % uwsgi.total_requests() 15 | 16 | uwsgi.applications = { 17 | '': werkzeug.testapp.test_app, 18 | '/app001': app001, 19 | '/app002': app002 20 | } 21 | -------------------------------------------------------------------------------- /examples/werkzeug.yml: -------------------------------------------------------------------------------- 1 | # werkzeug test module via YAML 2 | uwsgi: 3 | module: werkzeug.testapp:test_app # a comment 4 | socket: :3032 # another comment 5 | # a line comment 6 | # another line comment 7 | 8 | # adding a tab as separator (discouraged) 9 | master: 1 10 | processes: 8 # the number of processes 11 | memory-report: 1 12 | show-config: true 13 | 14 | # now a psgi app via plugin 15 | app2: 16 | plugins: psgi 17 | socket: :3032 # another comment 18 | # adding a tab as separator (discouraged) 19 | master: 1 20 | processes: 8 # the number of processes 21 | memory-report: 1 22 | psgi: test.psgi 23 | show-config: true 24 | -------------------------------------------------------------------------------- /examples/config17.ru: -------------------------------------------------------------------------------- 1 | require 'stringio' 2 | 3 | hello = proc do |signum| 4 | puts "Hello i am signal #{signum}" 5 | end 6 | 7 | file_changed = proc do |signum| 8 | puts "/tmp has been modified" 9 | end 10 | 11 | UWSGI.register_signal(17, '', hello) 12 | UWSGI.register_signal(30, '', file_changed) 13 | 14 | UWSGI.add_rb_timer(17 , 2) 15 | UWSGI.add_timer(17 , 1) 16 | UWSGI.add_file_monitor(30 , '/tmp') 17 | 18 | puts UWSGI.signal_registered(1) 19 | puts UWSGI.signal_registered(17) 20 | 21 | run lambda { |env| 22 | puts env.inspect 23 | UWSGI.signal(17) 24 | [200, {'Content-Type'=>'text/plain'}, StringIO.new("Hello World!\n")] 25 | } 26 | -------------------------------------------------------------------------------- /t/cachebitmap.ini: -------------------------------------------------------------------------------- 1 | [uwsgi] 2 | socket = /tmp/foo 3 | 4 | cache2 = name=items_1,blocks=4,items=2,bitmap=1,blocksize=1 5 | cache2 = name=items_2,blocks=4,items=3,bitmap=1,blocksize=1 6 | cache2 = name=items_3,blocks=4,items=4,bitmap=1,blocksize=1 7 | cache2 = name=items_4,blocks=5,items=5,bitmap=1,blocksize=1 8 | cache2 = name=items_17,blocks=17,items=17,bitmap=1,blocksize=1 9 | cache2 = name=items_4_10,blocks=5,items=5,bitmap=1,blocksize=10 10 | cache2 = name=items_1_100000,blocks=1000,items=2,bitmap=1,blocksize=100 11 | cache2 = name=items_non_bitmap,items=2,blocksize=20 12 | cache2 = name=items_lru,items=3,blocksize=20,purge_lru=1 13 | pyrun = t/cachebitmap.py 14 | -------------------------------------------------------------------------------- /examples/uwsgi.xml: -------------------------------------------------------------------------------- 1 | 2 | rtmpt 3 | :3031 4 | :3031 5 | 6 | 7 | 8 | homepage 9 | view1 10 | amfapp 11 | rtmpt_open 12 | rtmpt_idle 13 | rtmpt_send 14 | index 15 | 16 | 17 | -------------------------------------------------------------------------------- /t/ring/src/uwsgi/ring/tests/upload.clj: -------------------------------------------------------------------------------- 1 | (ns uwsgi.ring.tests.upload 2 | (:use [compojure.core])) 3 | 4 | (defn upload-file [fname fsize fbody] { 5 | :status 200 6 | :headers { "Content-Type" "text/html" , "Server" "uWSGI" } 7 | :body (str "

Uploaded file

" 8 | "
    " 9 | "
  • " fname "
  • " 10 | "
  • " fsize "
  • " 11 | "
")}) 12 | 13 | (defroutes app-routes 14 | (POST "/upload" {params :params} 15 | (let [file (params :file) 16 | file-name (file :filename) 17 | file-size (file :size) 18 | file-body (file :tempfile)] 19 | (upload-file file-name file-size file-body)))) 20 | 21 | -------------------------------------------------------------------------------- /t/spooler/cheap.py: -------------------------------------------------------------------------------- 1 | # uwsgi --spooler spool1 --spooler spool2 --spooler-cheap --spooler-frequency 5 --spooler-processes 4 --mule --shared-py-import=t/spooler/cheap.py --stats :5000 2 | from uwsgidecorators import * 3 | import time 4 | import random 5 | import os 6 | 7 | def fake(args): 8 | time.sleep(6) 9 | return uwsgi.SPOOL_OK 10 | 11 | uwsgi.spooler = fake 12 | 13 | base = os.getcwd() 14 | spoolers = [base + '/spool1', base + '/spool2'] 15 | 16 | @mule(1) 17 | def spooler_enqueuer(): 18 | while True: 19 | print("enqueuing task...") 20 | uwsgi.spool({'one':'two', 'spooler': random.choice(spoolers)}) 21 | time.sleep(random.randrange(1, 15)) 22 | -------------------------------------------------------------------------------- /tests/picazzo.py: -------------------------------------------------------------------------------- 1 | from picasso import * 2 | 3 | 4 | def home(req): 5 | if not req["session"].get("user"): 6 | return redirect("/login") 7 | return "

Welcome back, %s!

" % req["session"]["user"] 8 | 9 | 10 | def login(req): 11 | return "
" 12 | 13 | 14 | def login_post(req): 15 | print req 16 | req["session"]["user"] = "James" 17 | return redirect("/") 18 | 19 | routes = setup_routes( 20 | GET("/", home), 21 | GET("/login", login), 22 | POST("/login", login_post), 23 | routing.not_found("

Not Found

") 24 | ) 25 | 26 | app = setup_app(routes) 27 | -------------------------------------------------------------------------------- /tests/grunter.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | import time 3 | 4 | 5 | def application(env, start_response): 6 | 7 | start_response('200 Ok', [('Content-Type', 'text/html')]) 8 | 9 | yield "I am the worker %d
" % uwsgi.worker_id() 10 | 11 | grunt = uwsgi.grunt() 12 | 13 | if grunt is None: 14 | print "worker %d detached" % uwsgi.worker_id() 15 | else: 16 | yield "And now i am the grunt with a fix worker id of %d
" % uwsgi.worker_id() 17 | time.sleep(2) 18 | yield "Now, i will start a very slow task...
" 19 | for i in xrange(1, 10): 20 | yield "waiting for %d seconds
" % i 21 | time.sleep(i) 22 | -------------------------------------------------------------------------------- /plugins/mono/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | NAME = 'mono' 4 | 5 | CFLAGS = os.popen('pkg-config --cflags mono-2').read().rstrip().split() 6 | LDFLAGS = [] 7 | LIBS = os.popen('pkg-config --libs mono-2').read().rstrip().split() 8 | GCC_LIST = ['mono_plugin'] 9 | 10 | if os.uname()[0] == 'Darwin': 11 | LIBS.append('-framework Foundation') 12 | 13 | 14 | def post_build(config): 15 | if os.system("sn -k plugins/mono/uwsgi.key") != 0: 16 | os._exit(1) 17 | if os.system("mcs /target:library /r:System.Web.dll /keyfile:plugins/mono/uwsgi.key plugins/mono/uwsgi.cs") != 0: 18 | os._exit(1) 19 | print("*** uwsgi.dll available in %s/plugins/mono/uwsgi.dll ***" % os.getcwd()) 20 | -------------------------------------------------------------------------------- /plugins/coroae/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | NAME = 'coroae' 5 | 6 | coroapi = None 7 | 8 | search_paths = os.popen('perl -MConfig -e \'print $Config{sitearch}.",".join(",", @INC);\'').read().rstrip().split(',') 9 | for p in search_paths: 10 | if os.path.exists(p + '/Coro/CoroAPI.h'): 11 | coroapi = p 12 | 13 | if not coroapi: 14 | print "unable to find the Coro perl module !!!" 15 | sys.exit(1) 16 | 17 | CFLAGS = os.popen('perl -MExtUtils::Embed -e ccopts').read().rstrip().split() 18 | CFLAGS += ['-Wno-int-to-pointer-cast', '-Wno-error=format', '-Wno-error=int-to-pointer-cast', '-I%s/Coro' % coroapi] 19 | LDFLAGS = [] 20 | LIBS = [] 21 | 22 | GCC_LIST = ['coroae'] 23 | -------------------------------------------------------------------------------- /plugins/emperor_mongodb/plugin.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void uwsgi_imperial_monitor_mongodb(struct uwsgi_emperor_scanner *); 4 | void uwsgi_imperial_monitor_mongodb_init(struct uwsgi_emperor_scanner *); 5 | void uwsgi_imperial_monitor_mongodb_init2(struct uwsgi_emperor_scanner *); 6 | 7 | void emperor_mongodb_init(void) { 8 | uwsgi_register_imperial_monitor("mongodb", uwsgi_imperial_monitor_mongodb_init, uwsgi_imperial_monitor_mongodb); 9 | uwsgi_register_imperial_monitor("mongodb2", uwsgi_imperial_monitor_mongodb_init2, uwsgi_imperial_monitor_mongodb); 10 | } 11 | 12 | struct uwsgi_plugin emperor_mongodb_plugin = { 13 | 14 | .name = "emperor_mongodb", 15 | .on_load = emperor_mongodb_init, 16 | }; 17 | -------------------------------------------------------------------------------- /t/ring/src/uwsgi/ring/tests/body.clj: -------------------------------------------------------------------------------- 1 | (ns uwsgi.ring.tests.body 2 | (:use [compojure.core])) 3 | 4 | ; generating primary numbers 5 | ; http://clojuredocs.org/clojure_core/clojure.core/lazy-seq#example_1000 6 | (defn sieve [s] 7 | (cons (first s) 8 | (lazy-seq (sieve (filter #(not= 0 (mod % (first s))) 9 | (rest s)))))) 10 | 11 | (defn numsequence [] (take 20 (sieve (iterate inc 2)))) 12 | 13 | (defn file [] (java.io.File. "CONTRIBUTORS")) 14 | 15 | (defn stream [] (java.io.FileInputStream. (java.io.File. "CONTRIBUTORS"))) 16 | 17 | (defroutes app-routes 18 | (GET "/sequence" [] (numsequence)) 19 | (GET "/file" [] (file)) 20 | (GET "/stream" [] (stream))) 21 | -------------------------------------------------------------------------------- /contrib/binder.pl: -------------------------------------------------------------------------------- 1 | use POSIX; 2 | use IO::Socket::INET; 3 | use IO::Socket::INET6; 4 | use IO::Socket::UNIX; 5 | 6 | my $s = IO::Socket::INET->new(LocalAddr => '127.0.0.1', LocalPort => 1717, Proto => 'tcp', Reuse => 1); 7 | my $s2 = IO::Socket::INET->new(LocalAddr => '127.0.0.1', LocalPort => 3022, Proto => 'tcp', Reuse => 1); 8 | my $s3 = IO::Socket::INET6->new(LocalAddr => '::', LocalPort => 3017, Proto => 'tcp', Reuse => 1); 9 | my $s4 = IO::Socket::UNIX->new(Local => '/tmp/u.sock', Listen => 1); 10 | 11 | dup2($s->fileno, 17); 12 | dup2($s2->fileno, 22); 13 | dup2($s3->fileno, 30); 14 | dup2($s4->fileno, 0); 15 | exec './uwsgi','-M', '--socket','fd://17', '--http-socket','fd://22', '--socket','fd://30','--stats',':5001'; 16 | -------------------------------------------------------------------------------- /examples/multiapp.py: -------------------------------------------------------------------------------- 1 | import werkzeug 2 | import uwsgi 3 | 4 | 5 | def zero_app(e, s): 6 | s('200 OK', [('Content-Type', 'text/plain')]) 7 | return "0" 8 | 9 | 10 | def not_found(e, s): 11 | s('404 Not Found', [('Content-Type', 'text/plain')]) 12 | return "" 13 | 14 | 15 | def wsgi_app(e, s): 16 | s('200 OK', [('Content-Type', 'text/plain')]) 17 | yield "I am a WSGI app\n" 18 | 19 | 20 | def internal_server_error(e, s): 21 | s('500 Internal Server Error', [('Content-Type', 'text/plain')]) 22 | return "" 23 | 24 | uwsgi.applications = { 25 | '/wsgi': wsgi_app, 26 | '/test': werkzeug.test_app, 27 | '/zero': zero_app, 28 | '/notfound': not_found, 29 | '/ise': internal_server_error 30 | } 31 | -------------------------------------------------------------------------------- /examples/router.lua: -------------------------------------------------------------------------------- 1 | print("uWSGI Lua router") 2 | 3 | uwsgi.log("i am ready") 4 | 5 | function route(env) 6 | 7 | print(env.REQUEST_URI) 8 | 9 | html = uwsgi.cache_get(env.REQUEST_URI) 10 | 11 | local function send_cache() 12 | coroutine.yield(html) 13 | end 14 | 15 | local function body() 16 | page = "" 17 | parts = { uwsgi.send_message("127.0.0.1:3033", 0, 0, env, 30, uwsgi.req_fd(), uwsgi.cl()) } 18 | for i, part in pairs(parts) do 19 | page = page .. part 20 | coroutine.yield(part) 21 | end 22 | 23 | uwsgi.cache_set(env.REQUEST_URI, page) 24 | end 25 | 26 | if html then 27 | return nil,{}, coroutine.wrap(send_cache) 28 | end 29 | 30 | return nil,{}, coroutine.wrap(body) 31 | end 32 | 33 | return route 34 | -------------------------------------------------------------------------------- /tests/badwrites.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | 4 | def application(e, sr): 5 | time.sleep(3) 6 | print("3 seconds elapsed") 7 | sr('200 Ok', [('Content-Type', 'text/html')]) 8 | 9 | time.sleep(2) 10 | print("2 seconds elapsed") 11 | 12 | yield "part1" 13 | 14 | try: 15 | time.sleep(2) 16 | except: 17 | print("CLIENT DISCONNECTED !!!") 18 | print("2 seconds elapsed") 19 | 20 | yield "part2" 21 | 22 | try: 23 | time.sleep(2) 24 | except: 25 | print("CLIENT DISCONNECTED !!!") 26 | print("2 seconds elapsed") 27 | 28 | yield "part3" 29 | 30 | time.sleep(2) 31 | print("2 seconds elapsed") 32 | 33 | yield "part4" 34 | 35 | print("end of request") 36 | -------------------------------------------------------------------------------- /t/perl/test_harakiri.psgi: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | 4 | { 5 | package psgix::harakiri::tester; 6 | sub DESTROY { print STDERR "$$: Calling DESTROY\n" } 7 | } 8 | 9 | uwsgi::atexit( 10 | sub { 11 | print STDERR "$$: Calling the atexit hook\n"; 12 | } 13 | ); 14 | 15 | sub { 16 | my $env = shift; 17 | 18 | die "PANIC: We should support psgix.harakiri here" unless $env->{'psgix.harakiri'}; 19 | 20 | $env->{'psgix.harakiri.tester'} = bless {} => 'psgix::harakiri::tester'; 21 | my $harakiri = $env->{QUERY_STRING}; 22 | $env->{'psgix.harakiri.commit'} = $harakiri ? 1 : 0; 23 | 24 | return [200, [], [ $harakiri ? "We are about to destroy ourselves\n" : "We will live for another request\n" ]]; 25 | } 26 | -------------------------------------------------------------------------------- /ext/uwsgi/extconf.rb: -------------------------------------------------------------------------------- 1 | require 'net/http' 2 | 3 | Net::HTTP.start("uwsgi.it", :use_ssl=>true) do |http| 4 | resp = http.get("/install") 5 | open("install.sh", "wb") do |file| 6 | file.write(resp.body) 7 | end 8 | end 9 | 10 | major,minor = RUBY_VERSION.split('.') 11 | if major.to_i >= 2 or (major.to_i == 1 and minor.to_i >= 9) 12 | # a trick for installations with messy PATH 13 | ENV['UWSGICONFIG_RUBYPATH'] = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']).sub(/.*\s.*/m, '"\&"') 14 | system("bash install.sh ruby2 #{Dir.pwd}/uwsgi.ruby") 15 | else 16 | system("bash install.sh rack #{Dir.pwd}/uwsgi.ruby") 17 | end 18 | 19 | open("Makefile", "w") do |file| 20 | file.write("all:\n") 21 | file.write("\t\n") 22 | end 23 | -------------------------------------------------------------------------------- /examples/mjpeg_stream.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | def application(env, start_response): 5 | 6 | boundary = 'uwsgi_mjpeg_frame' 7 | 8 | start_response('200 Ok', [ 9 | ('Cache-Control', 'no-cache'), 10 | ('Cache-Control', 'private'), 11 | ('Pragma', 'no-cache'), 12 | ('Content-Type', 'multipart/x-mixed-replace; boundary=' + boundary), 13 | ]) 14 | 15 | yield "--%s\r\n" % boundary 16 | 17 | while 1: 18 | yield "Content-Type: image/jpeg\r\n\r\n" 19 | print os.system('screencapture -t jpg -m -T 1 screenshot.jpg') 20 | f = open('screenshot.jpg') 21 | yield env['wsgi.file_wrapper'](f) 22 | yield "\r\n--%s\r\n" % boundary 23 | # os.system('./isightcapture -w 640 -h 480 screenshot.jpg') 24 | -------------------------------------------------------------------------------- /mongrel2-uwsgi.conf: -------------------------------------------------------------------------------- 1 | main = Server( 2 | uuid="f400bf85-4538-4f7a-8908-67e313d515c2", 3 | access_log="/logs/access.log", 4 | error_log="/logs/error.log", 5 | chroot="./", 6 | default_host="192.168.173.18", 7 | name="test", 8 | pid_file="/run/mongrel2.pid", 9 | port=6767, 10 | hosts = [ 11 | Host(name="192.168.173.18", routes={ 12 | '/': Handler(send_spec='tcp://192.168.173.18:9999', 13 | send_ident='54c6755b-9628-40a4-9a2d-cc82a816345e', 14 | recv_spec='tcp://192.168.173.18:9998', recv_ident='') 15 | }) 16 | ] 17 | ) 18 | 19 | settings = {'upload.temp_store':'tmp/mongrel2.upload.XXXXXX'} 20 | servers = [main] 21 | 22 | 23 | uwsgi = { 'socket':':3031', 'master':'true'} 24 | -------------------------------------------------------------------------------- /lib/sun_fixes.c: -------------------------------------------------------------------------------- 1 | /* function written by Ben Taylor (found in the qemu-devel list) */ 2 | 3 | #include "../uwsgi.h" 4 | 5 | time_t timegm(struct tm *t) { 6 | time_t tl, tb; 7 | struct tm *tg; 8 | 9 | tl = mktime (t); 10 | if (tl == -1) { 11 | t->tm_hour--; 12 | tl = mktime (t); 13 | if (tl == -1) 14 | return -1; /* can't deal with output from strptime */ 15 | 16 | tl += 3600; 17 | } 18 | tg = gmtime (&tl); 19 | tg->tm_isdst = 0; 20 | tb = mktime (tg); 21 | if (tb == -1) { 22 | tg->tm_hour--; 23 | tb = mktime (tg); 24 | if (tb == -1) 25 | return -1; /* can't deal with output from gmtime */ 26 | tb += 3600; 27 | } 28 | return (tl - (tb - tl)); 29 | } 30 | -------------------------------------------------------------------------------- /tests/sigwait.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | from uwsgidecorators import * 3 | 4 | 5 | @signal(17, target='workers') 6 | def hello(signum): 7 | print("I AM THE WORKER %d" % uwsgi.worker_id()) 8 | 9 | 10 | @signal(30, target='worker2') 11 | def hello2(signum): 12 | print("I AM THE WORKER 2") 13 | 14 | 15 | @postfork 16 | def wait_for_signal(): 17 | if uwsgi.worker_id() != 2: 18 | print("waiting for a signal...") 19 | uwsgi.signal_wait() 20 | print("signal %d received" % uwsgi.signal_received()) 21 | 22 | 23 | def application(e, s): 24 | s('200 OK', [('Content-Type', 'text/html')]) 25 | if e['PATH_INFO'] == '/30': 26 | uwsgi.signal(30) 27 | uwsgi.signal(100) 28 | else: 29 | uwsgi.signal(17) 30 | return "Signal raised" 31 | -------------------------------------------------------------------------------- /t/routing/limiter.ini: -------------------------------------------------------------------------------- 1 | [uwsgi] 2 | http-socket = :9090 3 | 4 | ; 8 bytes blocksize is the right thing to do 5 | cache2 = name=limiter,items=1000,blocksize=8 6 | ; allows expiring items 7 | master = true 8 | 9 | ; get the cache value for the current ip (if any) 10 | route-run = cachevar:key=${REMOTE_ADDR},as_num=1,var=LIMIT 11 | ; block the peer if it did more than 10 requests in the last 30 seconds 12 | route-if = >:${LIMIT};10 goto:blockit 13 | ; increment the value (expires value will not be updated) 14 | route-run = cacheinc:key=${REMOTE_ADDR},expires=30 15 | ; end of the checks 16 | route-run = last: 17 | 18 | module = werkzeug.testapp:test_app 19 | threads = 10 20 | 21 | ; block the client 22 | route-label = blockit 23 | route-run = log:STOP YOU BASTARD !!! 24 | route-run = break:503 25 | -------------------------------------------------------------------------------- /plugins/ring/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | import os 2 | import shutil 3 | 4 | NAME = 'ring' 5 | 6 | jvm_path = 'plugins/jvm' 7 | 8 | up = {} 9 | try: 10 | execfile('%s/uwsgiplugin.py' % jvm_path, up) 11 | except: 12 | f = open('%s/uwsgiplugin.py' % jvm_path) 13 | exec(f.read(), up) 14 | f.close() 15 | 16 | CFLAGS = up['CFLAGS'] 17 | CFLAGS.append('-I%s' % jvm_path) 18 | LDFLAGS = [] 19 | LIBS = [] 20 | GCC_LIST = ['ring_plugin'] 21 | 22 | 23 | def post_build(config): 24 | env = os.environ.get('VIRTUAL_ENV') 25 | if env: 26 | plugin = "%s/ring_plugin.so" % os.getcwd() 27 | if os.path.exists(plugin): 28 | tgt = "%s/bin/ring_plugin.so" % env 29 | shutil.copyfile(plugin, tgt) 30 | print("*** ring_plugin.so had been copied to %s" % tgt) 31 | -------------------------------------------------------------------------------- /t/xslt/cd.xml.xslt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

Blackmetal albums

8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
TitleArtist
--
22 | 23 | 24 |
25 |
26 | -------------------------------------------------------------------------------- /plugins/signal/signal_plugin.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern struct uwsgi_server uwsgi; 4 | 5 | /* request 110 */ 6 | int uwsgi_request_signal(struct wsgi_request *wsgi_req) { 7 | 8 | uint8_t ret_status = 1; 9 | 10 | struct uwsgi_header uh; 11 | if (uwsgi_signal_send(uwsgi.signal_socket, wsgi_req->uh->modifier2) < 0) { 12 | ret_status = 0; 13 | } 14 | 15 | uh.modifier1 = 255; 16 | uh._pktsize = 0; 17 | uh.modifier2 = ret_status; 18 | 19 | if (uwsgi_response_write_body_do(wsgi_req, (char *) &uh, 4)) { 20 | return -1; 21 | } 22 | 23 | return UWSGI_OK; 24 | } 25 | 26 | 27 | struct uwsgi_plugin signal_plugin = { 28 | 29 | .name = "signal", 30 | .modifier1 = 110, 31 | .request = uwsgi_request_signal, 32 | 33 | }; 34 | 35 | -------------------------------------------------------------------------------- /t/python/spooler_handler.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python2 2 | # coding = utf-8 3 | 4 | from __future__ import print_function 5 | from constants import tasks, LOGFILE 6 | from os import remove 7 | import uwsgi 8 | 9 | counter = 0 10 | 11 | 12 | def spoolerHandler(env): 13 | global counter 14 | # Spooler is handling a task 15 | with open(LOGFILE, "a") as log: 16 | print("%s" % (env['name']), file=log) 17 | 18 | counter += 1 19 | 20 | if counter == len(tasks): 21 | # Each task has been processed. 22 | uwsgi.signal(17) 23 | 24 | # Spooler has done handling the task 25 | return uwsgi.SPOOL_OK 26 | 27 | uwsgi.spooler = spoolerHandler 28 | 29 | # Clear the logfile 30 | try: 31 | remove(LOGFILE) 32 | except OSError, e: # log does not exist 33 | pass 34 | # print(e) 35 | -------------------------------------------------------------------------------- /contrib/uwsgi.erl: -------------------------------------------------------------------------------- 1 | -module(uwsgi). 2 | -export([encode/1,send/3]). 3 | 4 | 5 | encode(Vars) -> 6 | Body = lists:map(fun(X) -> Len = length(X), lists:append( binary_to_list(<>), X) end, Vars), 7 | lists:flatten(Body). 8 | 9 | response(Sock, Output) -> 10 | case gen_tcp:recv(Sock,0) of 11 | { ok, Data } -> 12 | response(Sock, lists:append(Output, binary_to_list(Data))); 13 | { error, closed } -> 14 | gen_tcp:close(Sock), 15 | Output 16 | end. 17 | 18 | send(Host, Port, Message) -> 19 | { ok, Sock } = gen_tcp:connect( Host, Port, [ binary, { active, false} ]), 20 | 21 | Body = encode(Message), 22 | 23 | Len = length(Body), 24 | 25 | ok = gen_tcp:send(Sock, << 0, Len:16/little-unsigned-integer, 0>>), 26 | 27 | ok = gen_tcp:send(Sock, Body), 28 | 29 | response(Sock, []). 30 | 31 | -------------------------------------------------------------------------------- /tests/mulefunc.py: -------------------------------------------------------------------------------- 1 | from uwsgidecorators import * 2 | 3 | 4 | @timer(3, target='mule1') 5 | def hello_timer(signum): 6 | print "3 seconds elapsed" 7 | 8 | 9 | @mulefunc 10 | def conto_fino_a_dieci(uno, due, tre): 11 | print "MULE ID %d: conto_fino_a_dieci" % uwsgi.mule_id(), uno, due, tre 12 | 13 | 14 | @mulefunc(2) 15 | def conto_fino_a_venti(uno, due, tre): 16 | print "MULE ID %d: conto_fino_a_venti" % uwsgi.mule_id(), uno, due, tre 17 | 18 | 19 | @mulefunc('topogigio') 20 | def conto_fino_a_trenta(uno, due, tre): 21 | print "MULE ID %d: conto_fino_a_trenta" % uwsgi.mule_id(), uno, due, tre 22 | 23 | 24 | def application(e, sr): 25 | conto_fino_a_dieci(1, 2, 3) 26 | conto_fino_a_venti(4, 5, 6) 27 | conto_fino_a_trenta(7, 8, 9) 28 | sr('200 OK', [('Content-Type', 'text/html')]) 29 | return "MULE !!!" 30 | -------------------------------------------------------------------------------- /t/python/spooler_priority/spooler_priority_handler.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # coding = utf-8 3 | 4 | from __future__ import print_function 5 | from spooler_priority_constants import tasks, LOGFILE 6 | from os import remove 7 | import uwsgi 8 | 9 | counter = 0 10 | 11 | 12 | def spoolerHandler(env): 13 | global counter 14 | # Spooler is handling a task 15 | with open(LOGFILE, "a") as log: 16 | print("%s" % (env['name']), file=log) 17 | 18 | counter += 1 19 | 20 | if counter == len(tasks): 21 | # Each task has been processed. 22 | uwsgi.signal(17) 23 | 24 | # Spooler has done handling the task 25 | return uwsgi.SPOOL_OK 26 | 27 | uwsgi.spooler = spoolerHandler 28 | 29 | # Clear the logfile 30 | try: 31 | remove(LOGFILE) 32 | except OSError, e: # log does not exist 33 | print(e) 34 | -------------------------------------------------------------------------------- /plugins/gridfs/plugin.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int uwsgi_gridfs_request(struct wsgi_request *); 4 | void uwsgi_gridfs_mount(); 5 | extern struct uwsgi_option uwsgi_gridfs_options[]; 6 | 7 | static void uwsgi_gridfs_log(struct wsgi_request *wsgi_req) { 8 | log_request(wsgi_req); 9 | } 10 | 11 | #ifdef UWSGI_ROUTING 12 | int uwsgi_router_gridfs(struct uwsgi_route *, char *); 13 | static void uwsgi_gridfs_register_router() { 14 | uwsgi_register_router("gridfs", uwsgi_router_gridfs); 15 | } 16 | #endif 17 | 18 | 19 | struct uwsgi_plugin gridfs_plugin = { 20 | 21 | .name = "gridfs", 22 | .modifier1 = 25, 23 | 24 | .init_apps = uwsgi_gridfs_mount, 25 | .options = uwsgi_gridfs_options, 26 | .request = uwsgi_gridfs_request, 27 | .after_request = uwsgi_gridfs_log, 28 | #ifdef UWSGI_ROUTING 29 | .on_load = uwsgi_gridfs_register_router, 30 | #endif 31 | }; 32 | -------------------------------------------------------------------------------- /plugins/php/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | NAME = 'php' 4 | 5 | ld_run_path = None 6 | PHPPATH = 'php-config' 7 | 8 | phpdir = os.environ.get('UWSGICONFIG_PHPDIR') 9 | if phpdir: 10 | ld_run_path = "%s/lib" % phpdir 11 | PHPPATH = "%s/bin/php-config" % phpdir 12 | 13 | PHPPATH = os.environ.get('UWSGICONFIG_PHPPATH', PHPPATH) 14 | 15 | CFLAGS = [os.popen(PHPPATH + ' --includes').read().rstrip(), '-Wno-sign-compare'] 16 | LDFLAGS = os.popen(PHPPATH + ' --ldflags').read().rstrip().split() 17 | 18 | if ld_run_path: 19 | LDFLAGS.append('-L%s' % ld_run_path) 20 | os.environ['LD_RUN_PATH'] = ld_run_path 21 | 22 | LIBS = [os.popen(PHPPATH + ' --libs').read().rstrip(), '-lphp5'] 23 | 24 | phplibdir = os.environ.get('UWSGICONFIG_PHPLIBDIR') 25 | if phplibdir: 26 | LIBS.append('-Wl,-rpath=%s' % phplibdir) 27 | 28 | GCC_LIST = ['php_plugin', 'session'] 29 | -------------------------------------------------------------------------------- /t/cachetest.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | 3 | import random 4 | import string 5 | 6 | items = {} 7 | 8 | 9 | def gen_rand_n(max_n): 10 | return random.randint(8, max_n) 11 | 12 | 13 | def gen_rand_s(size): 14 | return ''.join(random.choice(string.letters) for i in range(size)) 15 | 16 | print 'filling cache...' 17 | for i in range(0, 1000): 18 | kl = gen_rand_n(200) 19 | key = gen_rand_s(kl) 20 | vl = gen_rand_n(10000) 21 | val = gen_rand_s(vl) 22 | items[key] = val 23 | uwsgi.cache_set(key, val) 24 | 25 | print 'checking cache...' 26 | count = 0 27 | for key in items.keys(): 28 | val = uwsgi.cache_get(key) 29 | count += 1 30 | if val != items[key]: 31 | print len(val), val 32 | print len(items[key]), items[key] 33 | raise Exception('CACHE TEST FAILED AFTER %d ITERATIONS !!!' % count) 34 | 35 | print "TEST PASSED" 36 | -------------------------------------------------------------------------------- /examples/info_uwsgi.php: -------------------------------------------------------------------------------- 1 | uWSGI version
2 | workerd id:
3 | master pid:
4 | 5 | uri:
6 | docroot:
7 | PATH_INFO:
8 | 9 | 10 | 11 | 12 | 13 | rpc result:
14 | 15 | 16 | 22 | cache value:
23 |
24 | 25 | 26 |
27 | -------------------------------------------------------------------------------- /plugins/alarm_xmpp/alarm_xmpp_plugin.c: -------------------------------------------------------------------------------- 1 | #include "../../uwsgi.h" 2 | 3 | void uwsgi_alarm_xmpp_loop(struct uwsgi_thread *); 4 | 5 | static void uwsgi_alarm_xmpp_init(struct uwsgi_alarm_instance *uai) { 6 | 7 | struct uwsgi_thread *ut = uwsgi_thread_new_with_data(uwsgi_alarm_xmpp_loop, uai->arg); 8 | if (!ut) return; 9 | uai->data_ptr = ut; 10 | } 11 | 12 | // pipe the message into the thread; 13 | static void uwsgi_alarm_xmpp_func(struct uwsgi_alarm_instance *uai, char *msg, size_t len) { 14 | struct uwsgi_thread *ut = (struct uwsgi_thread *) uai->data_ptr; 15 | ut->rlen = write(ut->pipe[0], msg, len); 16 | } 17 | 18 | static void uwsgi_alarm_xmpp_load(void) { 19 | uwsgi_register_alarm("xmpp", uwsgi_alarm_xmpp_init, uwsgi_alarm_xmpp_func); 20 | } 21 | 22 | struct uwsgi_plugin alarm_xmpp_plugin = { 23 | .name = "alarm_xmpp", 24 | .on_load = uwsgi_alarm_xmpp_load, 25 | }; 26 | -------------------------------------------------------------------------------- /plugins/notfound/notfound.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int uwsgi_notfound_log_enabled = 0; 4 | 5 | struct uwsgi_option uwsgi_notfound_options[] = { 6 | {"notfound-log", no_argument, 0, "log requests to the notfound plugin", uwsgi_opt_true, &uwsgi_notfound_log_enabled, 0}, 7 | {NULL, 0, 0, NULL, NULL, NULL, 0}, 8 | }; 9 | 10 | static int uwsgi_request_notfound(struct wsgi_request *wsgi_req) { 11 | if (uwsgi_parse_vars(wsgi_req)) { 12 | return -1; 13 | } 14 | uwsgi_404(wsgi_req); 15 | return UWSGI_OK; 16 | } 17 | 18 | static void uwsgi_notfound_log(struct wsgi_request *wsgi_req) { 19 | if (uwsgi_notfound_log_enabled) { 20 | log_request(wsgi_req); 21 | } 22 | } 23 | 24 | struct uwsgi_plugin notfound_plugin = { 25 | .name = "notfound", 26 | .options = uwsgi_notfound_options, 27 | .request = uwsgi_request_notfound, 28 | .after_request = uwsgi_notfound_log, 29 | }; 30 | -------------------------------------------------------------------------------- /plugins/clock_realtime/clock_realtime.c: -------------------------------------------------------------------------------- 1 | #include "../../uwsgi.h" 2 | 3 | // timespecs have nanoseconds resolution 4 | 5 | time_t uwsgi_realtime_seconds() { 6 | struct timespec ts; 7 | clock_gettime(CLOCK_REALTIME, &ts); 8 | return ts.tv_sec; 9 | } 10 | 11 | uint64_t uwsgi_realtime_microseconds() { 12 | struct timespec ts; 13 | clock_gettime(CLOCK_REALTIME, &ts); 14 | return ((uint64_t) ts.tv_sec * 1000000) + (ts.tv_nsec/1000); 15 | } 16 | 17 | 18 | static struct uwsgi_clock uwsgi_realtime_clock = { 19 | .name = "realtime", 20 | .seconds = uwsgi_realtime_seconds, 21 | .microseconds = uwsgi_realtime_microseconds, 22 | }; 23 | 24 | 25 | void uwsgi_realtime_clock_load() { 26 | uwsgi_register_clock(&uwsgi_realtime_clock); 27 | } 28 | 29 | struct uwsgi_plugin clock_realtime_plugin = { 30 | .name = "clock_realtime", 31 | .on_load = uwsgi_realtime_clock_load 32 | }; 33 | -------------------------------------------------------------------------------- /examples/logic.ini: -------------------------------------------------------------------------------- 1 | [uwsgi] 2 | 3 | for = 4031 14032 4033 14034 24035 4 | socket = /tmp/%(_)/uwsgi.sock 5 | socket = 192.*:%(_) 6 | print = ciao %(_) hello %(_) bye %(_) 7 | endfor = 8 | 9 | 10 | socket = :4045 11 | socket = :4046 12 | socket = :4047 13 | socket = :4048 14 | 15 | 16 | socket = :4049 17 | socket = :4050 18 | socket = :4051 19 | 20 | show-config = 21 | 22 | if-env = PIPPO 23 | print = 24 | print = PIPPO e' definita e il suo valore e' %(_) boh 25 | endif = 26 | 27 | socket = :5051 28 | socket = :5052 29 | socket = :5053 30 | socket = :5054 31 | 32 | if-exists = /etc/services 33 | print = il file %(_) esiste $(PATH) 34 | endif = 35 | 36 | if-exists = /etc/foobar 37 | print = il file %(_) esiste $(PATH) 38 | endif = 39 | 40 | socket = :6060 41 | if-file = /etc/fstab 42 | socket = :7171 43 | endif = 44 | 45 | ifdir = /tmp 46 | print = %(_) is a directory 47 | endif= 48 | -------------------------------------------------------------------------------- /plugins/clock_monotonic/clock_monotonic.c: -------------------------------------------------------------------------------- 1 | #include "../../uwsgi.h" 2 | 3 | // timespecs have nanoseconds resolution 4 | 5 | time_t uwsgi_monotonic_seconds() { 6 | struct timespec ts; 7 | clock_gettime(CLOCK_MONOTONIC, &ts); 8 | return ts.tv_sec; 9 | } 10 | 11 | uint64_t uwsgi_monotonic_microseconds() { 12 | struct timespec ts; 13 | clock_gettime(CLOCK_MONOTONIC, &ts); 14 | return ((uint64_t)ts.tv_sec * 1000000) + (ts.tv_nsec/1000); 15 | } 16 | 17 | 18 | static struct uwsgi_clock uwsgi_monotonic_clock = { 19 | .name = "monotonic", 20 | .seconds = uwsgi_monotonic_seconds, 21 | .microseconds = uwsgi_monotonic_microseconds, 22 | }; 23 | 24 | 25 | void uwsgi_monotonic_clock_load() { 26 | uwsgi_register_clock(&uwsgi_monotonic_clock); 27 | } 28 | 29 | struct uwsgi_plugin clock_monotonic_plugin = { 30 | .name = "clock_monotonic", 31 | .on_load = uwsgi_monotonic_clock_load 32 | }; 33 | -------------------------------------------------------------------------------- /plugins/python/gil.c: -------------------------------------------------------------------------------- 1 | #include "uwsgi_python.h" 2 | 3 | extern struct uwsgi_server uwsgi; 4 | extern struct uwsgi_python up; 5 | 6 | void gil_real_get() { 7 | //uwsgi_log("LOCK %d\n", uwsgi.mywid); 8 | #if !defined(PYTHREE) 9 | PyEval_AcquireLock(); 10 | PyThreadState_Swap((PyThreadState *) pthread_getspecific(up.upt_gil_key)); 11 | #else 12 | PyEval_RestoreThread((PyThreadState *) pthread_getspecific(up.upt_gil_key)); 13 | #endif 14 | 15 | //uwsgi_log("LOCKED !!! %d\n", uwsgi.mywid); 16 | } 17 | 18 | void gil_real_release() { 19 | //uwsgi_log("UNLOCK %d\n", uwsgi.mywid); 20 | #if !defined(PYTHREE) 21 | pthread_setspecific(up.upt_gil_key, (void *) PyThreadState_Swap(NULL)); 22 | PyEval_ReleaseLock(); 23 | #else 24 | pthread_setspecific(up.upt_gil_key, (void *) PyThreadState_Get()); 25 | PyEval_SaveThread(); 26 | #endif 27 | } 28 | 29 | 30 | void gil_fake_get() {} 31 | void gil_fake_release() {} 32 | -------------------------------------------------------------------------------- /tests/threads.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | import threading 3 | import time 4 | import sys 5 | 6 | 7 | def monitor1(): 8 | while 1: 9 | time.sleep(1) 10 | print("i am the monitor 1") 11 | 12 | 13 | def monitor2(): 14 | while 1: 15 | time.sleep(2) 16 | print("i am the monitor 2") 17 | print(sys.modules) 18 | 19 | 20 | def monitor3(): 21 | while 1: 22 | time.sleep(5) 23 | print("5 seconds elapsed") 24 | # reload(fake) 25 | 26 | 27 | def spawn_my_magic_threads(): 28 | print("^^^ spawning magic threads ^^^") 29 | threading.Thread(target=monitor1).start() 30 | threading.Thread(target=monitor2).start() 31 | threading.Thread(target=monitor3).start() 32 | 33 | uwsgi.post_fork_hook = spawn_my_magic_threads 34 | 35 | 36 | def application(e, s): 37 | s('200 Ok', [('Content-Type', 'text/html')]) 38 | return "Hello Threaded World !!!" 39 | -------------------------------------------------------------------------------- /plugins/lua/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | NAME = 'lua' 4 | 5 | LUAINC = os.environ.get('UWSGICONFIG_LUAINC') 6 | LUALIB = os.environ.get('UWSGICONFIG_LUALIB') 7 | LUALIBPATH = os.environ.get('UWSGICONFIG_LUALIBPATH') 8 | LUAPC = os.environ.get('UWSGICONFIG_LUAPC', 'lua5.1') 9 | 10 | # we LUAINC/LUALIB/LUALIBPATH override the LUAPC for backwards compat 11 | if LUAINC: 12 | CFLAGS = ['-I%s' % LUAINC] 13 | else: 14 | try: 15 | CFLAGS = os.popen('pkg-config --cflags %s' % LUAPC).read().rstrip().split() 16 | except: 17 | CFLAGS = ['-I/usr/include/lua5.1'] 18 | 19 | if LUALIB: 20 | LIBS = ['-l%s' % LUALIB] 21 | else: 22 | try: 23 | LIBS = os.popen('pkg-config --libs %s' % LUAPC).read().rstrip().split() 24 | except: 25 | LIBS = ['-llua5.1'] 26 | 27 | if LUALIBPATH: 28 | LDFLAGS = ['-L%s' % LUALIBPATH] 29 | else: 30 | LDFLAGS = [] 31 | 32 | GCC_LIST = ['lua_plugin'] 33 | -------------------------------------------------------------------------------- /examples/taskqueue.py: -------------------------------------------------------------------------------- 1 | import Queue 2 | from threading import Thread 3 | import uwsgi 4 | 5 | CONSUMERS = 4 6 | 7 | 8 | def consumer(q): 9 | while True: 10 | item = q.get() 11 | print(item) 12 | # ... DO A HEAVY TASK HERE ... 13 | q.task_done() 14 | 15 | 16 | def spawn_consumers(): 17 | global q 18 | q = Queue.Queue() 19 | for i in range(CONSUMERS): 20 | t = Thread(target=consumer, args=(q,)) 21 | t.daemon = True 22 | t.start() 23 | print("consumer %d on worker %d started" % (i, uwsgi.worker_id())) 24 | 25 | 26 | uwsgi.post_fork_hook = spawn_consumers 27 | 28 | 29 | def application(env, start_response): 30 | global q 31 | 32 | # we pass a copy of the env dictionary as it gets cleared after yield/return 33 | q.put(env.copy()) 34 | 35 | start_response('200 OK', [('Content-Type', 'text/html')]) 36 | 37 | yield "Task enqueued" 38 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | - this is a incomplete list of all the contributors of the project - 2 | 3 | Roberto De Ioris, Unbit, 4 | Riccardo Magliocchetti 5 | Yann Malet, Lincoln Loop 6 | Simon Litchfield 7 | Masahiro Honma, 8 | Łukasz Wróblewski 9 | Giacomo Bagnoli, Asidev 10 | Guido Notari, Link I.T. S.p.a. 11 | Marco Beri, Link I.T. S.p.a. 12 | Leonid Borisenko 13 | Cal Leeming, Simplicity Media Ltd 14 | Luigi Scarso 15 | Corey Farwell 16 | Charles Duffy 17 | Lukas Lalinsky 18 | Steven Fernandez 19 | Łukasz Mierzwa 20 | Roy Marples 21 | Aarni Koskela 22 | C Anthony Risinger 23 | Stephen Pierce 24 | Mingli Yuan 25 | Natanael Copa 26 | Roberto Leandrini 27 | Ryan Petrello 28 | Danila Shtan 29 | Ævar Arnfjörð Bjarmason 30 | Yu Zhao (getcwd) 31 | Mathieu Dupuy 32 | Mike Kaplinskiy 33 | Adriano Di Luzio (adriano@unbit.it) 34 | James Raspass 35 | Curtis Maloney 36 | Vladimir Didenko 37 | -------------------------------------------------------------------------------- /plugins/systemd_logger/systemd_logger.c: -------------------------------------------------------------------------------- 1 | #include "../../uwsgi.h" 2 | 3 | #include 4 | 5 | ssize_t uwsgi_systemd_logger(struct uwsgi_logger *ul, char *message, size_t len) { 6 | 7 | // split multiline log messages to multiple journal lines 8 | size_t i; 9 | char *base = message; 10 | for(i=0;i 'text/plain'}, SuspendingBody.new] 43 | end 44 | 45 | end 46 | 47 | run RackFoo.new 48 | -------------------------------------------------------------------------------- /t/core/read_body_and_send.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | #uwsgi --http-socket :9090 --psgi t/core/apps/read_body_and_send.pl 4 | 5 | use IO::Socket::INET; 6 | 7 | my @chars = ("A".."Z", "a".."z"); 8 | 9 | foreach(0..100) { 10 | $size = int(rand(8*1024*1024)); 11 | print "testing: round ".$_." body size ".$size."\n"; 12 | my $req = "POST /foobar HTTP/1.0\r\n"; 13 | $req .= 'Content-Length: '.$size."\r\n\r\n"; 14 | my $body = ''; 15 | $body .= $chars[rand @chars] for 1..($size); 16 | $req .= $body; 17 | 18 | my $s = IO::Socket::INET->new(PeerAddr => $ARGV[0]); 19 | $s->send($req); 20 | 21 | my $response = ''; 22 | while(1) { 23 | $s->recv(my $buf, 4096); 24 | last unless length($buf); 25 | $response .= $buf; 26 | } 27 | $s->close; 28 | 29 | if ($response ne "HTTP/1.0 200 OK\r\nContent-Type: x-application/binary\r\n\r\n".$body) { 30 | print "TEST FOR ROUND ".$_." FAILED\n"; 31 | exit; 32 | } 33 | } 34 | 35 | print "test result: SUCCESS\n"; 36 | -------------------------------------------------------------------------------- /vhosttest/nginx.conf: -------------------------------------------------------------------------------- 1 | 2 | worker_processes 1; 3 | 4 | events { 5 | worker_connections 1024; 6 | } 7 | 8 | 9 | http { 10 | include mime.types; 11 | default_type application/octet-stream; 12 | 13 | sendfile on; 14 | 15 | keepalive_timeout 65; 16 | 17 | gzip on; 18 | 19 | upstream uwsgi_server { 20 | server 127.0.0.1:3031; 21 | } 22 | 23 | include uwsgi_params; 24 | uwsgi_param UWSGI_FILE $app; 25 | uwsgi_param UWSGI_PYHOME $virtualenv; 26 | 27 | 28 | server { 29 | listen 8026; 30 | server_name flask001; 31 | set $app vhosttest/flask001/app1.py; 32 | set $virtualenv vhosttest/venv001; 33 | location / { 34 | uwsgi_pass uwsgi_server; 35 | } 36 | } 37 | 38 | server { 39 | listen 8026; 40 | server_name flask002; 41 | set $app vhosttest/flask002/app2.py; 42 | set $virtualenv vhosttest/venv001; 43 | location / { 44 | uwsgi_pass uwsgi_server; 45 | } 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /plugins/transformation_toupper/toupper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int transform_toupper(struct wsgi_request *wsgi_req, struct uwsgi_transformation *ut) { 4 | size_t i; 5 | for(i=0;ichunk->pos;i++) { 6 | ut->chunk->buf[i] = toupper((int) ut->chunk->buf[i]); 7 | } 8 | return 0; 9 | } 10 | 11 | static int uwsgi_routing_func_toupper(struct wsgi_request *wsgi_req, struct uwsgi_route *ur) { 12 | struct uwsgi_transformation *ut = uwsgi_add_transformation(wsgi_req, transform_toupper, NULL); 13 | ut->can_stream = 1; 14 | return UWSGI_ROUTE_NEXT; 15 | } 16 | 17 | static int uwsgi_router_toupper(struct uwsgi_route *ur, char *args) { 18 | ur->func = uwsgi_routing_func_toupper; 19 | return 0; 20 | } 21 | 22 | static void router_toupper_register(void) { 23 | uwsgi_register_router("toupper", uwsgi_router_toupper); 24 | } 25 | 26 | struct uwsgi_plugin transformation_toupper_plugin = { 27 | .name = "transformation_toupper", 28 | .on_load = router_toupper_register, 29 | }; 30 | -------------------------------------------------------------------------------- /contrib/securesubscribe.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use Crypt::OpenSSL::RSA; 4 | use IO::Socket::INET; 5 | 6 | open PK,$ARGV[3]; 7 | my @lines = ; 8 | close PK; 9 | 10 | $rsa_priv = Crypt::OpenSSL::RSA->new_private_key(join('',@lines)); 11 | 12 | my %items = {}; 13 | 14 | $items{'key'} = $ARGV[1]; 15 | $items{'address'} = $ARGV[2]; 16 | 17 | my $uwsgi_pkt = ''; 18 | 19 | foreach(keys %items) { 20 | $uwsgi_pkt .= pack('v', length($_)).$_.pack('v', length($items{$_})).$items{$_}; 21 | } 22 | 23 | my $unix_check = time(); 24 | 25 | $uwsgi_pkt .= pack('v', 4).'unix'.pack('v', length($unix_check)).$unix_check; 26 | 27 | my $signature = $rsa_priv->sign($uwsgi_pkt); 28 | 29 | $uwsgi_pkt .= pack('v', 4).'sign'.pack('v', length($signature)).$signature; 30 | 31 | 32 | my $udp = new IO::Socket::INET(PeerAddr => $ARGV[0], Proto => 'udp'); 33 | 34 | $udp->send(pack('CvC', 224, length($uwsgi_pkt), 0).$uwsgi_pkt); 35 | 36 | print ''.(length($uwsgi_pkt)+4).' bytes sent to '.$ARGV[0]."\n"; 37 | -------------------------------------------------------------------------------- /plugins/example/example_plugin.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern struct uwsgi_server uwsgi; 4 | 5 | static int uwsgi_example_init(){ 6 | uwsgi_log("i am the example plugin initialization function\n"); 7 | return 0; 8 | } 9 | 10 | static int uwsgi_example_request(struct wsgi_request *wsgi_req) { 11 | 12 | uwsgi_response_prepare_headers(wsgi_req, "200 OK", 6); 13 | uwsgi_response_add_header(wsgi_req, "Content-type", 12, "text/html", 9); 14 | uwsgi_response_write_body_do(wsgi_req, "

Hello World

", 20); 15 | 16 | return UWSGI_OK; 17 | } 18 | 19 | 20 | static void uwsgi_example_after_request(struct wsgi_request *wsgi_req) { 21 | uwsgi_log("i am the example plugin after request function\n"); 22 | } 23 | 24 | 25 | struct uwsgi_plugin example_plugin = { 26 | 27 | .name = "example", 28 | .modifier1 = 250, 29 | .init = uwsgi_example_init, 30 | .request = uwsgi_example_request, 31 | .after_request = uwsgi_example_after_request, 32 | 33 | }; 34 | 35 | -------------------------------------------------------------------------------- /t/ring/src/uwsgi/ring/tests/app.clj: -------------------------------------------------------------------------------- 1 | (ns uwsgi.ring.tests.app 2 | (:use compojure.core) 3 | (:use [ring.middleware params 4 | keyword-params 5 | nested-params 6 | multipart-params]) 7 | (:require [compojure.route :as route] 8 | [uwsgi.ring.tests.basic :as basic] 9 | [uwsgi.ring.tests.body :as body] 10 | [uwsgi.ring.tests.simple :as simple] 11 | [uwsgi.ring.tests.upload :as upload]) 12 | (:gen-class 13 | :main true)) 14 | 15 | (defn app-routes [req] 16 | (if (= (get req :uri) "/") 17 | (basic/index-page req) 18 | ((routes simple/app-routes body/app-routes upload/app-routes (route/not-found "

Page not found

")) req))) 19 | 20 | (def app 21 | (-> app-routes 22 | wrap-keyword-params 23 | wrap-nested-params 24 | wrap-params 25 | wrap-multipart-params)) 26 | 27 | (defn -main [& args] 28 | (println "uwsgi ring tests app loaded")) 29 | 30 | -------------------------------------------------------------------------------- /examples/simple_app.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | import os 3 | 4 | print("!!! uWSGI version:", uwsgi.version) 5 | 6 | 7 | def ciao(): 8 | print("modifica su /tmp") 9 | 10 | 11 | def ciao2(): 12 | print("nuovo uwsgi_server") 13 | print os.getpid() 14 | 15 | counter = 0 16 | 17 | #if uwsgi.load_plugin(0, 'plugins/example/example_plugin.so', 'ciao'): 18 | # print "example plugin loaded" 19 | #else: 20 | # print "unable to load example plugin" 21 | 22 | #uwsgi.event_add(uwsgi.EVENT_FILE, "/tmp", ciao) 23 | #uwsgi.event_add(uwsgi.EVENT_DNSSD, "_uwsgi._tcp", ciao2) 24 | #uwsgi.event_add(uwsgi.EVENT_TIMER, 1000, ciao2) 25 | 26 | uwsgi.post_fork_hook = ciao2 27 | 28 | 29 | def application(env, start_response): 30 | global counter 31 | 32 | start_response('200 Ok', [('Content-type', 'text/plain')]) 33 | yield "hello world" 34 | yield "hello world2" 35 | 36 | for i in range(1, 1000): 37 | yield str(i) 38 | 39 | yield "\n" 40 | 41 | yield str(counter) 42 | counter += 1 43 | -------------------------------------------------------------------------------- /tests/testgevent.py: -------------------------------------------------------------------------------- 1 | # uwsgi -s :3031 -M -p 4 --plugin gevent --loop gevent --async 1000 --enable-threads -w tests.testgevent 2 | from threading import Thread 3 | import gevent 4 | import uwsgi 5 | import time 6 | 7 | 8 | def microtask(wid): 9 | print "i am a gevent task" 10 | gevent.sleep(10) 11 | print "10 seconds elapsed in worker id %d" % wid 12 | 13 | 14 | def athread(): 15 | while True: 16 | time.sleep(1) 17 | print "i am the thread 1" 18 | 19 | 20 | def athread2(): 21 | while True: 22 | time.sleep(1) 23 | print "i am the thread 2" 24 | 25 | t1 = Thread(target=athread) 26 | t1.daemon = True 27 | t1.start() 28 | 29 | t2 = Thread(target=athread2) 30 | t2.daemon = True 31 | t2.start() 32 | 33 | 34 | def application(environ, start_response): 35 | 36 | gevent.sleep() 37 | start_response('200 OK', [('Content-Type', 'text/html')]) 38 | yield "sleeping for 3 seconds...
" 39 | gevent.sleep(3) 40 | yield "done
" 41 | gevent.spawn(microtask, uwsgi.worker_id()) 42 | yield "microtask started
" 43 | -------------------------------------------------------------------------------- /plugins/v8/v8_uwsgi.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // as we have isolates in multithread modes, we need to maintain 5 | // special tables for the handlers (mules and spooler just run on the core 0) 6 | struct uwsgi_v8_signal_table { 7 | v8::Persistent *func; 8 | uint8_t registered; 9 | }; 10 | 11 | struct uwsgi_v8_rpc_table { 12 | char *name; 13 | v8::Persistent *func; 14 | }; 15 | 16 | struct uwsgi_v8 { 17 | v8::Persistent *contexts; 18 | v8::Isolate **isolates; 19 | char *jsgi; 20 | v8::Persistent *jsgi_func; 21 | v8::Persistent *jsgi_writer_func; 22 | int jsgi_announced; 23 | struct uwsgi_string_list *load; 24 | struct uwsgi_v8_signal_table *sigtable; 25 | struct uwsgi_v8_rpc_table *rpctable; 26 | pthread_key_t current_core; 27 | int preemptive; 28 | uint64_t gc_freq; 29 | struct uwsgi_string_list *module_paths; 30 | }; 31 | 32 | v8::Persistent uwsgi_v8_load_jsgi(int, char *); 33 | -------------------------------------------------------------------------------- /core/clock.c: -------------------------------------------------------------------------------- 1 | #include "uwsgi.h" 2 | 3 | extern struct uwsgi_server uwsgi; 4 | 5 | int uwsgi_simple_wait_milliseconds_hook(int timeout) { 6 | return poll(NULL, 0, timeout); 7 | } 8 | 9 | 10 | // in the future we will need to use the best clock source for each os/system 11 | time_t uwsgi_now() { 12 | return uwsgi.clock->seconds(); 13 | } 14 | 15 | uint64_t uwsgi_micros() { 16 | return uwsgi.clock->microseconds(); 17 | } 18 | 19 | 20 | void uwsgi_register_clock(struct uwsgi_clock *clock) { 21 | struct uwsgi_clock *clocks = uwsgi.clocks; 22 | 23 | clock->next = NULL; 24 | 25 | if (!clocks) { 26 | uwsgi.clocks = clock; 27 | return; 28 | } 29 | 30 | while (clocks) { 31 | if (!clocks->next) { 32 | clocks->next = clock; 33 | return; 34 | } 35 | clocks = clocks->next; 36 | } 37 | } 38 | 39 | void uwsgi_set_clock(char *name) { 40 | struct uwsgi_clock *clocks = uwsgi.clocks; 41 | while (clocks) { 42 | if (!strcmp(name, clocks->name)) { 43 | uwsgi.clock = clocks; 44 | return; 45 | } 46 | clocks = clocks->next; 47 | } 48 | 49 | uwsgi_log("unable to set \"%s\" clock\n", name); 50 | exit(1); 51 | } 52 | -------------------------------------------------------------------------------- /tests/iobound_async.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | 3 | 4 | def send_request(env, client): 5 | 6 | uwsgi.send(client, b"GET /intl/it_it/images/logo.gif HTTP/1.0\r\n") 7 | 8 | # test for suspend/resume 9 | uwsgi.suspend() 10 | 11 | uwsgi.send(client, b"Host: www.google.it\r\n\r\n") 12 | 13 | while 1: 14 | yield uwsgi.wait_fd_read(client, 2) 15 | if env['x-wsgiorg.fdevent.timeout']: 16 | return 17 | 18 | buf = uwsgi.recv(client, 4096) 19 | if buf: 20 | yield buf 21 | else: 22 | break 23 | 24 | 25 | def application(env, start_response): 26 | 27 | c = uwsgi.async_connect('74.125.232.115:80') 28 | 29 | # wait for connection 30 | yield uwsgi.wait_fd_write(c, 2) 31 | 32 | if env['x-wsgiorg.fdevent.timeout']: 33 | uwsgi.close(c) 34 | raise StopIteration 35 | 36 | if uwsgi.is_connected(c): 37 | for r in send_request(env, c): 38 | yield r 39 | else: 40 | start_response('500 Internal Server Error', [('Content-Type', 'text/html')]) 41 | yield "Internal Server Error" 42 | 43 | uwsgi.close(c) 44 | -------------------------------------------------------------------------------- /contrib/graphite_uwsgi.py: -------------------------------------------------------------------------------- 1 | # uwsgi --master --chdir /opt/graphite/webapp/graphite --module graphite_uwsgi ... 2 | # 3 | # 4 | # this module will update a carbon server (used by the graphite tool: http://graphite.wikidot.com/) 5 | # with requests count made by a Django app (and can track graphite itself as it is a Django app ;) 6 | # 7 | # 8 | 9 | import os 10 | import uwsgi 11 | import time 12 | from django.core.handlers.wsgi import WSGIHandler 13 | 14 | os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' 15 | 16 | CARBON_SERVER = "127.0.0.1:2003" 17 | 18 | 19 | def update_carbon(signum): 20 | # connect to the carbon server 21 | carbon_fd = uwsgi.connect(CARBON_SERVER) 22 | # send data to the carbon server 23 | uwsgi.send(carbon_fd, "uwsgi.%s.requests %d %d\n" % (uwsgi.hostname, uwsgi.total_requests(), int(time.time()))) 24 | # close the connection with the carbon server 25 | uwsgi.close(carbon_fd) 26 | 27 | # register a new uwsgi signal (signum: 17) 28 | uwsgi.register_signal(17, '', update_carbon) 29 | 30 | # attach a timer of 10 seconds to signal 17 31 | uwsgi.add_timer(17, 10) 32 | 33 | # the Django app 34 | application = WSGIHandler() 35 | -------------------------------------------------------------------------------- /t/go/uploadtest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "uwsgi" 4 | import "net/http" 5 | import "fmt" 6 | import "io/ioutil" 7 | import "os" 8 | 9 | 10 | func viewHandler(w http.ResponseWriter, r *http.Request) { 11 | fmt.Fprintf(w, "
") 12 | } 13 | 14 | func postHandler(w http.ResponseWriter, r *http.Request) { 15 | foo := r.FormValue("foo") 16 | bar, handler, err := r.FormFile("bar") 17 | if err != nil { 18 | http.Error(w, err.Error(), http.StatusInternalServerError) 19 | return 20 | } 21 | bar_data, err := ioutil.ReadAll(bar) 22 | w.Header().Set("Content-Type", "text/plain") 23 | w.Header().Set("X-Server", "uWSGI") 24 | fmt.Fprintf(w, foo + "\n\n" + handler.Filename + "\n\n" + string(bar_data)) 25 | } 26 | 27 | func signal30(sig uint8) { 28 | fmt.Println("ciao") 29 | } 30 | 31 | func main() { 32 | fmt.Println(os.Args) 33 | uwsgi.RegisterSignal(30, "", signal30) 34 | http.HandleFunc("/view/", viewHandler) 35 | http.HandleFunc("/post/", postHandler) 36 | uwsgi.Run() 37 | } 38 | -------------------------------------------------------------------------------- /t/routing/errorlimiter.ini: -------------------------------------------------------------------------------- 1 | [uwsgi] 2 | plugins = geoip, router_cache 3 | http-socket = :9090 4 | 5 | ; 8 bytes blocksize is the right thing to do 6 | cache2 = name=limiter,items=1000,blocksize=8 7 | ; allows expiring items 8 | master = true 9 | 10 | ; get the cache value for the current ip (if any) 11 | route-run = cachevar:key=${REMOTE_ADDR},as_num=1,var=LIMIT 12 | ; block the peer if it did more than 10 404 requests in the last 30 seconds 13 | route-if = >:${LIMIT};10 goto:blockit 14 | ; end of routing 15 | route-run = last: 16 | 17 | 18 | module = werkzeug.testapp:test_app 19 | threads = 10 20 | 21 | ; track the user if a 404 is returned 22 | final-route-if = equal:${uwsgi[status]};404 goto:trackit 23 | ; end of final routing 24 | final-route-run = last: 25 | 26 | final-route-label = trackit 27 | ; increase the value in the 'limiter' cache 28 | final-route-run = cacheinc:key=${REMOTE_ADDR},expires=30 29 | ; increase the value if the connection is from italy !!! 30 | final-route-if = equal:${geoip[country_name]};Italy cacheinc:key=${REMOTE_ADDR},expires=30 31 | 32 | ; block the client 33 | route-label = blockit 34 | route-run = log:STOP YOU BASTARD !!! 35 | route-run = break:503 36 | -------------------------------------------------------------------------------- /tests/iobound_green.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | import socket 3 | import errno 4 | 5 | 6 | def send_request(env, client): 7 | 8 | client.setblocking(1) 9 | 10 | client.send(b"GET /intl/it_it/images/logo.gif HTTP/1.0\r\n") 11 | client.send(b"Host: www.google.it\r\n\r\n") 12 | 13 | uwsgi.green_schedule() 14 | 15 | while 1: 16 | uwsgi.green_wait_fdread(client.fileno(), 10) 17 | buf = client.recv(4096) 18 | if len(buf) == 0: 19 | break 20 | else: 21 | yield buf 22 | 23 | 24 | def application(env, start_response): 25 | 26 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 27 | s.setblocking(0) 28 | 29 | c = s.connect_ex(('74.125.77.104', 80)) 30 | if c == errno.EINPROGRESS: 31 | uwsgi.green_wait_fdwrite(s.fileno(), 10) 32 | for r in send_request(env, s): 33 | yield r 34 | elif c == errno.EISCONN: 35 | for r in send_request(env, s): 36 | yield r 37 | else: 38 | uwsgi.green_schedule() 39 | start_response('500 Internal Server Error', [('Content-Type', 'text/html')]) 40 | yield "Internal Server Error" 41 | 42 | s.close() 43 | -------------------------------------------------------------------------------- /tests/signals.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | 3 | 4 | def hello_signal(num, payload): 5 | print "i am the signal %d" % num 6 | 7 | 8 | def hello_signal2(num, payload): 9 | print "i am the signal %d with payload: %s" % (num, payload) 10 | 11 | 12 | def hello_file(num, filename): 13 | print "file %s has been modified !!!" % filename 14 | 15 | 16 | def hello_timer(num, secs): 17 | print "%s seconds elapsed" % secs 18 | 19 | # uwsgi.register_signal(30, uwsgi.SIGNAL_KIND_WORKER, hello_signal) 20 | uwsgi.register_signal(30, "workers", hello_signal) 21 | uwsgi.register_signal(22, "worker", hello_signal2, "*** PAYLOAD FOO ***") 22 | 23 | uwsgi.register_file_monitor(3, "/tmp", "workers", hello_file) 24 | uwsgi.register_timer(26, 2, "worker", hello_timer) 25 | uwsgi.register_timer(17, 4, "worker2", hello_timer) 26 | uwsgi.register_timer(5, 8, "worker3", hello_timer) 27 | 28 | 29 | def application(env, start_response): 30 | 31 | start_response('200 Ok', [('Content-Type', 'text/html')]) 32 | 33 | # this will send a signal to the master that will report it to the first available worker 34 | uwsgi.signal(30) 35 | uwsgi.signal(22) 36 | 37 | return "signals sent to workers" 38 | -------------------------------------------------------------------------------- /t/sharedarea/sharedarea_incdec.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | import unittest 3 | 4 | class SharedareaTest(unittest.TestCase): 5 | 6 | def setUp(self): 7 | uwsgi.sharedarea_write(0, 0, '\0' * 64) 8 | 9 | def test_32(self): 10 | uwsgi.sharedarea_write32(0, 0, 17) 11 | self.assertEqual(uwsgi.sharedarea_read32(0, 0), 17) 12 | 13 | def test_inc32(self): 14 | uwsgi.sharedarea_write32(0, 4, 30) 15 | uwsgi.sharedarea_inc32(0, 4, 3) 16 | self.assertEqual(uwsgi.sharedarea_read32(0, 4), 33) 17 | 18 | def test_dec32(self): 19 | uwsgi.sharedarea_write32(0, 5, 30) 20 | uwsgi.sharedarea_dec32(0, 5, 4) 21 | self.assertEqual(uwsgi.sharedarea_read32(0, 5), 26) 22 | 23 | def test_inc64(self): 24 | uwsgi.sharedarea_write64(0, 8, 17 * (1024 ** 5)) 25 | uwsgi.sharedarea_inc64(0, 8, 1) 26 | self.assertEqual(uwsgi.sharedarea_read64(0, 8), 17 * (1024 ** 5) + 1) 27 | 28 | def test_dec64(self): 29 | uwsgi.sharedarea_write64(0, 8, 30 * (1024 ** 5)) 30 | uwsgi.sharedarea_dec64(0, 8, 30 * (1024 ** 5) - 1) 31 | self.assertEqual(uwsgi.sharedarea_read64(0, 8), 1) 32 | 33 | 34 | unittest.main() 35 | -------------------------------------------------------------------------------- /t/python/spooler_decorators/spooler_decorator_tests.py: -------------------------------------------------------------------------------- 1 | # run it with: 2 | # export SPOOLER_DIR=t/python/spooler_priority/temporary_spooler; # or your spooler dir 3 | # ./uwsgi t/python/spooler_decorators/spooler_decorator_test.ini 4 | 5 | import unittest 6 | import uwsgi 7 | import spooler_handlers 8 | from os import remove, path 9 | 10 | 11 | class BitmapTest(unittest.TestCase): 12 | 13 | def setUp(self): 14 | try: 15 | remove(spooler_handlers.ghostpath) 16 | except OSError: # file does not exist 17 | pass 18 | 19 | spooler_handlers.controlled_task.spool(arg='alive', ghost='world') 20 | spooler_handlers.controlled_task.spool(arg='barbis') 21 | spooler_handlers.controlled_raw_task.spool(arg='alive', ghost='world') 22 | spooler_handlers.controlled_raw_task.spool(arg='barbis') 23 | spooler_handlers.controlled_arguments_task.spool( 24 | {'key': 'value'}, 2, key1='value1') 25 | 26 | for i in range(5): 27 | uwsgi.signal_wait(20) 28 | print("Signal received!") 29 | 30 | def test_spooler(self): 31 | self.assertFalse(path.exists(spooler_handlers.ghostpath)) 32 | 33 | unittest.main() 34 | -------------------------------------------------------------------------------- /plugins/php/session.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | PS_OPEN_FUNC(uwsgi) { 4 | PS_SET_MOD_DATA((char *)save_path); 5 | return SUCCESS; 6 | } 7 | 8 | PS_CLOSE_FUNC(uwsgi) { 9 | return SUCCESS; 10 | } 11 | 12 | PS_READ_FUNC(uwsgi) { 13 | char *cache = PS_GET_MOD_DATA(); 14 | uint64_t valsize = 0; 15 | char *value = uwsgi_cache_magic_get((char *)key, strlen(key), &valsize, NULL, cache); 16 | if (!value) return FAILURE; 17 | char *new_val = emalloc(valsize); 18 | memcpy(new_val, value, valsize); 19 | free(value); 20 | *val = new_val; 21 | *vallen = valsize; 22 | return SUCCESS; 23 | 24 | } 25 | 26 | PS_WRITE_FUNC(uwsgi) { 27 | char *cache = PS_GET_MOD_DATA(); 28 | if (vallen == 0) return SUCCESS; 29 | if (!uwsgi_cache_magic_set((char *)key, strlen(key), (char *)val, vallen, 0, UWSGI_CACHE_FLAG_UPDATE, cache)) { 30 | return SUCCESS; 31 | } 32 | return FAILURE; 33 | } 34 | 35 | PS_DESTROY_FUNC(uwsgi) { 36 | char *cache = PS_GET_MOD_DATA(); 37 | if (!uwsgi_cache_magic_del((char *)key, strlen(key), cache)) { 38 | return SUCCESS; 39 | } 40 | return FAILURE; 41 | } 42 | 43 | PS_GC_FUNC(uwsgi) { 44 | return SUCCESS; 45 | } 46 | 47 | ps_module ps_mod_uwsgi = { 48 | PS_MOD(uwsgi) 49 | }; 50 | 51 | -------------------------------------------------------------------------------- /plugins/v8/plugin.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int uwsgi_v8_init(void); 4 | void uwsgi_v8_apps(void); 5 | void uwsgi_v8_configurator(char *, char **); 6 | uint64_t uwsgi_v8_rpc(void *, uint8_t, char **, uint16_t *, char **); 7 | int uwsgi_v8_signal_handler(uint8_t, void *); 8 | void uwsgi_v8_init_thread(int); 9 | void uwsgi_v8_enable_threads(); 10 | int uwsgi_v8_mule(char *); 11 | 12 | static void uwsgi_v8_register(void) { 13 | uwsgi_register_configurator(".js", uwsgi_v8_configurator); 14 | } 15 | 16 | extern struct uwsgi_option uwsgi_v8_options[]; 17 | 18 | int uwsgi_v8_request(struct wsgi_request *); 19 | 20 | static void uwsgi_v8_after_request(struct wsgi_request *wsgi_req) { 21 | log_request(wsgi_req); 22 | } 23 | 24 | struct uwsgi_plugin v8_plugin = { 25 | .name = "v8", 26 | .modifier1 = 24, 27 | .init = uwsgi_v8_init, 28 | .init_apps = uwsgi_v8_apps, 29 | .options = uwsgi_v8_options, 30 | .on_load = uwsgi_v8_register, 31 | .rpc = uwsgi_v8_rpc, 32 | .request = uwsgi_v8_request, 33 | .after_request = uwsgi_v8_after_request, 34 | .signal_handler = uwsgi_v8_signal_handler, 35 | .enable_threads = uwsgi_v8_enable_threads, 36 | .init_thread = uwsgi_v8_init_thread, 37 | .mule = uwsgi_v8_mule, 38 | }; 39 | -------------------------------------------------------------------------------- /plugins/rack/uwsgi_rack.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #ifndef RUBY19 6 | #include 7 | #define rb_errinfo() ruby_errinfo 8 | #endif 9 | 10 | #ifndef RARRAY_LEN 11 | #define RARRAY_LEN(x) RARRAY(x)->len 12 | #endif 13 | 14 | #ifndef RARRAY_PTR 15 | #define RARRAY_PTR(x) RARRAY(x)->ptr 16 | #endif 17 | 18 | #ifndef RSTRING_PTR 19 | #define RSTRING_PTR(x) RSTRING(x)->ptr 20 | #endif 21 | 22 | #ifndef RSTRING_LEN 23 | #define RSTRING_LEN(x) RSTRING(x)->len 24 | #endif 25 | 26 | struct uwsgi_rack { 27 | 28 | char *rails; 29 | char *rack; 30 | int gc_freq; 31 | uint64_t cycles; 32 | 33 | int call_gc; 34 | 35 | // why why why !!!!????!!!??? 36 | VALUE signals_protector; 37 | VALUE rpc_protector; 38 | 39 | VALUE dollar_zero; 40 | 41 | VALUE dispatcher; 42 | VALUE rb_uwsgi_io_class; 43 | ID call; 44 | 45 | char *rbshell; 46 | int rb_shell_oneshot; 47 | int app_id; 48 | 49 | int unprotected; 50 | 51 | struct uwsgi_string_list *rbrequire; 52 | struct uwsgi_string_list *shared_rbrequire; 53 | struct uwsgi_string_list *rvm_path; 54 | 55 | char *gemset; 56 | 57 | struct uwsgi_string_list *libdir; 58 | }; 59 | 60 | void uwsgi_rack_init_api(void); 61 | -------------------------------------------------------------------------------- /tests/pgbound_async.py: -------------------------------------------------------------------------------- 1 | import psycopg2 2 | 3 | 4 | def pg_wait(conn, env, timeout=0): 5 | while 1: 6 | state = conn.poll() 7 | if state == psycopg2.extensions.POLL_OK: 8 | raise StopIteration 9 | elif state == psycopg2.extensions.POLL_WRITE: 10 | yield env['x-wsgiorg.fdevent.writable'](conn.fileno(), timeout) 11 | elif state == psycopg2.extensions.POLL_READ: 12 | yield env['x-wsgiorg.fdevent.readable'](conn.fileno(), timeout) 13 | else: 14 | raise psycopg2.OperationalError("poll() returned %s" % state) 15 | 16 | 17 | def application(env, start_response): 18 | 19 | start_response('200 OK', [('Content-Type', 'text/html')]) 20 | 21 | connection = psycopg2.connect(database='uwsgi', user='uwsgi', password='uwsgi', host='192.168.173.100', async=1) 22 | 23 | for i in pg_wait(connection, env, 3): 24 | yield i 25 | 26 | print "connected" 27 | cursor = connection.cursor() 28 | 29 | cursor.execute("SELECT * FROM foo") 30 | 31 | for i in pg_wait(cursor.connection, env, 3): 32 | yield i 33 | 34 | print "query result available" 35 | 36 | for record in cursor: 37 | yield str(record) 38 | 39 | connection.close() 40 | -------------------------------------------------------------------------------- /contrib/spoolqueue/tasksconsumer.py: -------------------------------------------------------------------------------- 1 | from uwsgidecorators import spool 2 | import Queue 3 | from threading import Thread 4 | 5 | queues = {} 6 | 7 | 8 | class queueconsumer(object): 9 | 10 | def __init__(self, name, num=1, **kwargs): 11 | self.name = name 12 | self.num = num 13 | self.queue = Queue.Queue() 14 | self.threads = [] 15 | self.func = None 16 | queues[self.name] = self 17 | 18 | @staticmethod 19 | def consumer(self): 20 | while True: 21 | req = self.queue.get() 22 | print req 23 | self.func(req) 24 | self.queue.task_done() 25 | 26 | def __call__(self, f): 27 | self.func = f 28 | for i in range(self.num): 29 | t = Thread(target=self.consumer, args=(self,)) 30 | self.threads.append(t) 31 | t.daemon = True 32 | t.start() 33 | 34 | 35 | @spool 36 | def spooler_enqueuer(arguments): 37 | if 'queue' in arguments: 38 | queue = arguments['queue'] 39 | queues[queue].queue.put(arguments) 40 | else: 41 | raise Exception("You have to specify a queue name") 42 | 43 | 44 | def enqueue(*args, **kwargs): 45 | return spooler_enqueuer.spool(*args, **kwargs) 46 | -------------------------------------------------------------------------------- /t/ring/src/uwsgi/ring/tests/basic.clj: -------------------------------------------------------------------------------- 1 | (ns uwsgi.ring.tests.basic) 2 | 3 | (defn index-page [req] {:status 200 4 | :headers { "Content-Type" "text/html" , "Server" "uWSGI" } 5 | :body (str "

Ring test suites

" 6 | "

Simple tests

" 7 | "" 12 | "

Body type tests

" 13 | "" 18 | "

Upload tests

" 19 | "
" 20 | "

" 21 | "Please select a file
" 22 | "" 23 | "

" 24 | "" 25 | "
" 26 | "

Other tests

" 27 | "
    " 28 | "
  • ...
  • " 29 | "
")}) 30 | 31 | -------------------------------------------------------------------------------- /tests/Responder.pm: -------------------------------------------------------------------------------- 1 | package Responder; 2 | 3 | sub new { 4 | my $class = shift; 5 | 6 | my $self = { 7 | _env => shift, 8 | _counter => 0, 9 | _fd => -1, 10 | }; 11 | 12 | bless $self, $class; 13 | 14 | return $self; 15 | } 16 | 17 | sub getline { 18 | my $self = shift; 19 | 20 | if ($self->{_counter} > 10) { 21 | return undef; 22 | } 23 | elsif ($self->{_counter} == 3) { 24 | $self->{_counter}++; 25 | $self->{_fd} = uwsgi::async_connect("81.174.68.52:80"); 26 | return uwsgi::wait_fd_write($self->{_fd}, 3); 27 | } 28 | elsif ($self->{_counter} == 4) { 29 | $self->{_counter}++; 30 | return "connected to http://projects.unbit.it
"; 31 | } 32 | elsif ($self->{_counter} == 7) { 33 | $self->{_counter}++; 34 | print "suspending the app...\n"; 35 | uwsgi::async_sleep(3); 36 | uwsgi::suspend(); 37 | print "resumed the app\n"; 38 | return "Suspended and Resumed the app
"; 39 | } 40 | elsif ($self->{_counter} % 2 == 0) { 41 | $self->{_counter}++; 42 | print "sleeping...\n"; 43 | return uwsgi::async_sleep(1); 44 | } 45 | else { 46 | $self->{_counter}++; 47 | return "Hello World ".$self->{_counter}."
"; 48 | } 49 | } 50 | 51 | sub close { 52 | my $self = shift; 53 | uwsgi::log("goodbye...\n"); 54 | } 55 | 56 | 1 57 | -------------------------------------------------------------------------------- /examples/welcome3.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | import os 3 | 4 | 5 | def xsendfile(e, sr): 6 | sr('200 OK', [('Content-Type', 'image/png'), ('X-Sendfile', os.path.abspath('logo_uWSGI.png'))]) 7 | return b'' 8 | 9 | 10 | def serve_logo(e, sr): 11 | sr('200 OK', [('Content-Type', 'image/png')]) 12 | return uwsgi.sendfile('logo_uWSGI.png') 13 | 14 | 15 | def serve_config(e, sr): 16 | sr('200 OK', [('Content-Type', 'text/html')]) 17 | for opt in uwsgi.opt.keys(): 18 | body = "{opt} = {optvalue}
".format(opt=opt, optvalue=uwsgi.opt[opt].decode('ascii')) 19 | yield bytes(body.encode('ascii')) 20 | 21 | routes = {} 22 | routes['/xsendfile'] = xsendfile 23 | routes['/logo'] = serve_logo 24 | routes['/config'] = serve_config 25 | 26 | 27 | def application(env, start_response): 28 | 29 | if env['PATH_INFO'] in routes: 30 | return routes[env['PATH_INFO']](env, start_response) 31 | 32 | start_response('200 OK', [('Content-Type', 'text/html')]) 33 | 34 | body = """ 35 | version {version}
36 |
37 | 38 | Configuration
39 |
40 | 41 |
42 | 43 | """.format(version=uwsgi.version.decode('ascii')) 44 | 45 | return bytes(body.encode('ascii')) 46 | -------------------------------------------------------------------------------- /tests/psycogreen_green.py: -------------------------------------------------------------------------------- 1 | import uwsgi 2 | import psycopg2 3 | 4 | 5 | def ugreen_wait_callback(conn, timeout=-1): 6 | """A wait callback useful to allow uWSGI/uGreen to work with Psycopg.""" 7 | while True: 8 | state = conn.poll() 9 | if state == psycopg2.extensions.POLL_OK: 10 | break 11 | elif state == psycopg2.extensions.POLL_READ: 12 | uwsgi.green_wait_fdread(conn.fileno()) 13 | elif state == psycopg2.extensions.POLL_WRITE: 14 | uwsgi.green_wait_fdwrite(conn.fileno()) 15 | else: 16 | raise Exception("Unexpected result from poll: %r", state) 17 | 18 | 19 | # set the wait callback 20 | psycopg2.extensions.set_wait_callback(ugreen_wait_callback) 21 | 22 | 23 | def application(env, start_response): 24 | 25 | start_response('200 Ok', [('Content-type', 'text/html')]) 26 | 27 | # connect 28 | conn = psycopg2.connect("dbname=prova user=postgres") 29 | # get cursor 30 | curs = conn.cursor() 31 | 32 | yield "" 33 | 34 | # run query 35 | curs.execute("SELECT * FROM tests") 36 | 37 | while True: 38 | row = curs.fetchone() 39 | if not row: 40 | break 41 | yield "" % str(row) 42 | 43 | yield "
%s
" 44 | 45 | conn.close() 46 | -------------------------------------------------------------------------------- /t/go/complextest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "uwsgi" 4 | import "fmt" 5 | import "net/http" 6 | import "time" 7 | 8 | func postfork() { 9 | if uwsgi.WorkerId() == 0 { 10 | fmt.Println("PoSt FoRk on mule", uwsgi.MuleId(), "!!!") 11 | } else { 12 | fmt.Println("PoSt FoRk on worker", uwsgi.WorkerId(), "!!!") 13 | } 14 | } 15 | 16 | func request_handler(w http.ResponseWriter, r *http.Request) { 17 | uwsgi.Signal(17) 18 | fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:]) 19 | fmt.Fprintf(w, "

Hi there, I love %s!

", r.URL.Path[1:]) 20 | fmt.Println("LOGSIZE: ", uwsgi.LogSize()) 21 | uwsgi.Alarm("jabber", "Hello") 22 | go slow() 23 | } 24 | 25 | func hello(signum int) { 26 | fmt.Println("Ciao, 3 seconds elapsed or RequestHandler() called") 27 | } 28 | 29 | func hello2(signum int) { 30 | fmt.Println("I am an rb_timer running on mule", uwsgi.MuleId()) 31 | } 32 | 33 | func slow() { 34 | time.Sleep(8 * time.Second) 35 | fmt.Println("8 seconds ELAPSED !!!") 36 | } 37 | 38 | func postinit() { 39 | uwsgi.RegisterSignal(17, "", hello) 40 | uwsgi.AddTimer(17, 3) 41 | 42 | uwsgi.RegisterSignal(30, "mule1", hello2) 43 | uwsgi.AddTimer(30, 5) 44 | } 45 | 46 | 47 | func main() { 48 | uwsgi.PostInit(postinit) 49 | uwsgi.PostFork(postfork) 50 | uwsgi.RequestHandler(request_handler) 51 | uwsgi.Run() 52 | } 53 | -------------------------------------------------------------------------------- /t/perl/run: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use TAP::Harness; 7 | 8 | my $cpus = `nproc`; 9 | my @perls = qw/ 10 | 5.20.2 11 | 5.18.4 12 | 5.16.3 13 | 5.14.4 14 | 5.12.4 15 | 5.10.1 16 | 5.8.9 17 | /; 18 | 19 | my %installed; 20 | @installed{ map /(uwsgi-perl-[-\w.]+)/ ? $1 : (), `perlbrew list` } = (); 21 | 22 | my $tap = TAP::Harness->new( { verbosity => 1 } ); 23 | 24 | for my $perl (@perls) { 25 | for my $thread (0, 1) { 26 | my $name = $ENV{UWSGI_PERL} = 27 | 'uwsgi-perl-' . $perl . ( '-thread' x $thread ); 28 | 29 | warn "\n# $name\n\n"; 30 | 31 | # Install required perlbrew, unless already installed. 32 | system 'perlbrew', 'install', $perl, 33 | '--as', $name, '-D', 'useshrplib', '-j', $cpus, '-n', '--noman', 34 | ('--thread') x $thread and die $! 35 | unless exists $installed{$name}; 36 | 37 | # Clean previously compiled uWSGI. 38 | system 'python', 'uwsgiconfig.py', '-c' and die $!; 39 | 40 | # Compile uWSGI, only show STDERR. 41 | `perlbrew exec --with $name python uwsgiconfig.py -b plonly`; 42 | exit if $?; 43 | 44 | my $res = $tap->runtests( @ARGV ? @ARGV : ); 45 | 46 | exit $res->exit if $res->exit; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /examples/multi.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | 11 | psgi 12 | rack 13 | 14 | :9090 15 | 16 | :3031 17 | 127.0.0.1:3032 18 | 19 | 20 | 21 | 22 | 8 23 | 24 | 28 | 29 | TRAC_ENV=utrac 30 | 31 | 32 | 33 | werkzeug.testapp:test_app 34 | 35 | 36 | werkzeug.testapp:test_app 37 | 38 | 39 | trac.web.main:dispatch_request 40 | 41 | 42 | 43 | werkzeug.testapp:test_app 44 | 45 | 46 | 47 | 48 | 49 | from bzrlib.transport.http import wsgi 50 | application = wsgi.make_app("mybzr", "/bzr", readonly=False) 51 | 52 | 53 | 54 | 55 | trac.web.main:dispatch_request 56 | 57 | 58 | 59 | config2.ru 60 | 61 | 62 | 63 | test.psgi 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /core/querystring.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | 5 | QUERY_STRING management functions (mainly used by the internal routing subsystem) 6 | 7 | */ 8 | 9 | static char *check_qs(char *qs, uint16_t qs_len, char *key, uint16_t keylen, uint16_t *vallen) { 10 | // search for the equal sign 11 | char *equal = memchr(qs, '=', qs_len); 12 | if (!equal) return NULL; 13 | 14 | if (uwsgi_strncmp(key, keylen, qs, equal-qs)) { 15 | return NULL; 16 | } 17 | 18 | qs_len -= (equal-qs)+1; 19 | if (qs_len == 0) return NULL; 20 | 21 | *vallen = qs_len; 22 | return equal+1; 23 | } 24 | 25 | char *uwsgi_get_qs(struct wsgi_request *wsgi_req, char *key, uint16_t keylen, uint16_t *vallen) { 26 | uint16_t i; 27 | 28 | char *qs = wsgi_req->query_string; 29 | uint16_t qs_len = 0; 30 | char *ptr = wsgi_req->query_string; 31 | //start splitting by ; 32 | for(i=0;iquery_string_len;i++) { 33 | if (!qs) { 34 | qs = ptr + i; 35 | } 36 | if (ptr[i] == '&') { 37 | char *value = check_qs(qs, qs_len, key, keylen, vallen); 38 | if (value) { 39 | return value; 40 | } 41 | qs_len = 0; 42 | qs = NULL; 43 | } 44 | else { 45 | qs_len++; 46 | } 47 | } 48 | 49 | if (qs_len > 0) { 50 | char *value = check_qs(qs, qs_len, key, keylen, vallen); 51 | if (value) { 52 | return value; 53 | } 54 | } 55 | 56 | return NULL; 57 | } 58 | -------------------------------------------------------------------------------- /t/pypy/t_continulet1.py: -------------------------------------------------------------------------------- 1 | """ 2 | simplified test for continulet without checking for partial writes 3 | 4 | to enable continulets you only need to call uwsgi_pypy_setup_continulets() soon after startup: 5 | 6 | uwsgi --pypy-wsgi-file t/pypy/t_continulet1.py --http-socket :9090 --pypy-home /opt/pypy --pypy-eval "uwsgi_pypy_setup_continulets()" --async 8 7 | 8 | """ 9 | import uwsgi 10 | 11 | 12 | def application(e, sr): 13 | sr('200 OK', [('Content-Type', 'text/plain')]) 14 | 15 | # call suspend 10 times and yield some value 16 | for i in range(0, 10): 17 | print i 18 | uwsgi.suspend() 19 | yield str(i) 20 | 21 | # connect to a memcached server 22 | fd = uwsgi.async_connect('127.0.0.1:11211') 23 | try: 24 | # start waiting for socket availability (4 seconds max) 25 | uwsgi.wait_fd_write(fd, 4) 26 | # suspend execution 'til event 27 | uwsgi.suspend() 28 | uwsgi.send(fd, "get /foobar\r\n") 29 | # now wait for memcached response 30 | uwsgi.wait_fd_read(fd, 4) 31 | uwsgi.suspend() 32 | # read the response 33 | data = uwsgi.recv(fd, 4096) 34 | # return to the client 35 | yield data 36 | finally: 37 | uwsgi.close(fd) 38 | 39 | print "sleeping for 3 seconds..." 40 | uwsgi.async_sleep(3) 41 | uwsgi.suspend() 42 | yield "done" 43 | -------------------------------------------------------------------------------- /core/storage.c: -------------------------------------------------------------------------------- 1 | #include "../uwsgi.h" 2 | 3 | /* 4 | 5 | Storage subsystem: filesystem-like abstraction 6 | 7 | struct uwsgi_storage_engine { 8 | char *name; 9 | uint16_t name_len; 10 | int64_t (*get)(char *, uint16_t, char *, uint64_t, uint64_t, uint64_t); 11 | int64_t (*set)(char *, uint16_t, char *, uint64_t, uint64_t, uint64_t); 12 | }; 13 | 14 | struct uwsgi_storage { 15 | char *name; 16 | uint16_t name_len; 17 | struct uwsgi_storage_engine *engine; 18 | }; 19 | 20 | 21 | 22 | */ 23 | 24 | struct uwsgi_storage* uwsgi_storage_by_name(char *name, uint16_t name_len) { 25 | if (!name_len) { 26 | name_len = strlen(name); 27 | } 28 | struct uwsgi_storage *s = uwsgi.virtualdisks; 29 | while(s) { 30 | if (!uwsgi_strncmp(s->name, s->name_len, name, name_len)) { 31 | return s; 32 | } 33 | s = s->next; 34 | } 35 | 36 | return NULL; 37 | } 38 | 39 | int64_t uwsgi_storage_get(struct uwsgi_storage *storage, char *key, uint16_t key_len, char *out_buf, uint64_t pos, uint64_t size, uint64_t flags) { 40 | if (!storage->get) return -1; 41 | return storage->get(key, key_len, out_buf, pos, size, flags); 42 | } 43 | 44 | int64_t uwsgi_storage_set(struct uwsgi_storage *storage, char *key, uint16_t key_len, char *in_buf, uint64_t pos, uint64_t size, uint64_t flags) { 45 | if (!storage->set) return -1; 46 | return storage->set(key, key_len, out_buf, pos, size, flags); 47 | } 48 | -------------------------------------------------------------------------------- /plugins/fiber/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | NAME = 'fiber' 4 | 5 | try: 6 | RUBYPATH = os.environ['UWSGICONFIG_RUBYPATH'] 7 | except: 8 | RUBYPATH = 'ruby' 9 | 10 | 11 | CFLAGS = os.popen(RUBYPATH + " -e \"require 'rbconfig';print RbConfig::CONFIG['CFLAGS']\"").read().rstrip().split() 12 | CFLAGS.append('-DRUBY19') 13 | CFLAGS.append('-Wno-unused-parameter') 14 | rbconfig = 'RbConfig' 15 | 16 | includedir = os.popen(RUBYPATH + " -e \"require 'rbconfig';print %s::CONFIG['rubyhdrdir']\"" % rbconfig).read().rstrip() 17 | if includedir == 'nil': 18 | includedir = os.popen(RUBYPATH + " -e \"require 'rbconfig';print %s::CONFIG['archdir']\"" % rbconfig).read().rstrip() 19 | CFLAGS.append('-I' + includedir) 20 | else: 21 | CFLAGS.append('-I' + includedir) 22 | archdir = os.popen(RUBYPATH + " -e \"require 'rbconfig';print %s::CONFIG['archdir']\"" % rbconfig).read().rstrip() 23 | arch = os.popen(RUBYPATH + " -e \"require 'rbconfig';print %s::CONFIG['arch']\"" % rbconfig).read().rstrip() 24 | CFLAGS.append('-I' + archdir) 25 | CFLAGS.append('-I' + archdir + '/' + arch) 26 | CFLAGS.append('-I' + includedir + '/' + arch) 27 | archdir2 = os.popen(RUBYPATH + " -e \"require 'rbconfig';print %s::CONFIG['rubyarchhdrdir']\"" % rbconfig).read().rstrip() 28 | if archdir2: 29 | CFLAGS.append('-I' + archdir2) 30 | 31 | LDFLAGS = [] 32 | LIBS = [] 33 | 34 | GCC_LIST = ['fiber'] 35 | -------------------------------------------------------------------------------- /plugins/rbthreads/uwsgiplugin.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | NAME = 'rbthreads' 4 | 5 | try: 6 | RUBYPATH = os.environ['UWSGICONFIG_RUBYPATH'] 7 | except: 8 | RUBYPATH = 'ruby' 9 | 10 | 11 | CFLAGS = os.popen(RUBYPATH + " -e \"require 'rbconfig';print RbConfig::CONFIG['CFLAGS']\"").read().rstrip().split() 12 | CFLAGS.append('-DRUBY19') 13 | CFLAGS.append('-Wno-unused-parameter') 14 | rbconfig = 'RbConfig' 15 | 16 | includedir = os.popen(RUBYPATH + " -e \"require 'rbconfig';print %s::CONFIG['rubyhdrdir']\"" % rbconfig).read().rstrip() 17 | if includedir == 'nil': 18 | includedir = os.popen(RUBYPATH + " -e \"require 'rbconfig';print %s::CONFIG['archdir']\"" % rbconfig).read().rstrip() 19 | CFLAGS.append('-I' + includedir) 20 | else: 21 | CFLAGS.append('-I' + includedir) 22 | archdir = os.popen(RUBYPATH + " -e \"require 'rbconfig';print %s::CONFIG['archdir']\"" % rbconfig).read().rstrip() 23 | arch = os.popen(RUBYPATH + " -e \"require 'rbconfig';print %s::CONFIG['arch']\"" % rbconfig).read().rstrip() 24 | CFLAGS.append('-I' + archdir) 25 | CFLAGS.append('-I' + archdir + '/' + arch) 26 | CFLAGS.append('-I' + includedir + '/' + arch) 27 | archdir2 = os.popen(RUBYPATH + " -e \"require 'rbconfig';print %s::CONFIG['rubyarchhdrdir']\"" % rbconfig).read().rstrip() 28 | if archdir2: 29 | CFLAGS.append('-I' + archdir2) 30 | 31 | LDFLAGS = [] 32 | LIBS = [] 33 | 34 | GCC_LIST = ['rbthreads'] 35 | -------------------------------------------------------------------------------- /core/timebomb.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | 5 | uWSGI timebomb 6 | 7 | this is a simple thread waiting for a timeout and calling exit 8 | with the specified value. 9 | 10 | You can use it as a last resort in async apps that could block 11 | normal uWSGI behaviours 12 | 13 | */ 14 | 15 | struct time_bomb { 16 | int timeout; 17 | int exit_code; 18 | }; 19 | 20 | static void *time_bomb(void *arg) { 21 | 22 | // block all signals 23 | sigset_t smask; 24 | sigfillset(&smask); 25 | pthread_sigmask(SIG_BLOCK, &smask, NULL); 26 | 27 | struct time_bomb *tb = (struct time_bomb *) arg; 28 | 29 | struct timeval tv; 30 | tv.tv_sec = tb->timeout; 31 | tv.tv_usec = 0; 32 | 33 | select(0, NULL, NULL, NULL, &tv); 34 | uwsgi_log_verbose("*** BOOOOOOM ***\n"); 35 | exit(tb->exit_code); 36 | 37 | } 38 | 39 | void uwsgi_time_bomb(int timeout, int exit_code) { 40 | 41 | pthread_t time_bomb_thread; 42 | 43 | struct time_bomb *tb = uwsgi_malloc(sizeof(struct time_bomb)); 44 | tb->timeout = timeout; 45 | tb->exit_code = exit_code; 46 | 47 | if (pthread_create(&time_bomb_thread, NULL, time_bomb, (void *) tb)) { 48 | uwsgi_error("pthread_create()"); 49 | uwsgi_log("unable to setup the time bomb, goodbye\n"); 50 | exit(exit_code); 51 | } 52 | else { 53 | uwsgi_log_verbose("Fire in the hole !!! (%d seconds to detonation)\n", timeout); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /examples/config30.ru: -------------------------------------------------------------------------------- 1 | require 'stringio' 2 | require 'uwsgidsl' 3 | 4 | 5 | 6 | signal 17,'mule5' do |signum| 7 | end 8 | 9 | puts UWSGI::VERSION 10 | puts UWSGI::NUMPROC 11 | puts UWSGI::HOSTNAME 12 | 13 | puts UWSGI::OPT.inspect 14 | 15 | timer 2 do |signum| 16 | puts "ciao sono un dsl ruby: #{signum} #{UWSGI::OPT.inspect}" 17 | end 18 | 19 | timer 1,'mule1' do |signum| 20 | puts "1 second elapsed (signum #{signum})" 21 | end 22 | 23 | filemon '/tmp' do |signum| 24 | puts "/tmp has been modified" 25 | end 26 | 27 | cron 5,-1,-1,-1,-1 do |signum| 28 | puts "cron ready #{signum}" 29 | end 30 | 31 | cron 58,-1,-1,-1,-1 do |signum| 32 | puts "cron ready #{signum}" 33 | end 34 | 35 | postfork do 36 | puts "fork() called" 37 | end 38 | 39 | rpc 'pippo' do 40 | "i am an rpc function" 41 | end 42 | 43 | rpc 'pluto' do |x,y| 44 | "i am another rpc function #{x} #{y}" 45 | end 46 | 47 | begin 48 | foo_func 49 | rescue 50 | end 51 | 52 | puts UWSGI.cache_exists('nilkey') 53 | puts UWSGI.cache_exists?('nilkey') 54 | 55 | UWSGI.cache_set!('foobar_key?a=1', UWSGI::OPT.inspect) 56 | begin 57 | puts UWSGI.cache_get(nil) 58 | rescue 59 | end 60 | puts UWSGI.cache_get('foobar_key?a=1') 61 | 62 | 63 | run lambda { |env| 64 | puts env.inspect 65 | UWSGI.setprocname("i am the uWSGI rack plugin") 66 | UWSGI.signal(17) 67 | [200, {'Content-Type'=>'text/plain'}, StringIO.new("Hello World! #{UWSGI.mem.inspect}\n")] 68 | } 69 | -------------------------------------------------------------------------------- /tests/iobound_async_unix.py: -------------------------------------------------------------------------------- 1 | import socket 2 | import errno 3 | import struct 4 | 5 | 6 | def send_request(env, client): 7 | 8 | client.setblocking(1) 9 | 10 | data = "hello world\r\n" 11 | 12 | # send uwsgi-echo header 13 | client.send(struct.pack('" 38 | 39 | curs.execute("SELECT * FROM tests") 40 | 41 | # suspend until result 42 | async_wait(curs) 43 | 44 | while True: 45 | row = curs.fetchone() 46 | if not row: 47 | break 48 | yield "%s" % str(row) 49 | 50 | yield "" 51 | 52 | conn.close() 53 | -------------------------------------------------------------------------------- /plugins/logpipe/logpipe.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | 5 | The pipe logger 6 | 7 | Author: INADA Naoki 8 | 9 | every log line is sent to the stdin of an external process 10 | 11 | Example: 12 | 13 | req-logger = pipe:/usr/local/bin/mylogger 14 | 15 | */ 16 | 17 | static ssize_t uwsgi_pipe_logger(struct uwsgi_logger *ul, char *message, size_t len) { 18 | if (!ul->configured) { 19 | if (ul->arg) { 20 | int pipefd[2]; 21 | // retry later... 22 | if (pipe(pipefd) < 0) return -1; 23 | pid_t pid = fork(); 24 | if (pid < 0) return -1; 25 | if (pid > 0) { 26 | close(pipefd[0]); 27 | ul->fd = pipefd[1]; 28 | } 29 | else { 30 | // child 31 | if (setsid() < 0) { 32 | uwsgi_error("setsid()"); 33 | exit(1); 34 | } 35 | close(pipefd[1]); 36 | dup2(pipefd[0], STDIN_FILENO); 37 | close(pipefd[0]); 38 | uwsgi_exec_command_with_args(ul->arg); 39 | exit(1); // if here something seriously failed 40 | } 41 | } 42 | 43 | ul->configured = 1; 44 | } 45 | 46 | int err = write(ul->fd, message, len); 47 | // on failed writes, re-configure the logger 48 | if (err <= 0) { 49 | close(ul->fd); 50 | ul->configured = 0; 51 | return err; 52 | } 53 | return 0; 54 | } 55 | 56 | static void uwsgi_pipe_logger_register() { 57 | uwsgi_register_logger("pipe", uwsgi_pipe_logger); 58 | } 59 | 60 | struct uwsgi_plugin logpipe_plugin = { 61 | .name = "logpipe", 62 | .on_load = uwsgi_pipe_logger_register, 63 | }; 64 | -------------------------------------------------------------------------------- /tests/templates/queue.html: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | {% with messages = get_flashed_messages() %} 10 | {% if messages %} 11 |
12 |
    13 | {% for message in messages %} 14 |
  • {{ message }}
  • 15 | {% endfor %} 16 |
17 |
18 | {% endif %} 19 | {% endwith %} 20 |

next available slot: {{uwsgi.queue_slot()}}

21 |

next available pull slot: {{uwsgi.queue_pull_slot()}}

22 | {% for item in range(0, uwsgi.queue_size) %} 23 | 24 | slot {{item}} = {{uwsgi.queue_get(item)}}
25 | 26 | {% endfor %} 27 | 28 |
29 | 30 |
31 |
32 |
33 | 34 |
35 |
36 |
37 | 38 |
39 |
40 |
41 | 42 |
43 |
44 |
45 | 46 |
47 |
48 |
49 | 50 | 51 | -------------------------------------------------------------------------------- /t/perl/test_post.psgi: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | 4 | sub { 5 | my $env = shift; 6 | 7 | my $cl = $env->{CONTENT_LENGTH}; 8 | $env->{'psgi.input'}->seek(0,0); 9 | my $content = ''; 10 | while ($cl) { 11 | $env->{'psgi.input'}->read(my $chunk, $cl < 8192 ? $cl : 8192); 12 | my $read = length $chunk; 13 | $cl -= $read; 14 | $content .= $chunk; 15 | } 16 | 17 | return [200, [], [ "Your content was: <$content>" ]]; 18 | }; 19 | 20 | __END__ 21 | 22 | This is a trival test that prints out a POST request, it's here to 23 | test a regression introduced in 2.0-103-gf041d10 where doing reads 24 | without offsets, e.g.: 25 | 26 | $ http_proxy= curl -d '{ "what": "ever" }' http://localhost:8080/ 27 | Your content was: $VAR1 = '{ "what": "ever" }'; 28 | 29 | Would result in: 30 | 31 | Use of uninitialized value in subroutine entry at 32 | /home/v-perlbrew/perl5/perlbrew/perls/perl-5.19.6/lib/site_perl/5.19.6/Plack/Request.pm 33 | line 280. 34 | 35 | Which is due to this commit having a one-off error in counting stack 36 | items. 37 | 38 | $ git bisect good 39 | f041d1095ddf7541c4b275e16d2ed3355a8e2be9 is the first bad commit 40 | commit f041d1095ddf7541c4b275e16d2ed3355a8e2be9 41 | Author: Unbit 42 | Date: Wed Feb 5 11:21:01 2014 +0100 43 | 44 | perl refactoring 45 | 46 | :040000 040000 98a25406b7edb9bd0b9be8bbcd351a99e7ce2d33 0087e3ca4b6bd65a087fade65d43a56085298ef0 M plugins 47 | 48 | -------------------------------------------------------------------------------- /plugins/alarm_speech/alarm_speech.m: -------------------------------------------------------------------------------- 1 | #include "../../uwsgi.h" 2 | #import "Foundation/NSString.h" 3 | #import "AppKit/NSSpeechSynthesizer.h" 4 | 5 | @interface uWSGIAlarmSpeaker : NSObject { 6 | NSSpeechSynthesizer *synth; 7 | } 8 | 9 | -(void)speak: (NSString *)phrase; 10 | 11 | @end 12 | 13 | 14 | @implementation uWSGIAlarmSpeaker 15 | 16 | - (uWSGIAlarmSpeaker *) init { 17 | self = [super init]; 18 | synth = [[NSSpeechSynthesizer alloc] initWithVoice:nil]; 19 | return self; 20 | } 21 | 22 | - (void)speak:(NSString *)phrase { 23 | [synth startSpeakingString:phrase]; 24 | } 25 | 26 | @end 27 | 28 | // generate a uwsgi signal on alarm 29 | void uwsgi_alarm_speech_init(struct uwsgi_alarm_instance *uai) { 30 | uai->data_ptr = [[uWSGIAlarmSpeaker alloc] init]; 31 | } 32 | 33 | void uwsgi_alarm_speech_func(struct uwsgi_alarm_instance *uai, char *msg, size_t len) { 34 | uWSGIAlarmSpeaker *say = (uWSGIAlarmSpeaker *) uai->data_ptr; 35 | NSString *phrase = [[NSString alloc] initWithBytes:msg 36 | length:len 37 | encoding:NSUTF8StringEncoding]; 38 | 39 | [say speak:phrase]; 40 | [phrase release]; 41 | 42 | } 43 | 44 | static void uwsgi_alarm_speech_load(void) { 45 | uwsgi_register_alarm("speech", uwsgi_alarm_speech_init, uwsgi_alarm_speech_func); 46 | } 47 | 48 | struct uwsgi_plugin alarm_speech_plugin = { 49 | .name = "alarm_speech", 50 | .on_load = uwsgi_alarm_speech_load, 51 | }; 52 | 53 | -------------------------------------------------------------------------------- /tests/queue.py: -------------------------------------------------------------------------------- 1 | # uwsgi --queue 10 --queue-store test.queue --master --module tests.queue --socket :3031 2 | 3 | import uwsgi 4 | import os 5 | from flask import Flask, render_template, request, redirect, flash 6 | 7 | app = Flask(__name__) 8 | app.debug = True 9 | app.secret_key = os.urandom(24) 10 | 11 | 12 | @app.route('/') 13 | def index(): 14 | return render_template('queue.html', uwsgi=uwsgi) 15 | 16 | 17 | @app.route('/push', methods=['POST']) 18 | def push_item(): 19 | if uwsgi.queue_push(request.form['body']): 20 | flash('item enqueued') 21 | return redirect('/') 22 | else: 23 | flash('unable to enqueue item') 24 | return render_template('queue.html', uwsgi=uwsgi) 25 | 26 | 27 | @app.route('/get', methods=['POST']) 28 | def get_item(): 29 | flash("slot %s value = %s" % (request.form['slot'], uwsgi.queue_get(int(request.form['slot'])))) 30 | return redirect('/') 31 | 32 | 33 | @app.route('/pop', methods=['POST']) 34 | def pop_item(): 35 | flash("popped value = %s" % uwsgi.queue_pop()) 36 | return redirect('/') 37 | 38 | 39 | @app.route('/pull', methods=['POST']) 40 | def pull_item(): 41 | flash("pulled value = %s" % uwsgi.queue_pull()) 42 | return redirect('/') 43 | 44 | 45 | @app.route('/set', methods=['POST']) 46 | def set_item(): 47 | if uwsgi.queue_set(int(request.form['pos']), request.form['body']): 48 | flash('item set') 49 | return redirect('/') 50 | else: 51 | flash('unable to set item') 52 | return render_template('queue.html', uwsgi=uwsgi) 53 | -------------------------------------------------------------------------------- /plugins/libtcc/libtcc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | unsigned long long uwsgi_libtcc_counter = 0; 5 | 6 | static int uwsgi_libtcc_hook(char *arg) { 7 | char *func_base = "uwsgi_libtcc_func"; 8 | size_t func_len = strlen(func_base) + sizeof(UMAX64_STR); 9 | char *func_name = uwsgi_malloc(func_len); 10 | int ret = snprintf(func_name, func_len, "%s%llu", func_base, uwsgi_libtcc_counter); 11 | if (ret < (int) strlen(func_base) || ret >= (int) func_len) { 12 | free(func_name); 13 | return -1; 14 | } 15 | uwsgi_libtcc_counter++; 16 | size_t source_len = 64 + func_len + strlen(arg); 17 | char *source = uwsgi_malloc(source_len); 18 | ret = snprintf(source, source_len, "void %s() { %s ;}", func_name, arg); 19 | if (ret < (int) ( strlen(func_base) + strlen(arg)) || ret >= (int) (source_len)) { 20 | free(func_name); 21 | free(source); 22 | return -1; 23 | } 24 | 25 | TCCState *s = tcc_new(); 26 | 27 | if (tcc_compile_string(s, source)) goto error; 28 | if (tcc_relocate(s, TCC_RELOCATE_AUTO)) goto error; 29 | 30 | void (*func)() = tcc_get_symbol(s, func_name); 31 | if (!func) goto error; 32 | free(func_name); 33 | free(source); 34 | 35 | // call the function 36 | func(); 37 | 38 | tcc_delete(s); 39 | return 0; 40 | 41 | error: 42 | free(func_name); 43 | free(source); 44 | tcc_delete(s); 45 | return -1; 46 | } 47 | 48 | static void uwsgi_libtcc_setup() { 49 | uwsgi_register_hook("tcc", uwsgi_libtcc_hook); 50 | } 51 | 52 | struct uwsgi_plugin libtcc_plugin = { 53 | .name = "libtcc", 54 | .on_load = uwsgi_libtcc_setup, 55 | }; 56 | -------------------------------------------------------------------------------- /t/perl/test_streaming.psgi: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | 4 | sub { 5 | my $env = shift; 6 | 7 | return sub { 8 | my $responder = shift; 9 | my $writer = $responder->([ 200, [ 'Content-Type', 'text/plain' ]]); 10 | sleep 3; 11 | $writer->write("hello\n"); 12 | sleep 3; 13 | $writer->write("world\n"); 14 | $writer->close; 15 | return; 16 | }; 17 | } 18 | 19 | __END__ 20 | 21 | Making a request to this will give you: 22 | 23 | $ date; curl -s -N -D - 'http://localhost:8080' 24 | Sat Mar 15 14:08:25 UTC 2014 25 | HTTP/1.1 200 OK 26 | Content-Type: text/plain 27 | 28 | hello 29 | world 30 | 31 | And monitoring it with tcpflow shows how the output (including 32 | headers) is flushed right away: 33 | 34 | $ sudo tcpflow -i lo -c port 8080 | perl -pe 's/^/localtime . " "/ge' 35 | Sat Mar 15 14:09:08 2014 127.000.000.001.55058-127.000.000.001.08080: GET / HTTP/1.1 36 | Sat Mar 15 14:09:08 2014 User-Agent: curl/7.35.0 37 | Sat Mar 15 14:09:08 2014 Host: localhost:8080 38 | Sat Mar 15 14:09:08 2014 Accept: */* 39 | Sat Mar 15 14:09:08 2014 40 | Sat Mar 15 14:09:08 2014 41 | Sat Mar 15 14:09:08 2014 127.000.000.001.08080-127.000.000.001.55058: HTTP/1.1 200 OK 42 | Sat Mar 15 14:09:08 2014 Content-Type: text/plain 43 | Sat Mar 15 14:09:08 2014 44 | Sat Mar 15 14:09:08 2014 45 | Sat Mar 15 14:09:11 2014 127.000.000.001.08080-127.000.000.001.55058: hello 46 | Sat Mar 15 14:09:11 2014 47 | Sat Mar 15 14:09:14 2014 127.000.000.001.08080-127.000.000.001.55058: world 48 | Sat Mar 15 14:09:14 2014 49 | -------------------------------------------------------------------------------- /plugins/pypy/README: -------------------------------------------------------------------------------- 1 | This is a bit convoluted, but you run it (so far) this way: 2 | 3 | You have to compile PyPy with strange options. I'll explain them below. 4 | In the pypy checkout, run: 5 | 6 | ./rpython/bin/rpython -Ojit --shared --gcrootfinder=shadowstack pypy/goal/targetpypystandalone 7 | 8 | Options: 9 | 10 | -Ojit - standard PyPy build with JIT 11 | --shared - as expected, creates a .so 12 | --gcrootfinder - on linux, the default rootfinder is asmgcc which has trouble 13 | with position independent code. This option is not needed 14 | on OS X or windows. 15 | 16 | If for some strange/dangerous/wrong reason your uWSGI binary is linked with cpython you could have name collisions 17 | with pypy cpyext. In such crazy case you can remove cpyext support with: 18 | 19 | ./rpython/bin/rpython -Ojit --shared --gcrootfinder=shadowstack pypy/goal/targetpypystandalone --withoutmod-cpyext 20 | 21 | By default the pypy uWSGI plugin will load the libpypy-c.so library. You should have it in the LD_LIBRARY_PATH, otherwise you can set its path 22 | with --pypy-lib option (pass an absolute path to it) 23 | 24 | You have to specify the pypy home too, you can use the --pypy-home option or the PYPY_HOME var 25 | 26 | PYPY_HOME=/home/user/pypy/lib_pypy uwsgi --pypy-lib /opt/pypy/libpypy-c.so --http-socket :9090 --pypy-wsgi werkzeug.testapp:test_app 27 | 28 | 29 | The funny part about the uWSGI pypy plugin is that it is mainly written in python. The pypy_setup.py script is linked to the plugin, but you can override 30 | it with the --pypy-setup option 31 | -------------------------------------------------------------------------------- /plugins/transformation_template/tt.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef UWSGI_ROUTING 4 | 5 | // apply templating 6 | static int transform_template(struct wsgi_request *wsgi_req, struct uwsgi_transformation *ut) { 7 | 8 | struct uwsgi_route *ur = (struct uwsgi_route *) ut->data; 9 | 10 | char **subject = (char **) (((char *)(wsgi_req))+ur->subject); 11 | uint16_t *subject_len = (uint16_t *) (((char *)(wsgi_req))+ur->subject_len); 12 | 13 | struct uwsgi_buffer *ub = uwsgi_routing_translate(wsgi_req, ur, *subject, *subject_len, ut->chunk->buf, ut->chunk->pos); 14 | if (!ub) return -1; 15 | uwsgi_buffer_map(ut->chunk, ub->buf, ub->pos); 16 | ub->buf = NULL; 17 | uwsgi_buffer_destroy(ub); 18 | return 0; 19 | } 20 | static int uwsgi_router_template_func(struct wsgi_request *wsgi_req, struct uwsgi_route *route) { 21 | uwsgi_add_transformation(wsgi_req, transform_template, route); 22 | return UWSGI_ROUTE_NEXT; 23 | } 24 | static int uwsgi_router_template(struct uwsgi_route *ur, char *arg) { 25 | ur->func = uwsgi_router_template_func; 26 | return 0; 27 | } 28 | 29 | static void transformation_template_register(void) { 30 | uwsgi_register_router("template", uwsgi_router_template); 31 | } 32 | 33 | struct uwsgi_plugin transformation_template_plugin = { 34 | .name = "transformation_template", 35 | .on_load = transformation_template_register, 36 | }; 37 | 38 | #else 39 | struct uwsgi_plugin transformation_template_plugin = { 40 | .name = "transformation_template", 41 | }; 42 | #endif 43 | -------------------------------------------------------------------------------- /t/pypy/t_continulet2.py: -------------------------------------------------------------------------------- 1 | """ 2 | safer test for continulet with partial writes check 3 | 4 | to enable continulets you only need to call uwsgi_pypy_setup_continulets() soon after startup: 5 | 6 | uwsgi --pypy-wsgi-file t/pypy/t_continulet2.py --http-socket :9090 --pypy-home /opt/pypy --pypy-eval "uwsgi_pypy_setup_continulets()" --async 8 7 | 8 | """ 9 | import uwsgi 10 | 11 | 12 | def application(e, sr): 13 | sr('200 OK', [('Content-Type', 'text/plain')]) 14 | 15 | # suspend 10 times and yield a value 16 | for i in range(1, 10): 17 | print i 18 | uwsgi.suspend() 19 | yield str(i) 20 | 21 | # connect to a memcached server 22 | fd = uwsgi.async_connect('127.0.0.1:11211') 23 | try: 24 | command = "get /foobar\r\n" 25 | remains = len(command) 26 | while remains > 0: 27 | # start waiting for socket availability (4 seconds max) 28 | uwsgi.wait_fd_write(fd, 4) 29 | # suspend execution 'til event 30 | uwsgi.suspend() 31 | pos = len(command) - remains 32 | written = uwsgi.send(fd, command[pos:]) 33 | remains -= written 34 | 35 | # now wait for memcached response 36 | uwsgi.wait_fd_read(fd, 4) 37 | uwsgi.suspend() 38 | # read a chunk of data 39 | data = uwsgi.recv(fd, 4096) 40 | # .. and yield it 41 | yield data 42 | finally: 43 | # always ensure sockets are closed 44 | uwsgi.close(fd) 45 | 46 | print "sleeping for 3 seconds..." 47 | uwsgi.async_sleep(3) 48 | uwsgi.suspend() 49 | yield "done" 50 | -------------------------------------------------------------------------------- /plugins/cplusplus/base.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern struct uwsgi_server uwsgi; 4 | 5 | class FakeClass { 6 | 7 | public: 8 | char *foobar; 9 | uint16_t foobar_len; 10 | void hello_world(struct wsgi_request *); 11 | 12 | }; 13 | 14 | void FakeClass::hello_world(struct wsgi_request *wsgi_req) { 15 | 16 | uwsgi_response_prepare_headers(wsgi_req, (char *)"200 OK", 6); 17 | uwsgi_response_add_content_type(wsgi_req, (char *)"text/html", 9); 18 | uwsgi_response_write_body_do(wsgi_req, foobar, foobar_len); 19 | } 20 | 21 | extern "C" int uwsgi_cplusplus_init(){ 22 | uwsgi_log("Initializing example c++ plugin\n"); 23 | return 0; 24 | } 25 | 26 | extern "C" int uwsgi_cplusplus_request(struct wsgi_request *wsgi_req) { 27 | 28 | FakeClass *fc; 29 | 30 | // empty request ? 31 | if (!wsgi_req->len) { 32 | uwsgi_log( "Invalid request. skip.\n"); 33 | goto clear; 34 | } 35 | 36 | // get uwsgi variables 37 | if (uwsgi_parse_vars(wsgi_req)) { 38 | uwsgi_log("Invalid request. skip.\n"); 39 | goto clear; 40 | } 41 | 42 | fc = new FakeClass(); 43 | // get PATH_INFO 44 | fc->foobar = uwsgi_get_var(wsgi_req, (char *) "PATH_INFO", 9, &fc->foobar_len); 45 | 46 | if (fc->foobar) { 47 | // send output 48 | fc->hello_world(wsgi_req); 49 | } 50 | 51 | delete fc; 52 | 53 | clear: 54 | return UWSGI_OK; 55 | } 56 | 57 | 58 | extern "C" void uwsgi_cplusplus_after_request(struct wsgi_request *wsgi_req) { 59 | // call log_request(wsgi_req) if you want a standard logline 60 | uwsgi_log("logging c++ request\n"); 61 | } 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /t/python/manage_script_name/test_manage_script_name.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # coding = utf-8 3 | # author = Adriano Di Luzio 4 | 5 | # I require requests! 6 | 7 | """ 8 | First run: 9 | $ ./uwsgi t/python/manage_script_name/manage_script_name_test.ini 10 | 11 | Then run me! 12 | """ 13 | 14 | import unittest 15 | import requests 16 | 17 | HOST = "http://127.0.0.1:8080" 18 | 19 | 20 | class ManageScriptNameTest(unittest.TestCase): 21 | 22 | def test_classic_mountpoints(self): 23 | mps = { 24 | "/foo", 25 | "/foobis/", 26 | "/footris/" 27 | } 28 | 29 | for mp in mps: 30 | # Requests to /foo should kick-in the managed script name. 31 | r = requests.get(HOST + mp) 32 | self.assertEqual(r.text, mp) 33 | 34 | ends = mp.endswith("/") 35 | 36 | # And equally requests to /foo/ 37 | r = requests.get( 38 | HOST + mp + "/") if not ends else requests.get(HOST + mp[:-1]) 39 | self.assertEqual(r.text, mp) 40 | 41 | # Or correct requests (/foo/resource) 42 | r = requests.get( 43 | HOST + mp + "/" + "resource") if not ends else requests.get(HOST + mp + "resource") 44 | self.assertEqual(r.text, mp) 45 | 46 | def test_intriguing_mountpoints(self): 47 | mps = { 48 | "/fooanything", 49 | "/foobisis/", 50 | "/foofighters", 51 | } 52 | 53 | for mp in mps: 54 | r = requests.get(HOST + mp) 55 | self.assertEqual(r.text, "") 56 | 57 | 58 | if __name__ == '__main__': 59 | unittest.main(verbosity=2) 60 | -------------------------------------------------------------------------------- /t/perl/apps/body-types.psgi: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | 4 | use FileHandle; 5 | use IO::File; 6 | use IO::String; 7 | 8 | my $code = do { local ( @ARGV, $/ ) = __FILE__; <> }; 9 | 10 | sub ObjectPath::path { __FILE__ } 11 | 12 | sub { 13 | my $path = shift->{PATH_INFO}; 14 | 15 | my $body = $path eq '/Array' ? [ split //, $code ] 16 | : $path eq '/Code' ? sub {} 17 | : $path eq '/DATA' ? \*DATA 18 | : $path eq '/DIRHANDLE' ? do { opendir my $fh, '.'; $fh } 19 | : $path eq '/FILEHANDLE' ? do { open my $fh, __FILE__; $fh } 20 | : $path eq '/FileHandle' ? FileHandle->new(__FILE__) 21 | : $path eq '/Float' ? 3.14 22 | : $path eq '/FloatRef' ? \3.14 23 | : $path eq '/Format' ? *STDOUT{FORMAT} 24 | : $path eq '/FormatRef' ? \*STDOUT{FORMAT} 25 | : $path eq '/IO::File' ? IO::File->new(__FILE__) 26 | : $path eq '/Hash' ? { foo => 'bar' } 27 | : $path eq '/Int' ? 3 28 | : $path eq '/IntRef' ? \3 29 | : $path eq '/IO::String' ? IO::String->new($code) 30 | : $path eq '/Object' ? bless({}) 31 | : $path eq '/ObjectPath' ? bless( {}, 'ObjectPath' ) 32 | : $path eq '/Regexp' ? qr/foo/ 33 | : $path eq '/String' ? 'foo' 34 | : $path eq '/StringRef' ? \'bar' 35 | : $path eq '/Undef' ? undef 36 | : $path eq '/UndefRef' ? \undef 37 | : return [ 404, [], [] ]; 38 | 39 | [ 200, [ 'X-ref' => ref $body ], $body ]; 40 | }; 41 | 42 | __DATA__ 43 | data data data 44 | -------------------------------------------------------------------------------- /plugins/jvm/uwsgi.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class uwsgi { 5 | 6 | static HashMap opt; 7 | 8 | public static class RequestBody extends InputStream { 9 | public native int read(); 10 | public native int read(byte[] b); 11 | public native int readLine(byte[] b); 12 | public native int available(); 13 | public native void seek(int pos); 14 | } 15 | 16 | public interface SignalHandler { 17 | void function(int signum); 18 | } 19 | 20 | public interface RpcFunction { 21 | String function(String... args); 22 | } 23 | 24 | public static native int worker_id(); 25 | 26 | public static native void register_signal(int signum, String target, SignalHandler sh); 27 | 28 | public static native void register_rpc(String name, RpcFunction rf); 29 | 30 | public static native void lock(); 31 | public static native void unlock(); 32 | public static native void lock(int locknum); 33 | public static native void unlock(int locknum); 34 | 35 | public static native byte[] cache_get(String key); 36 | public static native byte[] cache_get(String key, String cache); 37 | public static native void cache_set(String key, byte[] value); 38 | public static native void cache_update(String key, byte[] value); 39 | public static native void cache_set(String key, byte[] value, int expires); 40 | public static native void cache_update(String key, byte[] value, int expires); 41 | public static native void cache_set(String key, byte[] value, int expires, String cache); 42 | public static native void cache_update(String key, byte[] value, int expires, String cache); 43 | 44 | public static native void alarm(String alarm, String msg); 45 | 46 | public static native String rpc(String... args); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /plugins/transformation_chunked/chunked.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if defined(UWSGI_ROUTING) 4 | 5 | /* 6 | 7 | transfer-encoding is added to the headers 8 | 9 | */ 10 | 11 | static int transform_chunked(struct wsgi_request *wsgi_req, struct uwsgi_transformation *ut) { 12 | struct uwsgi_buffer *ub = ut->chunk; 13 | 14 | if (ut->is_final) { 15 | if (uwsgi_buffer_append(ub, "0\r\n\r\n", 5)) return -1; 16 | return 0; 17 | } 18 | 19 | if (ut->round == 1) { 20 | // do not check for errors !!! 21 | uwsgi_response_add_header(wsgi_req, "Transfer-Encoding", 17, "chunked", 7); 22 | } 23 | 24 | if (ub->pos > 0) { 25 | if (uwsgi_buffer_insert_chunked(ub, 0, ub->pos)) return -1; 26 | if (uwsgi_buffer_append(ub, "\r\n", 2)) return -1; 27 | } 28 | 29 | return 0; 30 | } 31 | 32 | static int uwsgi_routing_func_chunked(struct wsgi_request *wsgi_req, struct uwsgi_route *ur) { 33 | struct uwsgi_transformation *ut = uwsgi_add_transformation(wsgi_req, transform_chunked, NULL); 34 | ut->can_stream = 1; 35 | // add a "final" transformation to add the trailing chunk 36 | ut = uwsgi_add_transformation(wsgi_req, transform_chunked, NULL); 37 | ut->is_final = 1; 38 | return UWSGI_ROUTE_NEXT; 39 | } 40 | 41 | static int uwsgi_router_chunked(struct uwsgi_route *ur, char *args) { 42 | ur->func = uwsgi_routing_func_chunked; 43 | return 0; 44 | } 45 | 46 | static void router_chunked_register(void) { 47 | uwsgi_register_router("chunked", uwsgi_router_chunked); 48 | } 49 | 50 | struct uwsgi_plugin transformation_chunked_plugin = { 51 | .name = "transformation_chunked", 52 | .on_load = router_chunked_register, 53 | }; 54 | #else 55 | struct uwsgi_plugin transformation_chunked_plugin = { 56 | .name = "transformation_chunked", 57 | }; 58 | #endif 59 | -------------------------------------------------------------------------------- /t/go/cachetest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "uwsgi" 4 | import "net/http" 5 | import "fmt" 6 | 7 | 8 | func getHandler(w http.ResponseWriter, r *http.Request) { 9 | p := uwsgi.CacheGet("foobar", "") 10 | if p == nil { 11 | fmt.Fprintf(w, "

item not found

") 12 | return 13 | } 14 | fmt.Fprintf(w, "

" + string(p) + "

") 15 | } 16 | 17 | func setHandler(w http.ResponseWriter, r *http.Request) { 18 | if uwsgi.CacheSet("foobar", []byte("Hello World !"), 0, "") == false { 19 | fmt.Fprintf(w, "

unable to set cache item

") 20 | return 21 | } 22 | fmt.Fprintf(w, "

item set

") 23 | } 24 | 25 | func updateHandler(w http.ResponseWriter, r *http.Request) { 26 | if uwsgi.CacheUpdate("foobar", []byte("Hello World ! [updated]"), 0, "") == false { 27 | fmt.Fprintf(w, "

unable to update cache item

") 28 | return 29 | } 30 | fmt.Fprintf(w, "

item updated

") 31 | } 32 | 33 | func deleteHandler(w http.ResponseWriter, r *http.Request) { 34 | if uwsgi.CacheDel("foobar", "") == false { 35 | fmt.Fprintf(w, "

unable to delete cache item

") 36 | return 37 | } 38 | fmt.Fprintf(w, "

item deleted

") 39 | } 40 | 41 | func checkHandler(w http.ResponseWriter, r *http.Request) { 42 | if !uwsgi.CacheExists("foobar", "") { 43 | fmt.Fprintf(w, "

item does not exist

") 44 | return 45 | } 46 | fmt.Fprintf(w, "

item exists

") 47 | } 48 | 49 | 50 | func main() { 51 | http.HandleFunc("/get/", getHandler) 52 | http.HandleFunc("/update/", updateHandler) 53 | http.HandleFunc("/set/", setHandler) 54 | http.HandleFunc("/delete/", deleteHandler) 55 | http.HandleFunc("/check/", checkHandler) 56 | uwsgi.Run() 57 | } 58 | -------------------------------------------------------------------------------- /contrib/cgi_python.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void uwsgi_cgi_load_python() { 4 | 5 | Py_Initialize(); 6 | } 7 | 8 | void uwsgi_cgi_run_python(char *filename) { 9 | 10 | char **e, *p; 11 | PyObject *k, *env_value; 12 | 13 | FILE *fp = fopen(filename, "r"); 14 | 15 | PySys_SetArgv(1, &filename); 16 | 17 | PyObject *os_module = PyImport_ImportModule("os"); 18 | if (os_module) { 19 | PyObject *os_module_dict = PyModule_GetDict(os_module); 20 | PyObject *py_environ = PyDict_GetItemString(os_module_dict, "environ"); 21 | if (py_environ) { 22 | for (e = environ; *e != NULL; e++) { 23 | p = strchr(*e, '='); 24 | if (p == NULL) continue; 25 | 26 | k = PyString_FromStringAndSize(*e, (int)(p-*e)); 27 | if (k == NULL) { 28 | PyErr_Print(); 29 | continue; 30 | } 31 | 32 | env_value = PyString_FromString(p+1); 33 | if (env_value == NULL) { 34 | PyErr_Print(); 35 | Py_DECREF(k); 36 | continue; 37 | } 38 | 39 | if (PyObject_SetItem(py_environ, k, env_value)) { 40 | PyErr_Print(); 41 | } 42 | 43 | Py_DECREF(k); 44 | Py_DECREF(env_value); 45 | 46 | } 47 | 48 | } 49 | } 50 | 51 | 52 | PyRun_AnyFileEx(fp, filename, 1); 53 | } 54 | -------------------------------------------------------------------------------- /t/core/url_sanitize.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | #uwsgi --http-socket :9090 --route-run "send:\${PATH_INFO}" 4 | 5 | use IO::Socket::INET; 6 | 7 | my @tests; 8 | 9 | push @tests, ['/foo','/foo']; 10 | push @tests, ['./foo','/foo']; 11 | push @tests, ['./foo/bar?a=1','/foo/bar']; 12 | push @tests, ['//foo/bar','//foo/bar']; 13 | push @tests, ['foo/bar','foo/bar']; 14 | push @tests, ['foo/bar/../','foo/']; 15 | push @tests, ['foo/bar/..','foo/']; 16 | push @tests, ['/foo/bar/..','/foo/']; 17 | push @tests, ['../../../foo/bar/..','/foo/']; 18 | push @tests, ['test1/test2/../test3/','test1/test3/']; 19 | push @tests, ['t#est1/test2/../test3/','t']; 20 | push @tests, ['/one/two/three/four/../five','/one/two/three/five']; 21 | push @tests, ['/one/two/three/four/../../five','/one/two/five']; 22 | push @tests, ['/one/two/three/four/../../five/','/one/two/five/']; 23 | push @tests, ['/one/two/three/four/../../five/..','/one/two/']; 24 | push @tests, ['.one/two/three/four/../../five/..','.one/two/']; 25 | push @tests, ['..one/two/three/four/../../five/..','..one/two/']; 26 | push @tests, ['/../','/']; 27 | push @tests, ['../','/']; 28 | push @tests, ['/.','/']; 29 | push @tests, ['..one/two/three/four/../../../../../five/..','/']; 30 | push @tests, ['./foo/.bar.','/foo/.bar.']; 31 | 32 | foreach(@tests) { 33 | print "testing: ".$_->[0]."\n"; 34 | my $req = "GET ".$_->[0]." HTTP/1.0\r\n\r\n"; 35 | 36 | my $s = IO::Socket::INET->new(PeerAddr => $ARGV[0]); 37 | $s->send($req); 38 | 39 | my $response = ''; 40 | while(1) { 41 | $s->recv(my $buf, 4096); 42 | last unless length($buf); 43 | $response .= $buf; 44 | } 45 | $s->close; 46 | 47 | if ($response ne $_->[1]) { 48 | print "TEST FOR ".$_->[0]." FAILED: EXPECTED ".$_->[1]." GOT ".$response."\n"; 49 | exit; 50 | } 51 | } 52 | 53 | print "test result: SUCCESS\n"; 54 | --------------------------------------------------------------------------------