This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module NetHttpFaradayPatch | |
def create_request(env) | |
super.tap do |request| | |
if env[:body].respond_to?(:read) | |
request.content_length = env[:body].size | |
end | |
end | |
end | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Net::HTTP::Post | |
.new('/', 'Content-Type': 'application/json') | |
.tap { |req| req.body_stream = StringIO.new(operation) } | |
.tap { |req| req.content_length = operation.bytesize } | |
.yield_self(&@http.method(:request)) | |
.yield_self(&:body) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts client.get #=> [] | |
puts client.add('12313131') #=> ['12313131'] | |
puts client.add('msg') #=> ['12313131', 'msg'] | |
puts client.del('msg') #=> ['12313131'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
class Api | |
HOST = 'localhost' | |
PORT = 3000 | |
def initialize | |
@http = Net::HTTP.new(HOST, PORT) | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby server.rb | |
[2019-01-09 22:38:58] INFO WEBrick 1.4.2 | |
[2019-01-09 22:38:58] INFO ruby 2.6.0 (2018-12-25) | |
[2019-01-09 22:38:58] INFO WEBrick::HTTPServer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'webrick' | |
require 'set' | |
server = WEBrick::HTTPServer.new(Port: 3000) | |
set = Set.new | |
server.mount_proc '/' do |req, res| | |
data, action = req.body.split(',') | |
action ||= 'ADD' | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client = Api.new | |
client.get #=> [] | |
client.add('12313131') #=> ['12313131'] | |
client.add('msg') #=> ['12313131', 'msg'] | |
client.del('msg') #=> ['12313131'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Net::HTTP.post(URI('http://httpbin.org/post'), 'ใ'*100_000) | |
Traceback (most recent call last): | |
16: from /net/http.rb:502:in `block in post' | |
15: from /net/http.rb:1281:in `post' | |
14: from /net/http.rb:1493:in `send_entity' | |
13: from /net/http.rb:1479:in `request' | |
12: from /net/http.rb:1506:in `transport_request' | |
11: from /net/http.rb:1506:in `catch' | |
10: from /net/http.rb:1507:in `block in transport_request' | |
9: from /net/http/generic_request.rb:123:in `exec' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt-get install sqlitebrowser |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tar -xvf backup.tar |
NewerOlder