|
134 | 134 | # - #[]=: Sets the string or array value for the given key.
|
135 | 135 | # - #add_field: Creates or adds to the array value for the given key.
|
136 | 136 | # - #basic_auth: Sets the string authorization header for <tt>'Authorization'</tt>.
|
| 137 | +# - #bearer_auth: Sets the string authorization header for <tt>'Authorization'</tt>. |
137 | 138 | # - #content_length=: Sets the integer length for field <tt>'Content-Length</tt>.
|
138 | 139 | # - #content_type=: Sets the string value for field <tt>'Content-Type'</tt>.
|
139 | 140 | # - #proxy_basic_auth: Sets the string authorization header for <tt>'Proxy-Authorization'</tt>.
|
| 141 | +# - #proxy_bearer_auth: Sets the string authorization header for <tt>'Proxy-Authorization'</tt>. |
140 | 142 | # - #set_range: Sets the value for field <tt>'Range'</tt>.
|
141 | 143 | #
|
142 | 144 | # === Form Setters
|
@@ -871,21 +873,36 @@ def set_form(params, enctype='application/x-www-form-urlencoded', formopt={})
|
871 | 873 | end
|
872 | 874 | end
|
873 | 875 |
|
874 |
| - # Set the Authorization: header for "Basic" authorization. |
| 876 | + # Sets the Authorization: header for "Basic" authorization. |
875 | 877 | def basic_auth(account, password)
|
876 | 878 | @header['authorization'] = [basic_encode(account, password)]
|
877 | 879 | end
|
878 | 880 |
|
879 |
| - # Set Proxy-Authorization: header for "Basic" authorization. |
| 881 | + # Sets the Authorization: header for "Bearer" authorization. |
| 882 | + def bearer_auth(access_token) |
| 883 | + @header['authorization'] = [bearer_encode(access_token)] |
| 884 | + end |
| 885 | + |
| 886 | + # Sets the Proxy-Authorization: header for "Basic" authorization. |
880 | 887 | def proxy_basic_auth(account, password)
|
881 | 888 | @header['proxy-authorization'] = [basic_encode(account, password)]
|
882 | 889 | end
|
883 | 890 |
|
| 891 | + # Sets the Proxy-Authorization: header for "Bearer" authorization. |
| 892 | + def proxy_bearer_auth(access_token) |
| 893 | + @header['proxy-authorization'] = [bearer_encode(access_token)] |
| 894 | + end |
| 895 | + |
884 | 896 | def basic_encode(account, password)
|
885 | 897 | 'Basic ' + ["#{account}:#{password}"].pack('m0')
|
886 | 898 | end
|
887 | 899 | private :basic_encode
|
888 | 900 |
|
| 901 | + def bearer_encode(access_token) |
| 902 | + "Bearer #{access_token}" |
| 903 | + end |
| 904 | + private :bearer_encode |
| 905 | + |
889 | 906 | def connection_close?
|
890 | 907 | token = /(?:\A|,)\s*close\s*(?:\z|,)/i
|
891 | 908 | @header['connection']&.grep(token) {return true}
|
|
0 commit comments