File: upload.rb

package info (click to toggle)
ruby-async-http 0.59.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 572 kB
  • sloc: ruby: 4,164; javascript: 40; makefile: 4
file content (26 lines) | stat: -rw-r--r-- 581 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env ruby

require 'async'
require 'protocol/http/body/file'
require 'async/http/internet'

Async do
	internet = Async::HTTP::Internet.new
	
	headers = [
		['accept', 'text/plain'],
	]
	
	body = Protocol::HTTP::Body::File.open(File.join(__dir__, "data.txt"))
	
	response = internet.post("https://utopia-falcon-heroku.herokuapp.com/echo/index", headers, body)
	
	# response.read -> string
	# response.each {|chunk| ...}
	# response.close (forcefully ignore data)
	# body = response.finish (read and buffer response)
	response.save("echo.txt")
	
ensure
	internet.close
end