rick_trolling 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9093ad63da176314559877a5922e063cd1d3efa5
4
+ data.tar.gz: 9278bb6030c8fad8227ae726c2538ec37b075cf0
5
+ SHA512:
6
+ metadata.gz: 4b018e30edf6f7a33c95b2270f1e02e93f39d5278fc4a6db77463b54a8231a05cf61ff56b5b5dd764ee96b76a86a74398a39be94d89925fdf0a4b9d047557efb
7
+ data.tar.gz: 00ca15cc2f58a5298b1fa562ac8425836d77d52d47cea68b8e5333efe39cc27124fb34871fac0ca14031b9199a0f6d76082a67baa284f6d4c18f78e75677c840
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,19 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rick_trolling (0.0.1)
5
+ rack
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ rack (1.5.2)
11
+ rake (10.1.1)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.3)
18
+ rake
19
+ rick_trolling!
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Rick Trolling
2
+
3
+ ## Author
4
+
5
+ By [Andrew Thul](https://github.com/adthul)
6
+
7
+ ## Description
8
+
9
+ **rick_trolling** is a basic ruby http server that will serve from a specified or public folder. Otherwise a provided index.html file will be served instead.
10
+
11
+ ## Installation
12
+
13
+ Add to your Gemfile:
14
+
15
+ ```ruby
16
+ gem 'rick_trolling'
17
+ ```
18
+
19
+ Bundle:
20
+
21
+ ```console
22
+ bundle install
23
+ ```
24
+
25
+ type 'rick_trolling' in console to open.
26
+
27
+ Or install it yourself as:
28
+
29
+ ```console
30
+ gem install rick_trolling
31
+ ```
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
40
+
41
+ ## License
42
+
43
+ [MIT License](http://adthul.mit-license.org)
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ task default: 'test'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.pattern = "test/**/*_test.rb"
8
+ end
data/bin/rick_trolling ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rick_trolling'
4
+ puts index.html
data/lib/index.html ADDED
@@ -0,0 +1,13 @@
1
+ <html>
2
+ <head>
3
+ <title>Landing Page</title>
4
+ </head>
5
+ <body>
6
+ <h1>Never gonna give you up</h1>
7
+ <h2>Never gonna let you down</h2>
8
+ <h3>Never gonna run around and desert you</h2>
9
+ <h4>Never gonna make you cry</h4>
10
+ <h5>Never gonna say goodbye</h5>
11
+ <h6>Never gonna tell a lie and hurt you</h6>
12
+ </body>
13
+ </html>
@@ -0,0 +1,3 @@
1
+ module Rick_trolling
2
+ VERSION = "0.0.1"
3
+ end
data/lib/server.rb ADDED
@@ -0,0 +1,67 @@
1
+ require 'rick_trolling/version'
2
+ require 'socket'
3
+ require 'uri'
4
+
5
+ WEB_ROOT = './public'
6
+
7
+ WEB_ROOT = "./public" unless defined?(WEB_ROOT)
8
+ SERVER_PORT = 1234 unless defined?(SERVER_PORT)
9
+
10
+ CONTENT_TYPE_MAPPING = {
11
+ 'html' => 'text/html',
12
+ 'txt' => 'text/plain',
13
+ 'png' => 'image/png',
14
+ 'jpg' => 'image/jpeg'
15
+ }
16
+
17
+ DEFAULT_CONTENT_TYPE = 'application/octet-stream'
18
+
19
+ def content_type(path)
20
+ ext = File.extname(path).split(".").last
21
+ CONTENT_TYPE_MAPPING.fetch(ext, DEFAULT_CONTENT_TYPE)
22
+ end
23
+
24
+ def requested_file(request_line)
25
+ request_uri = request_line.split(" ")[1]
26
+ path = URI.unescape(URI(request_uri).path)
27
+
28
+ clean = []
29
+ parts = path.split("/")
30
+
31
+ parts.each do |part|
32
+ next if part.empty? || part == '.'
33
+ part == '..' ? clean.pop : clean << part
34
+ end
35
+
36
+ File.join(WEB_ROOT, *clean)
37
+ end
38
+
39
+ server = TCPServer.new('localhost', SERVER_PORT)
40
+
41
+ loop do
42
+ socket = server.accept
43
+ request_line = socket.gets
44
+
45
+ STDERR.puts request_line
46
+ path = requested_file(request_line)
47
+ + path = File.join(path, 'index.html') if File.directory?(path)
48
+
49
+ if File.exist?(path) && !File.directory?(path)
50
+ File.open(path, "rb") do |file|
51
+ socket.print "HTTP/1.1 200 OK\r\n" + "Content-Type: #{content_type(file)}\r\n" +
52
+ "Content-Length: #{file.size}\r\n" + "Connection: close\r\n"
53
+
54
+ socket.print "\r\n"
55
+ IO.copy_stream(file, socket)
56
+ end
57
+ else
58
+ message = "File not found\n"
59
+
60
+ socket.print "HTTP/1.1 404 Not Found\r\n" + "Content-Type: text/plain\r\n" +
61
+ "Content-Length: #{message.size}\r\n" + "Connection: close\r\n"
62
+
63
+ socket.print "\r\n"
64
+ socket.print message
65
+ end
66
+ socket.close
67
+ end
Binary file
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rick_trolling/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rick_trolling"
8
+ spec.version = Rick_trolling::VERSION
9
+ spec.executables << "rick_trolling"
10
+ spec.authors = ["adthul"]
11
+ spec.email = ["thul.andy@gmail.com"]
12
+ spec.description = %q{A simple ruby web server}
13
+ spec.summary = %q{server with a rick roll landing page!}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_runtime_dependency "rack"
25
+ end
@@ -0,0 +1,9 @@
1
+ require 'minitest/autorun'
2
+ require 'rick_trolling'
3
+
4
+ describe 'Lands on page' do
5
+ it 'has text "Never"' do
6
+ visit 'localhost:1234/'
7
+ page.must_have_content 'Never'
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rick_trolling
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - adthul
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A simple ruby web server
56
+ email:
57
+ - thul.andy@gmail.com
58
+ executables:
59
+ - rick_trolling
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - README.md
66
+ - Rakefile
67
+ - bin/rick_trolling
68
+ - lib/index.html
69
+ - lib/rick_trolling/version.rb
70
+ - lib/server.rb
71
+ - rick_trolling-0.0.1.gem
72
+ - rick_trolling.gemspec
73
+ - test/rick_trolling_test.rb
74
+ homepage: ''
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.2.1
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: server with a rick roll landing page!
98
+ test_files:
99
+ - test/rick_trolling_test.rb