femtows 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.txt ADDED
@@ -0,0 +1,5 @@
1
+ "form guidemo"
2
+ form in guidemo
3
+ ruiby_require : do a gem install if gem not
4
+ ruiby_require : do a gem install if gem not
5
+ 1.2.0
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # Femtows : femto sized web server
2
+ ## Presentation
3
+
4
+ The tiny web server ...
5
+ 230 Lines of code.
6
+
7
+ Build to be embedded in any ruby application, test/debug/admin access...
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ gem install femtows
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```ruby
18
+ > ruby -rfemtows -e "cliweb()"
19
+ > ruby -rfemtows -e "cliweb(8080,'/tmp')"
20
+ or
21
+ > femtows.bat
22
+ # femtows.sh
23
+ ```
24
+
25
+ Embedded:
26
+
27
+ ```ruby
28
+ # server all file in current dir and .info request :
29
+
30
+ $ws=WebserverRoot.new(8080,"/tmp","femto ws",10,300, {})
31
+
32
+ $ws.serve("/info") {|p|
33
+ [200,".html", "Femto demo<hr><a href='/'>site</a><hr>#{$ws.to_table(p)}" ]
34
+ }
35
+ ```
36
+
37
+ ## API
38
+
39
+ ```ruby
40
+ WebserverRoot.new(
41
+ port_http, # server http port (>1024 on posix, if not root)
42
+ root-dir, # only one file root. indexed by defalut
43
+ ws_name, # name in trace & index title
44
+ 10,300, # watch too long connection: every 10 secondes,
45
+ # kill session which have started from more than 300 seconds
46
+ {} # options. only one, for logg events , see demo.rb
47
+ )
48
+ ```
49
+
50
+ Servelet receive params hash which content :
51
+
52
+ - all http header, with key upercase, prefixed with 'HEAD-'
53
+ - http parameters (?a=b&...)
54
+
55
+ Exemple : http://localhost:9980/info?aa=bb&cc=dd, give with p.to_a.inspect:
56
+
57
+ ```
58
+ ["aa", "bb"]
59
+ ["cc", "dd"]
60
+ ["HEAD-HOST", "localhost:9980"]
61
+ ["HEAD-USER-AGENT", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2"]
62
+ ["HEAD-ACCEPT", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"]
63
+ ["HEAD-ACCEPT-LANGUAGE", "fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3"]
64
+ ["HEAD-ACCEPT-ENCODING", "gzip, deflate"]
65
+ ["HEAD-CONNECTION", "keep-alive"]
66
+ ```
67
+ ## License
68
+
69
+ LGPL
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.2.0
data/bin/femtows.bat ADDED
@@ -0,0 +1,2 @@
1
+ @start "ws" ruby -rfemtows -e "cliweb()"
2
+ start http://localhost:59999/
data/bin/femtows.sh ADDED
@@ -0,0 +1 @@
1
+ ruby -rfemtows -e "cliweb()" &
data/demo.rb ADDED
@@ -0,0 +1,33 @@
1
+ require_relative "lib/femtows.rb"
2
+
3
+ ##################### mini log
4
+
5
+ $loggs= Queue.new
6
+ $file_log="femtows.log"
7
+ def logger(name="",adr="",*res)
8
+ mess= "%s | %-10s|%15s | %s" % [Time.now.strftime("%Y-%m-%d %H:%M:%S"),name,adr,res.join(" ")]
9
+ ($loggs.size<1000) ? $loggs.push(mess) : puts(mess)
10
+ true
11
+ end
12
+ Thread.new do
13
+ loop do
14
+ sleep 10
15
+ if $loggs.size>0
16
+ File.open($file_log,"a") { |f| f.puts( $loggs.pop ) while $loggs.size>0 }
17
+ end
18
+ end
19
+ end
20
+
21
+ ########################### main
22
+
23
+ Thread.abort_on_exception = false
24
+ BasicSocket.do_not_reverse_lookup = true
25
+
26
+ $ws=WebserverRoot.new(ARGV[0].to_i,".","femto ws",10,300, {
27
+ "logg" => proc {|*par| logger(*par) }
28
+ })
29
+ $ws.serve("/info") {|p|
30
+ [200,".html", "Femto demo<hr><a href='/'>site</a><hr>#{$ws.to_table(p)}" ]
31
+ }
32
+
33
+ sleep
data/femtows.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push('lib')
3
+ require "ruiby/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "femtows"
7
+ s.version = File.read("VERSION").strip
8
+ s.date = Time.now.to_s.split(/\s+/)[0]
9
+ s.email = "regis.aubarede@gmail.com"
10
+ s.homepage = "http://github.com/raubarede/femtows"
11
+ s.authors = ["Regis d'Aubarede"]
12
+ s.summary = "a tiny webserver"
13
+ s.description = <<'EEND'
14
+ a tiny web server, for local file transfert,
15
+ embededded, http experimentations
16
+ EEND
17
+
18
+
19
+ s.files = Dir['**/*']
20
+ s.test_files = Dir['samples/**']
21
+ s.require_paths = ["lib"]
22
+ s.executables = `ls bin/*`.split("\n").map{ |f| File.basename(f) }
23
+
24
+ ## Make sure you can build the gem on older versions of RubyGems too:
25
+ s.rubygems_version = "1.8.15"
26
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
27
+ s.specification_version = 3 if s.respond_to? :specification_version
28
+
29
+ end
30
+