webot 2.0.0
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/weboot.rb +56 -0
- data/webot.rb +71 -0
- metadata +44 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 2fdb558a55d7539f2849047b208b32d9f80cfbace98207e5a6525ac3950bcefa
|
|
4
|
+
data.tar.gz: 58426c5a6ec91d7781b0cf365738e05de30987fd369ed43b324f601d713603d9
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 33c68b658feba52187cad6682462cbfc2f4f22771a9d7c255dec2e9c25e65ed2df41b98a390c34de2efc2a0937b70b42397bdb8251fa4fd153cf433a53c6c9b5
|
|
7
|
+
data.tar.gz: '088d0cb7568e55a85681cc5458b36e92ad4fae9a08297fc56b93b3544d89afcaca11c948c538c9bb7a541d42da71bff85109fbaf0705ae2d6916734368eb5971'
|
data/weboot.rb
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#coding:utf-8
|
|
2
|
+
require 'net/http'
|
|
3
|
+
|
|
4
|
+
module Weboot
|
|
5
|
+
module_function
|
|
6
|
+
|
|
7
|
+
def request text, protocol='http'
|
|
8
|
+
parts = text.gsub("\r","").split("\n\n")
|
|
9
|
+
head = parts.first
|
|
10
|
+
body = parts[1..-1].join("\n\n")
|
|
11
|
+
|
|
12
|
+
fields = head.split("\n")
|
|
13
|
+
action, path, method = fields.first.split(' ')
|
|
14
|
+
|
|
15
|
+
params = {}
|
|
16
|
+
fields[1..-1].each do|field|
|
|
17
|
+
key, value = field.split(': ')
|
|
18
|
+
params[key] = value
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
url = "#{protocol}://#{params['Host']}#{path}"
|
|
22
|
+
|
|
23
|
+
return { action: action, url: url, params: params, body: body }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def construct request
|
|
27
|
+
uri = URI.parse(request[:url])
|
|
28
|
+
protocol = uri.scheme
|
|
29
|
+
if request[:action]=='POST'
|
|
30
|
+
post = Net::HTTP::Post.new(uri.path, {'Content-Type' => 'application/x-www-form-urlencoded'}.merge(request[:params]))
|
|
31
|
+
post.body = request[:body] || '{}'
|
|
32
|
+
response = Net::HTTP.start(uri.host, uri.port) do |http|
|
|
33
|
+
http.request(post)
|
|
34
|
+
end
|
|
35
|
+
else # GET
|
|
36
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
37
|
+
http.use_ssl = protocol == 'https'
|
|
38
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl?
|
|
39
|
+
response, data = http.get(uri.path, {'Content-Type' => 'application/x-www-form-urlencoded'}.merge(request[:params]))
|
|
40
|
+
end
|
|
41
|
+
result = {'headers'=>{},'body'=>''}
|
|
42
|
+
case response
|
|
43
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
|
44
|
+
result['Code'] = response.code
|
|
45
|
+
result['Message'] = response.message
|
|
46
|
+
response.each do|key,value|
|
|
47
|
+
result['headers'][key] = value
|
|
48
|
+
end
|
|
49
|
+
result['body'] = response.body
|
|
50
|
+
else
|
|
51
|
+
result['body'] = response.value
|
|
52
|
+
end
|
|
53
|
+
return result
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
data/webot.rb
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#coding:utf-8
|
|
2
|
+
require 'net/http'
|
|
3
|
+
# https://ruby-doc.org/stdlib-3.0.1/libdoc/net/http/rdoc/Net/HTTP.html
|
|
4
|
+
|
|
5
|
+
module Webot
|
|
6
|
+
module_function
|
|
7
|
+
|
|
8
|
+
def get options
|
|
9
|
+
http = Net::HTTP.new(options[:url], (options[:port] || 80))
|
|
10
|
+
http.use_ssl = options[:https] || false
|
|
11
|
+
protocol = http.use_ssl? ? "https" : "http"
|
|
12
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl?
|
|
13
|
+
path = options[:path] || '/'
|
|
14
|
+
|
|
15
|
+
resp, data = http.get(path)
|
|
16
|
+
cookie = (options[:cookies] ? options[:cookies] : resp.response['set-cookie']).to_s.split(', ')[0].split('; ')[0]
|
|
17
|
+
headers = {
|
|
18
|
+
'Cookie' => cookie,
|
|
19
|
+
'Referer' => (options[:referer] || "#{protocol}://#{options[:url]}"),
|
|
20
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
|
21
|
+
}.merge!(options[:headers] || {})
|
|
22
|
+
|
|
23
|
+
resp, data = http.get(path, headers)
|
|
24
|
+
result = {'headers'=>{},'body'=>''}
|
|
25
|
+
result['Code'] = resp.code
|
|
26
|
+
result['Message'] = resp.message
|
|
27
|
+
resp.each do|key,value|
|
|
28
|
+
result['headers'][key] = value
|
|
29
|
+
end
|
|
30
|
+
result['body'] = resp.body
|
|
31
|
+
return result
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def post options
|
|
35
|
+
path = options[:path] || '/'
|
|
36
|
+
options[:protocol] = options[:protocol] ? options[:protocol] : (options[:https] ? 'https' : 'http')
|
|
37
|
+
uri = URI("#{options[:protocol]}://#{options[:url]}:#{options[:port]}#{path}")
|
|
38
|
+
req = Net::HTTP::Post.new(uri, options[:headers])
|
|
39
|
+
|
|
40
|
+
cookie = (options[:cookies] ? options[:cookies] : '').to_s.split(', ').to_s[0].split('; ')[0]
|
|
41
|
+
headers = {
|
|
42
|
+
'Cookie' => cookie,
|
|
43
|
+
'Referer' => (options[:referer] || "#{options[:protocol]}://#{options[:url]}:#{options[:port]}#{path}"),
|
|
44
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
|
45
|
+
}.merge!(options[:headers] || {})
|
|
46
|
+
req.set_form_data(options[:data] || {})
|
|
47
|
+
|
|
48
|
+
resp = Net::HTTP.start(options[:url], options[:port]) do |http|
|
|
49
|
+
http.request(req)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
result = {'headers'=>{},'body'=>''}
|
|
53
|
+
case resp
|
|
54
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
|
55
|
+
result['Code'] = resp.code
|
|
56
|
+
result['Message'] = resp.message
|
|
57
|
+
resp.each do|key,value|
|
|
58
|
+
result['headers'][key] = value
|
|
59
|
+
end
|
|
60
|
+
result['body'] = resp.body
|
|
61
|
+
else
|
|
62
|
+
resp.value
|
|
63
|
+
end
|
|
64
|
+
return result
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
__END__
|
|
69
|
+
result = Webot.get( url: 'www.baidu.com' )
|
|
70
|
+
result = Webot.post( url: '127.0.0.1', port:4567, path: '/1', data: {a: "1314"} )
|
|
71
|
+
pp result
|
metadata
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: webot
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 2.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Matt
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2025-01-03 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: web tool for request
|
|
14
|
+
email:
|
|
15
|
+
- matthrewchains@gmail.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- weboot.rb
|
|
21
|
+
- webot.rb
|
|
22
|
+
homepage: http://127.0.0.1
|
|
23
|
+
licenses: []
|
|
24
|
+
metadata: {}
|
|
25
|
+
post_install_message:
|
|
26
|
+
rdoc_options: []
|
|
27
|
+
require_paths:
|
|
28
|
+
- "."
|
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
requirements: []
|
|
40
|
+
rubygems_version: 3.5.23
|
|
41
|
+
signing_key:
|
|
42
|
+
specification_version: 4
|
|
43
|
+
summary: web-tool
|
|
44
|
+
test_files: []
|