Module: Wwwtf::HTTP
- Defined in:
- lib/wwwtf/http.rb,
lib/wwwtf/http/url.rb
Defined Under Namespace
Modules: URL
Class Attribute Summary collapse
-
.curl_headers ⇒ Object
Returns the value of attribute curl_headers.
Class Method Summary collapse
- .body(url) ⇒ Object
- .fix_urls(base_url, src_string) ⇒ Object
- .headers(url) ⇒ Object
- .page_dependency(url) ⇒ Object
Class Attribute Details
.curl_headers ⇒ Object
Returns the value of attribute curl_headers.
7 8 9 |
# File 'lib/wwwtf/http.rb', line 7 def curl_headers @curl_headers end |
Class Method Details
.body(url) ⇒ Object
21 22 23 |
# File 'lib/wwwtf/http.rb', line 21 def self.body(url) %x{curl -kLs -H '#{curl_headers}' #{url}} end |
.fix_urls(base_url, src_string) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/wwwtf/http.rb', line 36 def self.fix_urls(base_url, src_string) begin src_string = src_string.unescape.strip src_string = src_string[1..-2] if src_string.match(/^\".*\"$/) http = base_url.scan(/^(https*)\:\/\//).flatten.join if src_string.match(/^https*\:\/\//i) src_string elsif src_string.match(/^\/\//) "#{http}:#{src_string}" else File.join base_url, src_string end rescue puts "ERR: #{src_string}" return nil end end |
.headers(url) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/wwwtf/http.rb', line 11 def self.headers(url) hdrs = %x{curl -IkLs -H '#{curl_headers}' #{url}} headr = {} return headr if hdrs.match(/HTTP\/1\.[01]\s*[45][0-9][0-9]\s*\w/) hdr = hdrs.split("\r\n") hdr = hdr.collect{|h| {h.split(':')[0].strip => h.split(':')[1..-1].join.strip} } hdr.each{|h| headr = headr.merge h} headr end |
.page_dependency(url) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/wwwtf/http.rb', line 25 def self.page_dependency(url) page_content = body url xtmp_nodes = XMLMotor.splitter page_content = XMLMotor.indexify xtmp_nodes tag_src = XMLMotor.xmlattrib 'src', xtmp_nodes, src_in_page = tag_src.uniq.collect{|src| fix_urls url, src } Wwwtf::HTTP::URL.uniq([url] + src_in_page).compact end |