mirror of
https://github.com/seejohnrun/haste-client.git
synced 2025-12-22 03:21:28 +00:00
Adds Basic HTTP Auth support
This commit is contained in:
@@ -47,6 +47,14 @@ alias work_haste="HASTE_SERVER=http://something.com haste"
|
|||||||
|
|
||||||
After which you can use `work_haste` to send hastes to that server instead.
|
After which you can use `work_haste` to send hastes to that server instead.
|
||||||
|
|
||||||
|
### Basic Auth
|
||||||
|
|
||||||
|
If your haste-server requires basic http authentication, you can use:
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
HASTE_SERVER=http://something.com HASTE_USER=user HASTE_PWD=pass haste some_file.txt
|
||||||
|
```
|
||||||
|
|
||||||
## Windows Support
|
## Windows Support
|
||||||
|
|
||||||
If you'd like an alternative on Windows that supports functionality similar to `pbcopy`, check out Aidan Ryan's [WinHaste](https://github.com/ajryan/WinHaste) project.
|
If you'd like an alternative on Windows that supports functionality similar to `pbcopy`, check out Aidan Ryan's [WinHaste](https://github.com/ajryan/WinHaste) project.
|
||||||
|
|||||||
16
lib/haste.rb
16
lib/haste.rb
@@ -16,6 +16,8 @@ module Haste
|
|||||||
abort 'No input file given' unless file
|
abort 'No input file given' unless file
|
||||||
abort "#{file}: No such path" unless File.exists?(file)
|
abort "#{file}: No such path" unless File.exists?(file)
|
||||||
@input = open(file).read
|
@input = open(file).read
|
||||||
|
@user = ENV['HASTE_USER']
|
||||||
|
@password = ENV['HASTE_PWD']
|
||||||
else
|
else
|
||||||
@input = STDIN.readlines.join
|
@input = STDIN.readlines.join
|
||||||
end
|
end
|
||||||
@@ -26,12 +28,16 @@ module Haste
|
|||||||
# Upload the and output the URL we get back
|
# Upload the and output the URL we get back
|
||||||
def start
|
def start
|
||||||
uri = URI.parse server
|
uri = URI.parse server
|
||||||
http = Net::HTTP.new uri.host, uri.port
|
post = Net::HTTP::Post.new '/documents'
|
||||||
if uri.scheme =~ /^https/
|
post.body = @input
|
||||||
http.use_ssl = true
|
post.basic_auth @user, @password if @user && @password
|
||||||
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
response = Net::HTTP.new(uri.host, uri.port).start do |http|
|
||||||
|
if uri.scheme =~ /^https/
|
||||||
|
http.use_ssl = true
|
||||||
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||||
|
end
|
||||||
|
http.request(post)
|
||||||
end
|
end
|
||||||
response = http.post '/documents', @input
|
|
||||||
if response.is_a?(Net::HTTPOK)
|
if response.is_a?(Net::HTTPOK)
|
||||||
data = JSON.parse(response.body)
|
data = JSON.parse(response.body)
|
||||||
method = STDOUT.tty? ? :puts : :print
|
method = STDOUT.tty? ? :puts : :print
|
||||||
|
|||||||
Reference in New Issue
Block a user