upside_down_server 0.0.2

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/upside_down_server +77 -0
  3. metadata +48 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: efa1f208a8264a0d9e2129104cc233c53a256d34
4
+ data.tar.gz: 8b85cd126bd5c811cb758941b7e9ed267f2a0e2e
5
+ SHA512:
6
+ metadata.gz: db75ff3ef301b302ee813cda19aa5beae61aa3ac2a1ddfff4bdb1c4131b21dd6d445b00d284d4fcbd01b6475ae91d0009bcf5e85e4e10e8ceba6e4029ec40596
7
+ data.tar.gz: d934f99df9007ef02153868ba3e34ded3b63c00e9dfa7962724bc0564d7ac458fada730fefe4b912bc65af37432cd0c0181fce2e7bbe50a6b90965866d481317
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'socket'
4
+ require 'uri'
5
+
6
+ WEB_ROOT = './public'
7
+
8
+ CONTENT_TYPE_MAPPING = {
9
+ 'html' => 'text/html',
10
+ 'txt' => 'text/plain',
11
+ 'png' => 'image/png',
12
+ 'jpg' => 'image/jpeg'
13
+ }
14
+
15
+ DEFAULT_CONTENT_TYPE = 'application/octet-stream'
16
+
17
+ def content_type(path)
18
+ ext = File.extname(path).split(".").last
19
+ CONTENT_TYPE_MAPPING.fetch(ext, DEFAULT_CONTENT_TYPE)
20
+ end
21
+
22
+ def requested_file(request_line)
23
+ request_uri = request_line.split(" ")[1]
24
+ path = URI.unescape(URI(request_uri).path)
25
+ clean = []
26
+
27
+ parts = path.split("/")
28
+
29
+ parts.each do |part|
30
+ next if part.empty? || part == '.'
31
+ part == '..' ? clean.pop : clean << part
32
+ end
33
+
34
+ File.join(WEB_ROOT, *clean)
35
+ end
36
+
37
+ server = TCPServer.new('localhost', 1234)
38
+
39
+ loop do
40
+ socket = server.accept
41
+ request_line = socket.gets
42
+
43
+ STDERR.puts request_line
44
+
45
+ path = requested_file(request_line)
46
+
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" +
52
+ "Content-Type: #{content_type(file)}\r\n" +
53
+ "Connection: close\r\n"
54
+
55
+ socket.print "\r\n"
56
+ file.each_line.each do |line|
57
+ if line.include? "<body>"
58
+ line["<body>"] = "<body style=\"-moz-transform: rotate(-180deg);" + "-webkit-transform: rotate(-180deg);" + "transform: rotate(-180deg);\">"
59
+ end
60
+ socket.puts line
61
+ end
62
+ end
63
+ else
64
+ message = "File not found\n"
65
+
66
+ socket.print "HTTP/1.1 404 Not Found\r\n" +
67
+ "Content-Type: text/plain\r\n" +
68
+ "Content-Length: #{message.size}\r\n" +
69
+ "Connection: close\r\n"
70
+
71
+ socket.print "\r\n"
72
+
73
+ socket.print message
74
+ end
75
+
76
+ socket.close
77
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: upside_down_server
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Joel Byron Smith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-02-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Anything you serve with this server will be upside-down and backwards
14
+ (mirrored). It works by dynamically by adding CSS to flip the contents of the page.
15
+ Place your files in the public folder
16
+ email: joely5525@gmail.com
17
+ executables:
18
+ - upside_down_server
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - bin/upside_down_server
23
+ homepage: https://www.github.com/jbsmith86/upside_down_server
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.2.0
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Upside-down server will flip the page contents of a webpage
47
+ test_files: []
48
+ has_rdoc: