panthro 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 +7 -0
- data/bin/panthro +3 -0
- data/config.ru +7 -0
- data/lib/panthro.rb +65 -0
- metadata +49 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 460eaea23290db9452d64f19f0423efee9ad9838
|
4
|
+
data.tar.gz: b9681b9b54a1a6182c3374552001f057b90b7f37
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6f949559137be9f3d2b5d6c380d127b4901a7c795ea0d649c04929ea7ad74ec2a29d41434193ba7d173e1d513e32e49460a1137c5b58583d19d8228d66ca6fba
|
7
|
+
data.tar.gz: 788e43e0a5c15736fc0670ed82f139df1ddf3da3801c57284aadcffcd57232252e7fe231ceb3169f4d767d518b60fdc16a0265c688329cafe5c9c6cbaa0bdf90
|
data/bin/panthro
ADDED
data/config.ru
ADDED
data/lib/panthro.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
class Panthro
|
4
|
+
|
5
|
+
def call env
|
6
|
+
@env = env
|
7
|
+
@file_path = "#{ self.class.path }#{ env['PATH_INFO'] }"
|
8
|
+
|
9
|
+
return get_from_cache if File.exists? @file_path
|
10
|
+
get_from_mirror
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
attr_accessor :path
|
15
|
+
attr_accessor :mirror
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def uri_str
|
21
|
+
uri = "#{ Panthro.mirror }#{ @env['PATH_INFO'] }"
|
22
|
+
uri += "?#{ @env['QUERY_STRING'] }" unless @env['QUERY_STRING'].empty?
|
23
|
+
uri
|
24
|
+
end
|
25
|
+
|
26
|
+
def get uri
|
27
|
+
http = Net::HTTP.new( uri.host, uri.port )
|
28
|
+
request = Net::HTTP::Get.new( uri.request_uri )
|
29
|
+
resp = http.request( request )
|
30
|
+
resp = get( URI resp['location'] ) if resp.code == '302'
|
31
|
+
resp
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_from_mirror
|
35
|
+
@uri = URI uri_str
|
36
|
+
@resp = get @uri
|
37
|
+
write_cache!
|
38
|
+
|
39
|
+
headers = @resp.to_hash
|
40
|
+
headers.delete 'transfer-encoding'
|
41
|
+
headers.each{ |k,v| headers[k] = v.first }
|
42
|
+
|
43
|
+
[ @resp.code, headers, [ @resp.body ] ]
|
44
|
+
end
|
45
|
+
|
46
|
+
def write_cache!
|
47
|
+
return if @uri.path =~ /\/api\//
|
48
|
+
return unless @resp.code =~ /20/
|
49
|
+
|
50
|
+
dir = File.dirname @file_path
|
51
|
+
FileUtils.mkdir_p dir unless File.directory? dir
|
52
|
+
|
53
|
+
open( @file_path, "wb" ) do |file|
|
54
|
+
file.write @resp.body
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_from_cache
|
59
|
+
file = File.open @file_path, "r"
|
60
|
+
content = file.read
|
61
|
+
file.close
|
62
|
+
|
63
|
+
[ 200, {}, [ content ] ]
|
64
|
+
end
|
65
|
+
end
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: panthro
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gaston Ramos
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: The idea is to speed up the gem command caching gem and spec files. Rubygems
|
14
|
+
proxy cache Is a rack app that cache static files into a local machine, where is
|
15
|
+
runing. Is does not cache /api calls.
|
16
|
+
email: ramos.gaston@gmail.com
|
17
|
+
executables:
|
18
|
+
- panthro
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- bin/panthro
|
23
|
+
- config.ru
|
24
|
+
- lib/panthro.rb
|
25
|
+
homepage: https://github.com/gramos/panthro
|
26
|
+
licenses:
|
27
|
+
- GPLv3
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 2.4.4
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: 'Panthro: the rubygems proxy cache'
|
49
|
+
test_files: []
|