nice_http 0.9.6 → 0.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +59 -0
- data/lib/nice_http.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 425c7cb8f8ed1196fde60bd2ccb0e3f96e8b020e78f36be07806f24ecd870340
|
4
|
+
data.tar.gz: 472dcb152fa486d8121f2ecf3482e4e2474b467f6616d606a01b50dab88ad9ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01d45597653f6af87582cbbff0d5bb34f429013e0dbf649eb75e9acf8d65f200a35f43154e26a03381c409e67389fd3c8ecf16fca1c8b6bb8dde55f2ef0a4ba9
|
7
|
+
data.tar.gz: e01f1cd9968013a7b27ab029e775feba356fa01933f4abf65b8c9b8942cc5e79f46afde0d7a04f61837bfccf773bb27e1fb5bf17b0d7cba74f0f58fde9364180
|
data/README.md
CHANGED
@@ -219,6 +219,65 @@ resp = @http.get("/HTTP/Basic/")
|
|
219
219
|
|
220
220
|
```
|
221
221
|
|
222
|
+
Remember for other kind of authentication systems NiceHttp take care of the redirections and cookies that are requested to be set. In case you need to add a header with a token you can add it by using your NiceHttp object and the key headers, for example:
|
223
|
+
|
224
|
+
```ruby
|
225
|
+
@http.headers.tokenuno = "xxx"
|
226
|
+
# headers => {tokenuno: "xxx"}
|
227
|
+
|
228
|
+
#another way:
|
229
|
+
@http.headers[:tokendos] = "yyy"
|
230
|
+
# headers => {tokenuno: "xxx", tokendos: "yyyy"}
|
231
|
+
|
232
|
+
```
|
233
|
+
|
234
|
+
In case you want or need to control the redirections by yourself instead of allowing NiceHttp to do it, then set ```@http.auto_redirect = false```
|
235
|
+
|
236
|
+
An example using OpenID authentication:
|
237
|
+
|
238
|
+
```ruby
|
239
|
+
server = "https://samples.auth0.com/"
|
240
|
+
path="/authorize?client_id=kbyuFDidLLm280LIwVFiazOqjO3ty8KH&response_type=code"
|
241
|
+
|
242
|
+
@http = NiceHttp.new(server)
|
243
|
+
|
244
|
+
|
245
|
+
resp = @http.get(path)
|
246
|
+
|
247
|
+
p "With autoredirection:"
|
248
|
+
p "Cookies: "
|
249
|
+
p @http.cookies
|
250
|
+
p "Code: #{resp.code} #{resp.message} "
|
251
|
+
p "*"*40
|
252
|
+
|
253
|
+
@http2 = NiceHttp.new(server)
|
254
|
+
@http2.auto_redirect = false
|
255
|
+
|
256
|
+
resp = @http2.get(path)
|
257
|
+
|
258
|
+
p "Without autoredirection:"
|
259
|
+
p "Cookies: "
|
260
|
+
p @http2.cookies
|
261
|
+
p "Code: #{resp.code} #{resp.message} "
|
262
|
+
|
263
|
+
```
|
264
|
+
|
265
|
+
The output:
|
266
|
+
|
267
|
+
```
|
268
|
+
"With autoredirection:"
|
269
|
+
"Cookies: "
|
270
|
+
{"/"=>{"auth0"=>"s%3A6vEEwmmIf-9YAG-NjvsOIyZAh-NS97jj.yFSXILdmCov6DRwXjEei3q3eHIrxZxHI4eg4%2BTpUaK4"}, "/usernamepassword/login"=>{"_csrf"=>"bboZ0koMScwXkISzWaAMTYdY"}}
|
271
|
+
"Code: 200 OK "
|
272
|
+
"****************************************"
|
273
|
+
"Without autoredirection:"
|
274
|
+
"Cookies: "
|
275
|
+
{"/"=>{"auth0"=>"s%3AcKndc44gllWyJv8FLztUIctuH4b__g0V.QEF3SOobK8%2FvX89iUKzGbfSP4Vt2bRtY2WH7ygBUkg4"}}
|
276
|
+
"Code: 302 Found "
|
277
|
+
|
278
|
+
```
|
279
|
+
|
280
|
+
|
222
281
|
## Send multipart content
|
223
282
|
|
224
283
|
Example posting a csv file:
|
data/lib/nice_http.rb
CHANGED
@@ -205,7 +205,7 @@ class NiceHttp
|
|
205
205
|
return @response
|
206
206
|
end
|
207
207
|
begin
|
208
|
-
if path.
|
208
|
+
if path.start_with?("http:") or path.start_with?("https:") then #server included on path problably because of a redirection to a different server
|
209
209
|
require 'uri'
|
210
210
|
uri = URI.parse(path)
|
211
211
|
ssl=false
|