Coder Social home page Coder Social logo

matsumotory / mod_mruby Goto Github PK

View Code? Open in Web Editor NEW
202.0 202.0 30.0 4.81 MB

mod_mruby: A Fast and Memory-Efficient Apache httpd Extension Mechanism Scripting with mruby

Home Page: http://mod.mruby.org/

Ruby 26.42% C 64.03% Objective-C 0.01% JavaScript 0.36% Shell 0.12% Makefile 0.06% C++ 2.32% Batchfile 0.03% Yacc 6.51% M4 0.08% HTML 0.02% Dockerfile 0.04%

mod_mruby's Introduction

mod_mruby's People

Contributors

ainoya avatar bamchoh avatar cubicdaiya avatar gitter-badger avatar hiboma avatar hiro-krool avatar kentaro avatar konchan avatar ksss avatar matsumotory avatar mattn avatar nazy avatar rrreeeyyy avatar tk3 avatar tsuzakiyo avatar udzura avatar whiteanthrax avatar zippy1981 avatar

Stargazers

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

Watchers

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

mod_mruby's Issues

Receive empty body on another module when read request body by mruby script.

Hi,
I am using Request.body to read POST request on my logging script (like below),
request body is being read properly at script, but another module (mod_proxy in my case)
receive empty body.

r = Apache::Request.new

if r.method_number == Apache::M_POST and r.uri == '/login'
  File.open('path/of/login/log/file', 'a') do |f|
    # mask password
    bodyMasked = r.body.gsub(/password=[^&]*/, 'password=xxx')
    # write body
    f.write("#{bodyMasked}\n")
  end
end

In my opinion, this problem is caused by ap_get_client_block() method (used by ap_mrb_get_request_body() for read request body).
(ref., http://www.gossamer-threads.com/lists/apache/dev/381941)

Is this behavior correct? or bug?

Compile error on CentOS 6

I don't know if this is really an issue, but CentOS 6's GCC 4.4.7 cannot compile mod_mruby. Following patch worked:

--- Makefile.in.orig    2014-04-05 20:58:50.520993033 +0900
+++ Makefile.in 2014-04-05 20:58:56.848993333 +0900
@@ -15,7 +15,7 @@
 DEFS=@DEFS@
 INC=-I. -I$(MRUBY_ROOT)/src -I$(MRUBY_ROOT)/include
 LIB=@LIBS@
-WC=-Wc,'-std=c99 -Wall -Werror-implicit-function-declaration -g'
+WC=-Wc,'-std=gnu99 -Wall -Werror-implicit-function-declaration -g'
 MRUBY_REPOS=@MRUBY_REPOS@
 RAKE_PATH=@RAKE_PATH@
 ENABLE_GEMS=@ENABLE_GEMS@

Add input filter directive

Directive
<Directory /path/to/dir>
  SetInputFilter mruby
  mrubyInputFilter /path/to/input_filter.rb
</Directory>
input_filter.rb example
f = Apache::Filter.new

data = f.flatten
f.cleanup

f.insert_tail data
f.insert_tail "\n__mod_mruby_tail__"
f.insert_head "__mod_mruby_head__\n"
f.insert_eos

Support multi path per directive

I want to support multi path per directive like the following example:

<Location />
  mrubyHandlerMiddleMulti /path/to/A.rb /path/to/B.rb /path/to/C.rb
</Location>

First, mod_mruby run A.rb. Then run B.rb, Finally run C.rb at mrubyHandlerMiddle phase.

begin/ensure variable scope incorrect?

if I execute the following code with mruby:

strX = 'some no foo'
begin
	y='start'
	puts y
	foo
rescue => excp
	strX = 'some foo error'
ensure
	puts strX
	puts 'end'
end
return

I get the output:

start
some foo error
end

Without the error line ( comment out 'foo') it's:
start
some no foo
end

In mod_mruby the scope of a variable is not carried into the ensure:

strX = 'some no foo'
begin
	y='start'
	Apache.echo y
	foo
rescue => excp
	strX = 'some foo error'
ensure
	Apache.echo strX
	Apache.echo 'end'
end
return

Output from this is:

start

end

The variable seen by the ensure is set to nil (tested by getting an error if you attempt " strX += 'more text' " or some other manipulation of the nil value string). This could be intentional, but I wanted to be sure that this was working as designed or a problem.

Build fail. './mruby/build/host/mrblib/mrblib.o: could not read symbols: Bad value'

I would like to create a recipe of the opscode chef for mod_mruby.
Current working branch is https://github.com/higanworks-cookbooks/mruby/tree/mod_mruby.

But, build fails on vm.

Steps will reproduce the problem.

  1. bundle
  2. kitchen converge mod-mruby-centos-64

additional information

Server ENV

# cat /etc/redhat-release 
CentOS release 6.4 (Final)
httpd -v
Server version: Apache/2.2.15 (Unix)
Server built:   Aug 13 2013 17:29:28

Error log

       STDOUT: checking for /usr/sbin/apachectl-gcc... no
       checking for gcc... gcc
       checking whether the C compiler works... yes
       checking for C compiler default output file name... a.out
       checking for suffix of executables... 
       checking whether we are cross compiling... no
       checking for suffix of object files... o
       checking whether we are using the GNU C compiler... yes
       checking whether gcc accepts -g... yes
       checking for gcc option to accept ISO C89... none needed
       checking whether make sets $(MAKE)... yes
       checking for main in -lm... yes
       checking for main in -lcrypto... yes
       checking how to run the C preprocessor... gcc -E
       checking for grep that handles long lines and -e... /bin/grep
       checking for egrep... /bin/grep -E
       checking for ANSI C header files... yes
       checking for sys/types.h... yes
       checking for sys/stat.h... yes
       checking for stdlib.h... yes
       checking for string.h... yes
       checking for memory.h... yes
       checking for strings.h... yes
       checking for inttypes.h... yes
       checking for stdint.h... yes
       checking for unistd.h... yes
       checking for string.h... (cached) yes
       checking for unistd.h... (cached) yes
       checking for an ANSI C-conforming const... yes
       checking whether lstat correctly handles trailing slash... yes
       checking whether stat accepts an empty string... no
       checking for memset... yes
       checking for putenv... yes
       checking for strtol... yes
       --with-mruby: git://github.com/mruby/mruby.git will be used.
       checking for rake1.9.1... /opt/chef/embedded/bin/rake
       checking for apxs2... no
       checking for apxs... /usr/sbin/apxs
       checking for apache2ctl... no
       checking for apachectl... /usr/sbin/apachectl
       checking for apache version... Apache/2.2.15
       configure: creating ./config.status
       config.status: creating Makefile
       config.status: creating config.h
       /usr/sbin/apxs -c -DHAVE_CONFIG_H -I. -I./mruby/src -I./mruby/include  -lcrypto -lm  ./mruby/build/host/lib/libmruby.a ./mruby/build/host/mrblib/mrblib.o -lm -Wc,-std=c99,-Wall,-Werror-implicit-function-declaration,-g -Wl,-lcrypto,-lm,  src/mod_mruby.c src/ap_mrb_*.c 

       *** Warning: Linking the shared library src/mod_mruby.la against the
       *** static library ./mruby/build/host/lib/libmruby.a is not portable!

       *** Warning: Linking the shared library src/mod_mruby.la against the non-libtool
       *** objects  ./mruby/build/host/mrblib/mrblib.o is not portable!
       STDERR: which: no apxs2 in (/sbin:/bin:/usr/sbin:/usr/bin:/opt/chef/embedded/bin:/opt/chef/embedded/bin:/usr/local/sbin:/usr/local/bin)
       configure: WARNING: you should use --build, --host, --target
       configure: WARNING: invalid host type: /usr/sbin/apachectl
       /usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wformat-security -fno-strict-aliasing  -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/httpd  -I/usr/include/apr-1   -I/usr/include/apr-1  -I. -I./mruby/src -I./mruby/include -DHAVE_CONFIG_H  -c -o src/mod_mruby.lo src/mod_mruby.c && touch src/mod_mruby.slo
       src/mod_mruby.c: In function 'ap_mrb_set_mrb_state':
       src/mod_mruby.c:99: warning: format '%x' expects type 'unsigned int', but argument 9 has type 'struct mrb_state *'
       src/mod_mruby.c: In function 'ap_mrb_get_mrb_state':
       src/mod_mruby.c:129: warning: format '%x' expects type 'unsigned int', but argument 9 has type 'struct mrb_state *'
       src/mod_mruby.c: In function 'mod_mruby_child_init':
       src/mod_mruby.c:782: warning: unused variable 'mrb'
       src/mod_mruby.c:779: warning: unused variable 'p'
       src/mod_mruby.c:778: warning: unused variable 'conf'
       src/mod_mruby.c: At top level:
       src/mod_mruby.c:827: warning: 'mod_mruby_post_config_first' defined but not used
       src/mod_mruby.c:828: warning: 'mod_mruby_post_config_middle' defined but not used
       src/mod_m
       ruby.c:829: warning: 'mod_mruby_post_config_last' defined but not used
       /usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wformat-security -fno-strict-aliasing  -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/httpd  -I/usr/include/apr-1   -I/usr/include/apr-1  -I. -I./mruby/src -I./mruby/include -DHAVE_CONFIG_H  -c -o src/ap_mrb_authnprovider.lo src/ap_mrb_authnprovider.c && touch src/ap_mrb_authnprovider.slo
       /usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wformat-security -fno-strict-aliasing  -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/httpd  -I/usr/include/apr-1   -I/usr/include/apr-1  -I. -I./mruby/src -I./mruby/include -DHAVE_CONFIG_H  -c -o src/ap_mrb_connection.lo src/ap_mrb_connection.c && touch src/ap_mrb_connection.slo
       /usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wformat-security -fno-strict-aliasing  -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/httpd  -I/usr/include/apr-1   -I/usr/include/apr-1  -I. -I./mruby/src -I./mruby/include -DHAVE_CONFIG_H  -c -o src/ap_mrb_core.lo src/ap_mrb_core.c && touch src/ap_mrb_core.slo
       /usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wformat-security -fno-strict-aliasing  -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/httpd  -I/usr/include/apr-1   -I/usr/include/apr-1  -I. -I./mruby/src -I./mruby/include -DHAVE_CONFIG_H  -c -o src/ap_mrb_env.lo src/ap_mrb_env.c && touch src/ap_mrb_env.slo
       /usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wformat-security -fno-strict-aliasing  -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/httpd  -I/usr/include/apr-1   -I/usr/include/apr-1  -I. -I./mruby/src -I./mruby/include -DHAVE_CONFIG_H  -c -o src/ap_mrb_filter.lo src/ap_mrb_filter.c && touch src/ap_mrb_filter.slo
       src/ap_mrb_filter.c: In function 'ap_mrb_filter_init':
       src/ap_mrb_filter.c:29: warning: unused variable 'r'
       src/ap_mrb_filter.c: In function 'ap_mrb_filter_bucket_read':

       src/ap_mrb_filter.c:142: warning: unused variable 'rv'
       /usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wformat-security -fno-strict-aliasing  -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/httpd  -I/usr/include/apr-1   -I/usr/include/apr-1  -I. -I./mruby/src -I./mruby/include -DHAVE_CONFIG_H  -c -o src/ap_mrb_init.lo src/ap_mrb_init.c && touch src/ap_mrb_init.slo
       /usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wformat-security -fno-strict-aliasing  -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/httpd  -I/usr/include/apr-1   -I/usr/include/apr-1  -I. -I./mruby/src -I./mruby/include -DHAVE_CONFIG_H  -c -o src/ap_mrb_request.lo src/ap_mrb_request.c && touch src/ap_mrb_request.slo
       src/ap_mrb_request.c: In function 'ap_mrb_run_handler':
       src/ap_mrb_request.c:789: warning: implicit declaration of function 'ap_invoke_handler'
       /usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wformat-security -fno-strict-aliasing  -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/httpd  -I/usr/include/apr-1   -I/usr/include/apr-1  -I. -I./mruby/src -I./mruby/include -DHAVE_CONFIG_H  -c -o src/ap_mrb_scoreboard.lo src/ap_mrb_scoreboard.c && touch src/ap_mrb_scoreboard.slo
       src/ap_mrb_scoreboard.c: In function 'ap_mrb_get_sc_clocks':
       src/ap_mrb_scoreboard.c:111: warning: unused variable 'tick'
       src/ap_mrb_scoreboard.c: At top level:
       src/ap_mrb_scoreboard.c:62: warning: 'status_child_init' defined but not used
       src/ap_mrb_scoreboard.c: In function 'ap_mrb_get_scoreboard_cpu_load':
       src/ap_mrb_scoreboard.c:113: warning: 'cur$tu' may be used uninitialized in this function
       src/ap_mrb_scoreboard.c:113: note: 'cur$tu' was declared here
       src/ap_mrb_scoreboard.c:113: warning: 'cur$ts' may be used uninitialized in this function
       src/ap_mrb_scoreboard.c:113: note: 'cur$ts' was declared here
       src/ap_mrb_scoreboard.c:113: warning: 'cur$tcu' may be used uninitialized in this function
       src/ap_mrb_scoreboard.c:113: note: 'cur$tcu' was declared here
       src/ap_mrb_scoreboard.c:113: warning: 'cur$tcs' may be used uninitialized in this function
       src/ap_mrb_scoreboard.c:113: note: 'cur$tcs' was declared here
       /usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wformat-security -fno-strict-aliasing  -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/httpd  -I/usr/include/apr-1   -I/usr/include/apr-1  -I. -I./mruby/src -I./mruby/include -DHAVE_CONFIG_H  -c -o src/ap_mrb_server.lo src/ap_mrb_server.c && touch src/ap_mrb_server.slo
       /usr/lib64/apr-1/build/libtool --silent --mode=link gcc -o src/mod_mruby.la  -lcrypto -lm -rpath /usr/lib64/httpd/modules -module -avoid-version    src/ap_mrb_server.lo src/ap_mrb_scoreboard.lo src/ap_mrb_request.lo src/ap_mrb_init.lo src/ap_mrb_filter.lo src/ap_mrb_env.lo src/ap_mrb_core.lo src/ap_mrb_connection.lo src/ap_mrb_authnprovider.lo src/mod_mruby.lo ./mruby/build/host/lib/libmruby.a ./mruby/build/host/mrblib/mrblib.o -lm -Wc,-std=c99,-Wall,-Werror-implicit-function-declaration,-g -Wl,-lcrypto,-lm,
       /usr/bin/ld: ./mruby/build/host/mrblib/mrblib.o: relocation R_X86_64_32 against `mrblib_irep' can not be used when making a shared object; recompile with -fPIC
       ./mruby/build/host/mrblib/mrblib.o: could not read symbols: Bad value
       collect2: ld returned 1 exit status
       apxs:Error: Command failed with rc=65536
       .

Add input filter directive

Directive
<Directory /path/to/dir>
  SetInputFilter mruby
  mrubyInputFilter /path/to/input_filter.rb
</Directory>
input_filter.rb example
f = Apache::Filter.new

data = f.flatten
f.cleanup

f.insert_tail data
f.insert_tail "\n__mod_mruby_tail__"
f.insert_head "__mod_mruby_head__\n"
f.insert_eos

Allow rb files to #include other rb files

Since we are already interpreting these rb files on the fly for every request, it would be very handy to have a simple way to include one file into another. An example of how this could look is:

#include foo
#include bar

foo = Foo.new
Apache.rputs foo.something(Bar)
Apache.return(Apache::OK)

This would presumably include foo.rb and bar.rb into this file before passing it to the mrb interpreter.

I have a very naive C program that will concatenate files into a tempfile based on #include statements at the very top: https://gist.github.com/myobie/4b0ee69c123f250c827f

I was not able to get the same code working in mod_mruby.c (segmentation fault 11 is my new friend), but I think the sample code helps explain my idea. For simplicity, I decided that the #include lines must appear on the first lines of a file.

Either way, this is the best I can do with C code right now. If I find a way to get my code actually working on a branch in mod_mruby, I will update this issue.

Change server config to dir config

Now mrubyHandlerMiddle or mrubyHandlerCodeMiddle and so on are server directive. The server directive can not work in directive. So we should change the server directive to dir directive.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.