Git Product home page Git Product logo

evma_httpserver's Introduction

eventmachine_httpserver

EM::HttpServer vs Thin

 +careo | is there a 25 word version of how it differs from thin?
  +tmm1 | good question.. its probably faster, but only because it doesn't have a real http parser like thin
+wyhaines | It is faster.  It's more of an nginx style parser than the mongrel, grammar based parser.
 +careo | so perhaps a better fit for putting an http interface on top of a bunch of already-evented code?
+wyhaines | careo: It depends.  There are very valid arguments for using an RFC-compliant parser a lot of the time.
+wyhaines | But, yeah, sometimes being strictly RFC compliant isn't something that you care about.

Installing

Without Bundler

sudo gem install eventmachine_httpserver

With bundler

gem 'eventmachine_httpserver', :require => 'evma_httpserver'

Usage example

require 'eventmachine'
require 'evma_httpserver'

class MyHttpServer < EM::Connection
  include EM::HttpServer

   def post_init
     super
     no_environment_strings
   end

  def process_http_request
    # the http request details are available via the following instance variables:
    #   @http_protocol
    #   @http_request_method
    #   @http_cookie
    #   @http_if_none_match
    #   @http_content_type
    #   @http_path_info
    #   @http_request_uri
    #   @http_query_string
    #   @http_post_content
    #   @http_headers

    response = EM::DelegatedHttpResponse.new(self)
    response.status = 200
    response.content_type 'text/html'
    response.content = '<center><h1>Hi there</h1></center>'
    response.send_response
  end
end

EM.run{
  EM.start_server '0.0.0.0', 8080, MyHttpServer
}

evma_httpserver's People

Contributors

abonec avatar almuthanna-athamina avatar alor avatar cmdrkeene avatar gdb avatar igrigorik avatar jf647 avatar meh avatar raggi avatar skaes avatar tmm1 avatar wyhaines 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

evma_httpserver's Issues

No access to client IP address (REMOTE_ADDR)

I can't see any way to access the IP address of the client; the value that would normally be pushed into the environment as REMOTE_ADDR.

Is this something that can be accessed using some more generic EventMachine accessor, or is it truly missing?

Cheers!
Paul

Doesn't install on jruby and darwin


bundle update
Fetching source index for http://rubygems.org/
Using eventmachine (0.12.10) 
Installing eventmachine_httpserver (0.2.1) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/matee/.rvm/rubies/jruby-1.6.4/bin/jruby extconf.rb 
WARNING: JRuby does not support native extensions or the `mkmf' library very well.
Check http://kenai.com/projects/jruby/pages/Home for alternatives.
checking for main() in -lpthread... yes
checking for main() in -lssl... yes
checking for main() in -lcrypto... yes
checking for openssl/ssl.h... yes
checking for openssl/err.h... yes
creating Makefile

make
g++ -I. -I. -I/Users/matee/.rvm/rubies/jruby-1.6.4/lib/native/include/ruby -I. -DHAVE_OPENSSL_SSL_H -DHAVE_OPENSSL_ERR_H  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE        -DOS_UNIX -DBUILD_FOR_RUBY -DWITH_SSL -fPIC -DTARGET_RT_MAC_CFM=0  -fno-omit-frame-pointer -fno-strict-aliasing  -fexceptions    -arch x86_64  -fno-omit-frame-pointer -fno-strict-aliasing  -fexceptions     -c http.cpp
g++ -I. -I. -I/Users/matee/.rvm/rubies/jruby-1.6.4/lib/native/include/ruby -I. -DHAVE_OPENSSL_SSL_H -DHAVE_OPENSSL_ERR_H  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE        -DOS_UNIX -DBUILD_FOR_RUBY -DWITH_SSL -fPIC -DTARGET_RT_MAC_CFM=0  -fno-omit-frame-pointer -fno-strict-aliasing  -fexceptions    -arch x86_64  -fno-omit-frame-pointer -fno-strict-aliasing  -fexceptions     -c rubyhttp.cpp
g++ -shared -o eventmachine_httpserver.bundle http.o rubyhttp.o -L"." -L"/Users/matee/.rvm/rubies/jruby-1.6.4/lib" -bundle -framework JavaVM -Wl,-syslibroot, -mmacosx-version-min=10.4   -arch x86_64  -lcrypto -lssl -lpthread   
i686-apple-darwin10-g++-4.2.1: -bundle not allowed with -dynamiclib
make: *** [eventmachine_httpserver.bundle] Error 1


Gem files will remain installed in /Users/matee/.rvm/gems/jruby-1.6.4/gems/eventmachine_httpserver-0.2.1 for inspection.
Results logged to /Users/matee/.rvm/gems/jruby-1.6.4/gems/eventmachine_httpserver-0.2.1/ext/gem_make.out
An error occured while installing eventmachine_httpserver (0.2.1), and Bundler cannot continue.
Make sure that `gem install eventmachine_httpserver -v '0.2.1'` succeeds before bundling.

gem_make.out

/Users/matee/.rvm/rubies/jruby-1.6.4/bin/jruby extconf.rb 
WARNING: JRuby does not support native extensions or the `mkmf' library very well.
Check http://kenai.com/projects/jruby/pages/Home for alternatives.
checking for main() in -lpthread... yes
checking for main() in -lssl... yes
checking for main() in -lcrypto... yes
checking for openssl/ssl.h... yes
checking for openssl/err.h... yes
creating Makefile

make
g++ -I. -I. -I/Users/matee/.rvm/rubies/jruby-1.6.4/lib/native/include/ruby -I. -DHAVE_OPENSSL_SSL_H -DHAVE_OPENSSL_ERR_H  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE        -DOS_UNIX -DBUILD_FOR_RUBY -DWITH_SSL -fPIC -DTARGET_RT_MAC_CFM=0  -fno-omit-frame-pointer -fno-strict-aliasing  -fexceptions    -arch x86_64  -fno-omit-frame-pointer -fno-strict-aliasing  -fexceptions     -c http.cpp
g++ -I. -I. -I/Users/matee/.rvm/rubies/jruby-1.6.4/lib/native/include/ruby -I. -DHAVE_OPENSSL_SSL_H -DHAVE_OPENSSL_ERR_H  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE        -DOS_UNIX -DBUILD_FOR_RUBY -DWITH_SSL -fPIC -DTARGET_RT_MAC_CFM=0  -fno-omit-frame-pointer -fno-strict-aliasing  -fexceptions    -arch x86_64  -fno-omit-frame-pointer -fno-strict-aliasing  -fexceptions     -c rubyhttp.cpp
g++ -shared -o eventmachine_httpserver.bundle http.o rubyhttp.o -L"." -L"/Users/matee/.rvm/rubies/jruby-1.6.4/lib" -bundle -framework JavaVM -Wl,-syslibroot, -mmacosx-version-min=10.4   -arch x86_64  -lcrypto -lssl -lpthread   
i686-apple-darwin10-g++-4.2.1: -bundle not allowed with -dynamiclib
make: *** [eventmachine_httpserver.bundle] Error 1

jRuby:

ruby --version
jruby 1.6.4 (ruby-1.8.7-p330) (2011-08-23 17ea768) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]

uname:

uname -a
Darwin prosiak 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun  7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386

send_response intermittent failure

The puffing billy gem is using evma_httpserver to simulate responses to javascript clients.

Intermittently a response is not getting back to the browser.

The puffing billy code (monkey patched to provide logging looks like this:)

Billy::ProxyConnection.send(:define_method, :send_response) do |response|
  Billy.log(:info, "puffing-billing: send_response #{response[:status]}, #{response[:headers]}, '#{response[:content][0..10]}'")
  res = EM::DelegatedHttpResponse.new(self)
  res.status = response[:status]
  res.headers = response[:headers]
  res.content = response[:content]
  res.send_response
  Billy.log(:info, "puffing-billing: send_response SENT!")
end

In the resulting log I see this:

puffing-billing: send_response 200, {"Content-Type"=>"application/javascript;charset=utf-8", "Connection"=>"close", "Status"=>"200", "X-Powered-By"=>"Phusion Passenger (mod_rails/mod_rack) 3.0.11", "Content-Length"=>"1708", "Server"=>"nginx/1.0.14 + Phusion Passenger 3.0.11 (mod_rails/mod_rack)"}, 'jQuery11200'
puffing-billing: send_response SENT!

but the browser log looks like this:

screen shot 2016-03-11 at 3 03 14 pm

This happens about 25 % of the time. When the response is successful everything looks exactly the same except in the browser net log I see 200 ... and 1708 bytes received.

The problem is NOT browser specific. I have tried the same scenario using poltergeist, with the same results.

It would be very difficult to get this into an isolated test case that I could share, but I would be happy to add logging to evma_httpserver, if I could have some clues WHAT to investigate. Also would be happy to set up a co-debug session on cloud9.

Version bump

Recent changes to HTTP 1.1 header support would be great to distribute to our production servers via rubygems/bundler. Is there anything prohibiting a new release?

Does not work on 10.6?

I am trying the example code the httpserver and no_environment_strings throws a method not found error and process_http_request never gets called.

The require and include statements work fine.

Test fails on:
EEEE..................
Finished in 0.013125 seconds.

  1. Error:
    test_headers(TestApp):
    RangeError: integer 4329072128 too big to convert to int' /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.8/lib/eventmachine.rb:242:inreceive_data'
    /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.8/lib/eventmachine.rb:242:in run_machine' /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.8/lib/eventmachine.rb:242:inrun'
    ./test/test_app.rb:151:in `test_headers'

  2. Error:
    test_parameters(TestApp):
    RangeError: integer 4329836032 too big to convert to int' /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.8/lib/eventmachine.rb:242:inreceive_data'
    /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.8/lib/eventmachine.rb:242:in run_machine' /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.8/lib/eventmachine.rb:242:inrun'
    ./test/test_app.rb:103:in `test_parameters'

  3. Error:
    test_post(TestApp):
    RangeError: integer 4329013248 too big to convert to int' /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.8/lib/eventmachine.rb:242:inreceive_data'
    /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.8/lib/eventmachine.rb:242:in run_machine' /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.8/lib/eventmachine.rb:242:inrun'
    ./test/test_app.rb:202:in `test_post'

  4. Error:
    test_simple_get(TestApp):
    RangeError: integer 4329039872 too big to convert to int' /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.8/lib/eventmachine.rb:242:inreceive_data'
    /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.8/lib/eventmachine.rb:242:in run_machine' /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.8/lib/eventmachine.rb:242:inrun'
    ./test/test_app.rb:57:in `test_simple_get'

22 tests, 30 assertions, 0 failures, 4 errors

changing MaxContentLength

is there a way to change the value of MaxContentLength at runtime ?
it is set to 20 MiB in the cpp code, but i need to adjust it dynamically to 25 MiB for a file upload.

thank you

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

  spec.license = 'MIT'
  # or
  spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

Suggestion: Use same license as eventmachine gem

It might just be my opinion, but if it's possible, I think this "child" gem should have the same license as its parent (which, to the best of my understanding, is dual licensed with GPL and the Ruby license).

Since this requires consent from all authors, I'll tag all authors here in the hopes of determining that 1) it's a change worth making and 2) all required people can add their consent.

@tmm1 @raggi @nahi @jf647 @cmdrkeene @skaes @alor @igrigorik @abonec @meh @gdb

doesn't build in doze

with mingw + devkit

gcc -shared -s -o eventmachine_httpserver.so http.o rubyhttp.o -L. -LC:/Ruby/lib -L. -Wl,--enable-auto-image-base,--enable-auto-import,--export-all -lmsvcrt-ruby18 -lgdi32 -lrpcrt4 -lkernel32 -lshell32 -lws2_32

C:/installs/build_env/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/ostream.tcc:63: undefined reference to `std::cerr'

I think it needs an added "-lstdc++'
Though I haven't tested it.
Thanks.
=r

gem2deb error

Getting following error while creating DPKG from source.

/usr/bin/ruby3.0 -S gem build --config-file /dev/null --verbose /tmp/d20240522-3266536-n4he2y/gemspec Failed to load /dev/null because it doesn't contain valid YAML hash WARNING: See https://guides.rubygems.org/specification-reference/ for help ERROR: While executing gem ... (Gem::InvalidSpecificationException) cert_chain must not be nil /usr/lib/ruby/vendor_ruby/gem2deb.rb:54:in run': /usr/bin/ruby3.0 -S gem build --config-file /dev/null --verbose /tmp/d20240522-3266536-n4he2y/gemspec (Gem2Deb::CommandFailed)
from /usr/lib/ruby/vendor_ruby/gem2deb/gem_installer.rb:212:in run_gem' from /usr/lib/ruby/vendor_ruby/gem2deb/gem_installer.rb:112:in block (2 levels) in install_files_and_build_extensions'
from /usr/lib/ruby/vendor_ruby/gem2deb/gem_installer.rb:111:in chdir' from /usr/lib/ruby/vendor_ruby/gem2deb/gem_installer.rb:111:in block in install_files_and_build_extensions'
from /usr/lib/ruby/vendor_ruby/gem2deb/gem_installer.rb:68:in each' from /usr/lib/ruby/vendor_ruby/gem2deb/gem_installer.rb:68:in install_files_and_build_extensions'
from /usr/lib/ruby/vendor_ruby/gem2deb/installer.rb:28:in install' from /usr/lib/ruby/vendor_ruby/gem2deb/dh_ruby.rb:86:in block in install'
from /usr/lib/ruby/vendor_ruby/gem2deb/dh_ruby.rb:84:in each' from /usr/lib/ruby/vendor_ruby/gem2deb/dh_ruby.rb:84:in install'
from /usr/bin/dh_ruby:89:in <main>' dh_auto_install: error: dh_ruby --install /home/pravin/ruby-eventmachine-httpserver-0.2.1/debian/ruby-eventmachine-httpserver returned exit code 1 make: *** [debian/rules:7: binary] Error 25 dpkg-buildpackage: error: debian/rules binary subprocess returned exit status 2 debuild: fatal error at line 1182: dpkg-buildpackage -us -uc -ui failed

GemSpec shows s.cert_chail = nil
`Gem::Specification.new do |s|
s.name = %q{eventmachine_httpserver}
s.version = "0.2.1"

s.specification_version = 1 if s.respond_to? :specification_version=

s.required_rubygems_version = nil if s.respond_to? :required_rubygems_version=
s.authors = ["Francis Cianfrocca"]
s.cert_chain = nil
s.date = %q{2007-03-16}
s.description = %q{}
s.email = %q{[email protected]}
s.extensions = ["ext/extconf.rb"]
s.extra_rdoc_files = git ls-files docs.split
s.files = git ls-files | grep -v .gitignore.split
s.has_rdoc = true
s.homepage = %q{https://github.com/eventmachine/evma_httpserver}
s.rdoc_options = ["--title", "EventMachine_HttpServer", "--main", "docs/README", "--line-numbers"]
s.require_paths = ["lib"]
s.required_ruby_version = Gem::Requirement.new("> 0.0.0")
s.rubygems_version = %q{1.3.1}
s.summary = %q{EventMachine HTTP Server}
end
`

Missing license

Hello,

we are using a gem which is using this gem.
We would like to know if it is safe to use it for commerical use,
so it would be great if you name a license for this gem.

Thank you

windows mingw can't compile ext

creating Makefile
make "DESTDIR="
generating eventmachine_httpserver-i386-mingw32.def
compiling http.cpp
g++.exe: error: unrecognized command line option '-EHs'
g++.exe: error: unrecognized command line option '-GR'

Doesn't work with SSL

Hi,
As it is, I don't think this gem works with SSL.

Here's gist of what I'm trying to get to go.
https://gist.github.com/1024086

If we comment out the start_tls line all works properly, but with it in it never reaches process_http_request.

Any thoughts?

License declaration mismatch

The README declares the license as "Lesser-GPL version 2", but the actual license is for GPLv2.

Also, if LGPL is intended, should specify 2.1 rather than just "2".

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.