From 3308362d9b30f4d34e805647dc78e1a273975a89 Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Thu, 19 Jan 2023 12:58:34 -0600 Subject: [PATCH] [DOC] Header doc (#104) --- lib/net/http/header.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/net/http/header.rb b/lib/net/http/header.rb index ab744f5f..ef6f32b8 100644 --- a/lib/net/http/header.rb +++ b/lib/net/http/header.rb @@ -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 'Authorization' 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 'Proxy-Authorization' 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 @@ -938,6 +950,7 @@ 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} @@ -945,6 +958,7 @@ def connection_close? 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}