panthro 0.0.5 → 0.1.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.
Files changed (5) hide show
  1. checksums.yaml +5 -5
  2. data/bin/panthro +5 -1
  3. data/config.ru +0 -2
  4. data/lib/panthro.rb +29 -16
  5. metadata +12 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a2b51d935324f8c6bc7d5fd5af10b01a9485e4d9
4
- data.tar.gz: fd5e4c59518fc472b01af20231996b83bb7d5bc8
2
+ SHA256:
3
+ metadata.gz: 3480979b92147050396d121f2bd8783cdae89f3246b43374ebad0db4304857ba
4
+ data.tar.gz: 87286819cb54e5a9338d2e662e76d8cd90c89348ef924a00a2f9bf433293c94f
5
5
  SHA512:
6
- metadata.gz: db4b83f581a21a5a0e07244f42e7f61c111e9ae450a6f5b938a1b86c02258e0ba3470d1867fb3eb2eede4888f12bf14281666271687fa3f81d0a0986595e9260
7
- data.tar.gz: 428c34a9d21eedecb27ecfa485438fe0381644d7ad04aabc577abad7af94f125925ed644da430e591e60be4879aeab74b42da115423375223de550103bf2df49
6
+ metadata.gz: 2a1a6417ca97dc6b0385bbea9918f8dd05165be9cb45b4b994844de98c17941c7f9037c11ea98fe3138b8de3ba576bb7b2ca4a57c393bf5a9472ffd648d668a7
7
+ data.tar.gz: 92b58936e0ed67c91a373c5dba2ff288cc86dc67f4051ae808c2f514099f1ee876dcbeb40608dc48c2399e6a1ca2f9dd187b5f227e14b870dc0f06d12fdb56dd
data/bin/panthro CHANGED
@@ -6,9 +6,10 @@ NAME
6
6
  panthro -- The rubygems proxy cache
7
7
 
8
8
  SYNOPSYS
9
- panthro [--start | --stop]
9
+ panthro [--start | --startd | --stop]
10
10
 
11
11
  DESCRIPTION
12
+ !!! This project is a toy, is not usable for serious !!!
12
13
  The idea is to speed up the gem command caching gem and spec files. Rubygems proxy cache Is a rack app that cache static files into a local machine, where is runing. Is does not cache /api calls.
13
14
  EOS
14
15
 
@@ -20,6 +21,9 @@ pid_file = "#{Panthro.path}/rack.pid"
20
21
  case ARGV[0]
21
22
  when '--start'
22
23
  puts "Starting panthro server..."
24
+ `cd #{path} && rackup`
25
+ when '--startd'
26
+ puts "Starting panthro daemon server..."
23
27
  `cd #{path} && rackup --daemonize --pid #{pid_file}`
24
28
  when '--stop'
25
29
  puts "Stopping panthro server..."
data/config.ru CHANGED
@@ -1,5 +1,3 @@
1
- #\ --port 4732
2
-
3
1
  require File.expand_path( "lib/panthro", File.dirname(__FILE__) )
4
2
 
5
3
  run Panthro.new
data/lib/panthro.rb CHANGED
@@ -1,20 +1,21 @@
1
1
  require 'net/http'
2
2
 
3
3
  class Panthro
4
+ class << self
5
+ attr_accessor :path, :mirror, :disable_logs
6
+ end
4
7
 
5
8
  def call env
6
9
  @env = env
7
10
  @file_path = "#{ self.class.path }#{ env['PATH_INFO'] }"
11
+ @path = @env['PATH_INFO']
12
+ @method = @env['REQUEST_METHOD']
8
13
 
9
- return get_from_cache if File.exists? @file_path
14
+ return get_from_mirror if (@path == '/' or @path =~ /\/info/)
15
+ return get_from_cache if File.exist? @file_path
10
16
  get_from_mirror
11
17
  end
12
18
 
13
- class << self
14
- attr_accessor :path
15
- attr_accessor :mirror
16
- end
17
-
18
19
  private
19
20
 
20
21
  def uri_str
@@ -24,45 +25,57 @@ class Panthro
24
25
  end
25
26
 
26
27
  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'
28
+ http = Net::HTTP.new( uri.host, uri.port )
29
+ http.use_ssl = true
30
+ request = Net::HTTP::Get.new( uri.request_uri )
31
+ resp = http.request( request ) if @method == 'GET'
32
+ resp = http.head(@path) if @method == 'HEAD'
33
+ resp = get( URI resp['location'] ) if resp.code == '302'
31
34
  resp
32
35
  end
33
36
 
34
37
  def get_from_mirror
35
38
  @uri = URI uri_str
39
+ log(:get_mirror)
36
40
  @resp = get @uri
37
- write_cache!
38
-
41
+ write_cache! unless (@path == '/' or @path =~ /\/info/)
39
42
  headers = @resp.to_hash
40
43
  headers.delete 'transfer-encoding'
41
44
  headers.each{ |k,v| headers[k] = v.first }
42
45
 
43
- [ @resp.code, headers, [ @resp.body ] ]
46
+ [ @resp.code.to_i, headers, [ @resp.body.to_s ] ]
44
47
  end
45
48
 
46
49
  def write_cache!
47
- return if @uri.path =~ /\/api\//
48
50
  return unless @resp.code =~ /20/
49
51
 
52
+ log(:write_cache)
50
53
  dir = File.dirname @file_path
51
54
  FileUtils.mkdir_p dir unless File.directory? dir
52
-
53
55
  open( @file_path, "wb" ) do |file|
54
56
  file.write @resp.body
55
57
  end
56
58
  end
57
59
 
58
60
  def get_from_cache
61
+ log(:get_cache)
59
62
  file = File.open @file_path, "r"
60
63
  content = file.read
61
64
  file.close
62
65
 
63
66
  [ 200, {}, [ content ] ]
64
67
  end
68
+
69
+ def log(action)
70
+ actions = {
71
+ :get_mirror => "[ GET MIRROR ] #{@uri}",
72
+ :get_cache => "[ GET CACHE ] #{@file_path}",
73
+ :write_cache => "[ WRITE CACHE ] #{@file_path}"
74
+ }
75
+
76
+ puts actions[action] unless Panthro.disable_logs
77
+ end
65
78
  end
66
79
 
67
80
  Panthro.path = "#{ ENV['HOME'] }/.panthro"
68
- Panthro.mirror = 'http://rubygems.org'
81
+ Panthro.mirror = 'https://index.rubygems.org'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: panthro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gaston Ramos
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-26 00:00:00.000000000 Z
11
+ date: 2024-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cutest
@@ -30,17 +30,18 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.5'
33
+ version: '3.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.5'
41
- description: The idea is to speed up the gem command caching gem and spec files. Rubygems
42
- proxy cache Is a rack app that cache static files into a local machine, where is
43
- runing. Is does not cache /api calls.
40
+ version: '3.1'
41
+ description: "!!! This project is a toy, is not usable for serious !!! The idea is
42
+ to speed up the gem command caching gem and spec files. Rubygems proxy cache Is
43
+ a rack app that cache static files into a local machine, where is runing. Is does
44
+ not cache /api calls."
44
45
  email: ramos.gaston@gmail.com
45
46
  executables:
46
47
  - panthro
@@ -249,16 +250,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
249
250
  requirements:
250
251
  - - ">="
251
252
  - !ruby/object:Gem::Version
252
- version: '0'
253
+ version: '3.0'
253
254
  required_rubygems_version: !ruby/object:Gem::Requirement
254
255
  requirements:
255
256
  - - ">="
256
257
  - !ruby/object:Gem::Version
257
258
  version: '0'
258
259
  requirements: []
259
- rubyforge_project:
260
- rubygems_version: 2.4.4
261
- signing_key:
260
+ rubygems_version: 3.5.22
261
+ signing_key:
262
262
  specification_version: 4
263
263
  summary: 'Panthro: the rubygems proxy cache'
264
264
  test_files: []