rhack 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,52 +1,20 @@
1
1
  Copyright (c) 2010-2013
2
2
  Sergey Baev <tinbka@gmail.com>
3
- Curb is free software licensed under the following terms:
4
3
 
5
- 1. You may make and give away verbatim copies of the source form of the
6
- software without restriction, provided that you duplicate all of the
7
- original copyright notices and associated disclaimers.
4
+ This work is licensed under the same license as Ruby language.
5
+
6
+ This licence also implies a compliance with details of CURB-LICENSE.
8
7
 
9
- 2. You may modify your copy of the software in any way, provided that
10
- you do at least ONE of the following:
8
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
9
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
10
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
11
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
12
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
13
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
14
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
15
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
16
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
17
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
18
+ SUCH DAMAGE.
11
19
 
12
- a) place your modifications in the Public Domain or otherwise
13
- make them Freely Available, such as by posting said
14
- modifications to Usenet or an equivalent medium, or by allowing
15
- the author to include your modifications in the software.
16
20
 
17
- b) use the modified software only within your corporation or
18
- organization.
19
-
20
- c) give non-standard binaries non-standard names, with
21
- instructions on where to get the original software distribution.
22
-
23
- d) make other distribution arrangements with the author.
24
-
25
- 3. You may distribute the software in object code or binary form,
26
- provided that you do at least ONE of the following:
27
-
28
- a) distribute the binaries and library files of the software,
29
- together with instructions (in the manual page or equivalent)
30
- on where to get the original distribution.
31
-
32
- b) accompany the distribution with the machine-readable source of
33
- the software.
34
-
35
- c) give non-standard binaries non-standard names, with
36
- instructions on where to get the original software distribution.
37
-
38
- d) make other distribution arrangements with the author.
39
-
40
- 4. You may modify and include the part of the software into any other
41
- software (possibly commercial).
42
-
43
- 5. The scripts and library files supplied as input to or produced as
44
- output from the software do not automatically fall under the
45
- copyright of the software, but belong to whomever generated them,
46
- and may be sold commercially, and may be aggregated with this
47
- software.
48
-
49
- 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
50
- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
51
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
52
- PURPOSE.
@@ -1,27 +1,19 @@
1
1
  ext/curb/curb_errors.c
2
2
  ext/curb/curb_errors.h
3
- ext/curb/curb_errors.o
4
3
  ext/curb/Makefile
5
4
  ext/curb/curb_macros.h
6
5
  ext/curb/curb_multi.c
7
6
  ext/curb/curb_multi.h
8
- ext/curb/curb_multi.o
9
7
  ext/curb/curb_upload.c
10
8
  ext/curb/curb_upload.h
11
- ext/curb/curb_upload.o
12
9
  ext/curb/curb_config.h
13
10
  ext/curb/extconf.rb
14
11
  ext/curb/curb.c
15
12
  ext/curb/curb.h
16
- ext/curb/curb.o
17
- ext/curb/curb_core.so
18
13
  ext/curb/curb_easy.c
19
14
  ext/curb/curb_easy.h
20
- ext/curb/curb_easy.o
21
- ext/curb/mkmf.log
22
15
  ext/curb/curb_postfield.c
23
16
  ext/curb/curb_postfield.h
24
- ext/curb/curb_postfield.o
25
17
  ext/curb-original/curb_errors.c
26
18
  ext/curb-original/curb_errors.h
27
19
  ext/curb-original/curb_macros.h
@@ -61,9 +53,8 @@ test/test_scout.rb
61
53
  test/test_frame.rb
62
54
  ./Gemfile.lock
63
55
  ./LICENSE
56
+ ./README.md
64
57
  ./Rakefile
65
58
  ./Manifest.txt
66
59
  ./CURB-LICENSE
67
- ./README.txt
68
- ./Gemfile
69
- ./History.txt
60
+ ./Gemfile
@@ -0,0 +1,76 @@
1
+ ### RHACK
2
+ [github](https://github.com/tinbka/rhack)
3
+
4
+ RHACK is Ruby Http ACcess Kit -- curl-based web-client for developing web-scrapers/bots.
5
+
6
+ ##### Features
7
+ * Asynchronous, still EventMachine independent. Synchronization can be turned on with 1sec per waiting penalty
8
+ * Fast as on simple queries as on high load. Can process up to thousands (limited by a net interface, of course) different parallel requests of any HTTP method with no penalty
9
+ * Flexibly configurable on 3 levels:
10
+ * * Curl::Easy (simplest request configuration, inherited from [curb gem](http://github.com/taf2/curb))
11
+ * * ::Scout (Curl::Easy wrapper with transparent cookies and extendable anonimization processing, detailed request/response info, callbacks and retry configuration)
12
+ * * ::Frame (Scout array wrapper with smart request interpretor, load balancing and extendable response processor)
13
+ * Included support of javascript processing on loaded pages (johnson gem)
14
+ * Web-service abstraction for creating scrapers, that implement some examples of how to use this library
15
+
16
+ ---
17
+
18
+ It's still randomly documented since it's just my working tool.
19
+
20
+ #### Expected to complete:
21
+
22
+ * Redis-based configurable cache for ::Service and for downloads
23
+ * Full javascript processing, including linked scripts; maybe support of other javascript engines gems
24
+
25
+ ### CHANGES
26
+
27
+ ##### Version 0.4.1
28
+
29
+ * Сhanged ::Frame @static behaviour, :static option now accept hash with :procotol key (::Frame#validate comment)
30
+ * Changed log level in curl-global.rb
31
+ * Described the library and *marked down* this readme
32
+
33
+ ##### Version 0.4
34
+
35
+ * Fixed bugs
36
+ * * idle execution in Rails application thread
37
+ * * Curl::Easy default callback
38
+ * * some misspelling-bugs
39
+ * Minified ::ScoutSquad#next waiting time
40
+ * ::Service
41
+ * * added meta-methods #login (sync only) and #scrape!(<::Page>)
42
+ * ::Frame
43
+ * * made new cache prototype. Call #use_cache!(false?) for (in)activate and #drop_cache! for clearance
44
+ * * added :xhr exec option
45
+ * ::Page
46
+ * * #title returns full title by default
47
+ * * #html is auto-encoded to UTF-8 during #process
48
+
49
+ ##### Version 0.3
50
+
51
+ * Adjusted cookie processor in accordance with web-servers and entrust redirection process to ::Scout
52
+ * Added some shortcuts to ::Frame and Curl modules
53
+ * Сonfig defaults are now taken from rails
54
+ * Removed crappy database usage from lib/words.rb
55
+ * curb_multi.c: Moved callbacks out of rb_rescue so that I could know wtf was happen there
56
+
57
+ ##### Version 0.2
58
+
59
+ * Nastily pulled down curb-0.8.1 extension sources and harshly patched by changes made long before, so that the core will be as modern as possible and with necessary features
60
+ * Fixed syntax for Ruby 1.9
61
+
62
+ ##### Version 0.1
63
+
64
+ * A long time ago in a galaxy far, far away...
65
+ * A library had been created based on Net::HTTP
66
+ * In a few months its base had been changed by curb-0.4.4 because of poorness and incovinience of Net::HTTP
67
+ * Had been made background-mode for Curl::Multi and multipart body setting for Curl::Easy so that Curl could be both sync and async
68
+ * Had been added a couple of wrappers for Curl::Easy and its results, proxy lists processor, scrapers for a few web-services, and plugin for libxml-ruby that lives at rmtools gem now
69
+
70
+ ### License
71
+
72
+ RHACK is copyright (c) 2010-2013 Sergey Baev <tinbka@gmail.com>, and released under the terms of the Ruby license.
73
+ See the LICENSE file for the details.
74
+ Rhack is also include slightly modified Curb gem extension source code. For original
75
+ Curb gem code you may want to check ext/curb-original or visit <http://github.com/taf2/curb/tree/master>.
76
+ See the CURB-LICENSE file for the details.
data/Rakefile CHANGED
@@ -8,14 +8,14 @@ rescue LoadError
8
8
  end
9
9
 
10
10
  compile_manifest
11
- RHACK_VERSION = '0.4.0'
11
+ RHACK_VERSION = '0.4.1'
12
12
  begin
13
13
  require 'hoe'
14
14
  config = Hoe.spec "rhack" do |h|
15
15
  h.developer("Sergey Baev", "tinbka@gmail.com")
16
16
 
17
- h.description = 'Webscraping library based on curb gem extension and libxml-ruby (and optionally Johnson and ActiveRecord)'
18
- # h.summary = h.description
17
+ h.description = 'Ruby Http ACcess Kit -- curl-based web-client for developing web-scrapers/bots'
18
+ h.summary = h.description
19
19
  h.urls = ['https://github.com/tinbka/rhack']
20
20
 
21
21
  h.extra_deps << ['rmtools','>= 1.2.12']
@@ -12,11 +12,11 @@ ECHO = $(ECHO1:0=@echo)
12
12
  #### Start of system configuration section. ####
13
13
 
14
14
  srcdir = .
15
- topdir = /home/shinku/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1
16
- hdrdir = /home/shinku/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1
17
- arch_hdrdir = /home/shinku/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/$(arch)
15
+ topdir = /home/shinku/.rvm/rubies/ruby-1.9.3-p327/include/ruby-1.9.1
16
+ hdrdir = /home/shinku/.rvm/rubies/ruby-1.9.3-p327/include/ruby-1.9.1
17
+ arch_hdrdir = /home/shinku/.rvm/rubies/ruby-1.9.3-p327/include/ruby-1.9.1/$(arch)
18
18
  VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
19
- prefix = $(DESTDIR)/home/shinku/.rvm/rubies/ruby-1.9.3-p194
19
+ prefix = $(DESTDIR)/home/shinku/.rvm/rubies/ruby-1.9.3-p327
20
20
  rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
21
21
  exec_prefix = $(prefix)
22
22
  vendorhdrdir = $(rubyhdrdir)/vendor_ruby
@@ -59,21 +59,22 @@ LIBRUBY = $(LIBRUBY_SO)
59
59
  LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
60
60
  LIBRUBYARG_SHARED = -Wl,-R -Wl,$(libdir) -L$(libdir) -l$(RUBY_SO_NAME)
61
61
  LIBRUBYARG_STATIC = -Wl,-R -Wl,$(libdir) -L$(libdir) -l$(RUBY_SO_NAME)-static
62
- OUTFLAG = -o
63
- COUTFLAG = -o
62
+ empty =
63
+ OUTFLAG = -o $(empty)
64
+ COUTFLAG = -o $(empty)
64
65
 
65
66
  RUBY_EXTCONF_H = curb_config.h
66
67
  cflags = $(optflags) $(debugflags) $(warnflags)
67
68
  optflags = -O3
68
69
  debugflags = -ggdb
69
- warnflags = -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration
70
- CFLAGS = -fPIC $(cflags) -fPIC -g -Wall $(ARCH_FLAG)
70
+ warnflags = -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration
71
+ CFLAGS = -fPIC -I/home/shinku/.rvm/usr/include -fPIC -g -Wall $(ARCH_FLAG)
71
72
  INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
72
73
  DEFS = -D_FILE_OFFSET_BITS=64
73
- CPPFLAGS = -DRUBY_EXTCONF_H=\"$(RUBY_EXTCONF_H)\" -I/home/shinku/.rvm/usr/include $(DEFS) $(cppflags)
74
+ CPPFLAGS = -DRUBY_EXTCONF_H=\"$(RUBY_EXTCONF_H)\" $(DEFS) $(cppflags) -I/home/shinku/.rvm/usr/include
74
75
  CXXFLAGS = $(CFLAGS) $(cxxflags)
75
- ldflags = -L. -rdynamic -Wl,-export-dynamic
76
- dldflags =
76
+ ldflags = -L. -L/home/shinku/.rvm/usr/lib -rdynamic -Wl,-export-dynamic -L/home/shinku/.rvm/usr/lib -Wl,-R/home/shinku/.rvm/usr/lib
77
+ dldflags = -L/home/shinku/.rvm/usr/lib -Wl,-R/home/shinku/.rvm/usr/lib
77
78
  ARCH_FLAG =
78
79
  DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
79
80
  LDSHARED = $(CC) -shared
@@ -87,7 +88,7 @@ RUBY_SO_NAME = ruby
87
88
  arch = i686-linux
88
89
  sitearch = $(arch)
89
90
  ruby_version = 1.9.1
90
- ruby = /home/shinku/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
91
+ ruby = /home/shinku/.rvm/rubies/ruby-1.9.3-p327/bin/ruby
91
92
  RUBY = $(ruby)
92
93
  RM = rm -f
93
94
  RM_RF = $(RUBY) -run -e rm -- -rf
@@ -97,6 +98,7 @@ INSTALL = /usr/bin/install -c
97
98
  INSTALL_PROG = $(INSTALL) -m 0755
98
99
  INSTALL_DATA = $(INSTALL) -m 644
99
100
  COPY = cp
101
+ TOUCH = exit >
100
102
 
101
103
  #### End of system configuration section. ####
102
104
 
@@ -115,8 +117,8 @@ extout_prefix =
115
117
  target_prefix =
116
118
  LOCAL_LIBS =
117
119
  LIBS = $(LIBRUBYARG_SHARED) -lpthread -lrt -ldl -lcrypt -lm -lc -lcurl
118
- SRCS = curb_easy.c curb_upload.c curb.c curb_multi.c curb_errors.c curb_postfield.c
119
- OBJS = curb_easy.o curb_upload.o curb.o curb_multi.o curb_errors.o curb_postfield.o
120
+ SRCS = curb.c curb_errors.c curb_multi.c curb_upload.c curb_easy.c curb_postfield.c
121
+ OBJS = curb.o curb_errors.o curb_multi.o curb_upload.o curb_easy.o curb_postfield.o
120
122
  TARGET = curb_core
121
123
  DLLIB = $(TARGET).so
122
124
  EXTSTATIC =
@@ -124,8 +126,8 @@ STATIC_LIB =
124
126
 
125
127
  BINDIR = $(bindir)
126
128
  RUBYCOMMONDIR = $(sitedir)$(target_prefix)
127
- RUBYLIBDIR = /home/shinku/.rvm/gems/ruby-1.9.3-p194@global/gems/rhack-0.3.3/lib$(target_prefix)
128
- RUBYARCHDIR = /home/shinku/.rvm/gems/ruby-1.9.3-p194@global/gems/rhack-0.3.3/lib$(target_prefix)
129
+ RUBYLIBDIR = /home/shinku/.rvm/gems/ruby-1.9.3-p327/gems/rhack-0.4.0/lib$(target_prefix)
130
+ RUBYARCHDIR = /home/shinku/.rvm/gems/ruby-1.9.3-p327/gems/rhack-0.4.0/lib$(target_prefix)
129
131
  HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
130
132
  ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
131
133
 
@@ -155,19 +157,21 @@ distclean: clean distclean-so distclean-rb-default distclean-rb
155
157
  realclean: distclean
156
158
  install: install-so install-rb
157
159
 
158
- install-so: $(RUBYARCHDIR)
159
160
  install-so: $(RUBYARCHDIR)/$(DLLIB)
160
161
  $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
161
- @-$(MAKEDIRS) $(@D)
162
+ -$(Q)$(MAKEDIRS) $(@D)
162
163
  $(INSTALL_PROG) $(DLLIB) $(@D)
164
+ clean-static::
165
+ -$(Q)$(RM) $(STATIC_LIB)
163
166
  install-rb: pre-install-rb install-rb-default
164
167
  install-rb-default: pre-install-rb-default
165
168
  pre-install-rb: Makefile
166
169
  pre-install-rb-default: Makefile
167
170
  pre-install-rb-default:
168
171
  $(ECHO) installing default curb_core libraries
169
- $(RUBYARCHDIR):
170
- $(Q) $(MAKEDIRS) $@
172
+ ./.RUBYARCHDIR.time:
173
+ $(Q) $(MAKEDIRS) $(RUBYARCHDIR)
174
+ $(Q) $(TOUCH) $@
171
175
 
172
176
  site-install: site-install-so site-install-rb
173
177
  site-install-so: install-so
@@ -205,7 +209,7 @@ site-install-rb: install-rb
205
209
 
206
210
  $(DLLIB): $(OBJS) Makefile
207
211
  $(ECHO) linking shared-object $(DLLIB)
208
- @-$(RM) $(@)
212
+ -$(Q)$(RM) $(@)
209
213
  $(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
210
214
 
211
215
 
@@ -3,13 +3,13 @@ module Curl
3
3
 
4
4
  def execute(unless_allready=false)
5
5
  if unless_allready and Curl.status
6
- return L.debug "Non-nil status! Avoid executing"
6
+ return L.log "Non-nil status! Avoid executing"
7
7
  end
8
8
  if $CarierThread and s = $CarierThread.status
9
- L.debug "Carier thread allready started and has status #{s}"
9
+ L.log "Carier thread allready started and has status #{s}"
10
10
  else
11
11
  if s = Curl.status(false) then L.warn s end
12
- L.debug($CarierThread ? "Resetting Carier thread" : "Setting Carier thread up")
12
+ L.log($CarierThread ? "Resetting Carier thread" : "Setting Carier thread up")
13
13
  $CarierThread = Thread.new {
14
14
  error = nil
15
15
  begin
@@ -22,7 +22,7 @@ module Curl
22
22
  begin
23
23
  # with true argument (idle) it would break only if no requests to perform
24
24
  break unless $Carier.perform true
25
- L.debug "Nothing to perform; idling..."
25
+ L.log "Nothing to perform; idling..."
26
26
  rescue => error
27
27
  break
28
28
  # but ruby mystically crashes if next sequence occur:
@@ -44,7 +44,7 @@ module Curl
44
44
 
45
45
  def wait
46
46
  if $CarierThread and $CarierThread.status
47
- if !(within = Thread.current == $CarierThread)
47
+ unless within = Thread.current == $CarierThread
48
48
  # We can't set `perform' timeout lesser than 1 second in the curl binding
49
49
  # because in that case thread status would always be "run"
50
50
  # so here we wait for exactly 1 sec
@@ -52,13 +52,14 @@ module Curl
52
52
  end
53
53
  # Also, if thread do Kernel.sleep, it would skip Curl.wait here
54
54
  if !$Carier.sheduled and ($CarierThread.status == 'sleep' or within && $Carier.reqs.empty?)
55
- L.debug "No shedule to wait"
55
+ L.log "No shedule to wait"
56
56
  else
57
- L.log "Waiting for Carier to complete in #{within ? 'it\'s thread' : Thread.main == Thread.current ? 'main thread' : 'thread '+Thread.current.object_id}"
57
+ this_thread = within ? 'it\'s thread' : Thread.main == Thread.current ? 'main thread' : 'thread '+Thread.current.object_id
58
+ L.log "Waiting for Carier to complete in #{this_thread}"
58
59
  begin
59
- L.log { "Trying to change $CarierThreadIsJoined #{$CarierThreadIsJoined} -> true from #{within ? 'it\'s thread' : Thread.main == Thread.current ? 'main thread' : 'thread '+Thread.current.object_id}" }
60
+ L.log { "Trying to change $CarierThreadIsJoined #{$CarierThreadIsJoined} -> true from #{this_thread}" }
60
61
  if within
61
- L.debug "calling this from one of callbacks to wait for the rest to complete"
62
+ L.log "calling this from one of callbacks to wait for the rest to complete"
62
63
  begin
63
64
  $Carier.perform
64
65
  rescue RuntimeError => e
@@ -74,12 +75,16 @@ module Curl
74
75
  recall!
75
76
  L.info "Carier thread recalled by keyboard"
76
77
  ensure
77
- L.log "trying to change $CarierThreadIsJoined #{$CarierThreadIsJoined} -> false from #{within ? 'it\'s' : 'main'} thread"
78
+ L.log "trying to change $CarierThreadIsJoined #{$CarierThreadIsJoined} -> false from #{this_thread}"
78
79
  if !within
79
80
  $CarierThreadIsJoined = false
81
+ # using Curl#execute from different threads may cause problems here when you don't control input,
82
+ # for example, in a daemonized ruby process
83
+ # just do not get $CarierThread joined from non-main thread
80
84
  if $CarierThread and e = $CarierThread.value
81
85
  # this will raise thread-safely in main thread
82
86
  # in case of unrescued error in CarierThread
87
+ L.log(([e.message]+RMTools.format_trace(e.backtrace))*"\n")
83
88
  recall!
84
89
  raise e
85
90
  end
@@ -98,23 +103,23 @@ module Curl
98
103
  def recall
99
104
  L.debug caller
100
105
  if $CarierThread
101
- L.debug "Recalling Carier thread"
106
+ L.log "Recalling Carier thread"
102
107
  $CarierThread.kill
103
108
  sleep 1
104
109
  else
105
- L.debug "No thread to recall"
110
+ L.log "No thread to recall"
106
111
  end
107
112
  end
108
113
  alias :stop :recall
109
114
 
110
115
  def recall!
111
116
  if $CarierThread
112
- L.info "Recalling thread and resetting Carier!!!"
117
+ L.warn "Recalling thread and resetting Carier!!!"
113
118
  $CarierThread.kill
114
119
  $CarierThread = nil
115
120
  $Carier.reset
116
121
  else
117
- L.debug "No thread to recall!"
122
+ L.log "No thread to recall!"
118
123
  end
119
124
  end
120
125
  alias :stop! :recall!
@@ -147,10 +152,10 @@ module Curl
147
152
  e
148
153
  end
149
154
  else
150
- L.debug "Carier Thread is exited without error"
155
+ L.log "Carier Thread is exited without error"
151
156
  end
152
157
  else
153
- L.debug "There is no Carier Thread atm"
158
+ L.log "There is no Carier Thread atm"
154
159
  end
155
160
  end
156
161
  alias :st :status
@@ -34,7 +34,7 @@ module HTTPAccessKit
34
34
  'http://' >> uri if uri !~ /^\w+:\/\//
35
35
  @loc = uri.parse:uri
36
36
  # be careful, if you set :static => false, frame will be unable to use implicit url
37
- @static = @opts.fetch(:static, true).b
37
+ @static = @opts.fetch(:static, true)
38
38
  else
39
39
  @loc = {}
40
40
  @static = false
@@ -76,7 +76,7 @@ module HTTPAccessKit
76
76
  end
77
77
 
78
78
  def inspect
79
- "<#Frame @ #{@ss.untargeted ? 'no target' : @loc.root}: #{'scout'.x @ss.size}#{', static' if @static}, cookies #{@ss[0].cookieProc ? 'on' : 'off'}>"
79
+ "<#Frame @ #{@ss.untargeted ? 'no target' : @loc.root}: #{'scout'.x @ss.size}#{', static'+(' => '+@static.protocol if @static.is(Hash)) if @static}, cookies #{@ss[0].cookieProc ? 'on' : 'off'}>"
80
80
  end
81
81
 
82
82
  # opts are :eval, :json, :hash, :wait, :proc_result, :save_result, :load_scripts,
@@ -426,15 +426,28 @@ module HTTPAccessKit
426
426
  end
427
427
  end
428
428
 
429
+ # :static option now can accept hash with :procotol key, in that case Frame can be relocated to the same domain on another protocol and default protocol would be the value of @static.protocol
429
430
  def validate(uri)
430
431
  if uri
431
432
  loc = uri.parse:uri
432
433
  if loc.root and loc.root != @loc.root
433
- raise TargetError, "failed to get #{uri} by static frame #{@loc.host}, you should first update it with new target" if @static
434
- @loc.root = loc.root
434
+ if @static
435
+ if @static.is Hash
436
+ if loc.host != @loc.host
437
+ raise TargetError, "unable to get #{uri} by static frame [#{@static.protocol}://]#{@loc.host}, you should first update it with new target"
438
+ end
439
+ else
440
+ raise TargetError, "unable to get #{uri} by static frame #{@loc.root}, you should first update it with new target"
441
+ end
442
+ end
443
+ @loc.root, @loc.host, @loc.protocol = loc.root, loc.host, loc.protocol
435
444
  uri
436
445
  elsif !loc.root
437
446
  raise TargetError if !@static
447
+ if @static.is Hash
448
+ @loc.protocol = @static.protocol
449
+ @loc.root = @loc.protocol+'://'+@loc.host
450
+ end
438
451
  File.join @loc.root, uri
439
452
  else uri
440
453
  end