Skip to content

Commit

Permalink
[DOC] Header doc (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
BurdetteLamar committed Jan 19, 2023
1 parent f6506ff commit 3308362
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/net/http/header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -923,12 +923,24 @@ def set_form(params, enctype='application/x-www-form-urlencoded', formopt={})
end
end

# Set the Authorization: header for "Basic" authorization.
# Sets header <tt>'Authorization'</tt> using the given
# +account+ and +password+ strings:
#
# req.basic_auth('my_account', 'my_password')
# req['Authorization']
# # => "Basic bXlfYWNjb3VudDpteV9wYXNzd29yZA=="
#
def basic_auth(account, password)
@header['authorization'] = [basic_encode(account, password)]
end

# Set Proxy-Authorization: header for "Basic" authorization.
# Sets header <tt>'Proxy-Authorization'</tt> using the given
# +account+ and +password+ strings:
#
# req.proxy_basic_auth('my_account', 'my_password')
# req['Proxy-Authorization']
# # => "Basic bXlfYWNjb3VudDpteV9wYXNzd29yZA=="
#
def proxy_basic_auth(account, password)
@header['proxy-authorization'] = [basic_encode(account, password)]
end
Expand All @@ -938,13 +950,15 @@ def basic_encode(account, password)
end
private :basic_encode

# Returns whether the HTTP session is to be closed.
def connection_close?
token = /(?:\A|,)\s*close\s*(?:\z|,)/i
@header['connection']&.grep(token) {return true}
@header['proxy-connection']&.grep(token) {return true}
false
end

# Returns whether the HTTP session is to be kept alive.
def connection_keep_alive?
token = /(?:\A|,)\s*keep-alive\s*(?:\z|,)/i
@header['connection']&.grep(token) {return true}
Expand Down

0 comments on commit 3308362

Please sign in to comment.