em-http-request-samesite 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.gemtest +0 -0
  3. data/.gitignore +9 -0
  4. data/.rspec +0 -0
  5. data/.travis.yml +7 -0
  6. data/Changelog.md +68 -0
  7. data/Gemfile +14 -0
  8. data/README.md +63 -0
  9. data/Rakefile +10 -0
  10. data/benchmarks/clients.rb +170 -0
  11. data/benchmarks/em-excon.rb +87 -0
  12. data/benchmarks/em-profile.gif +0 -0
  13. data/benchmarks/em-profile.txt +65 -0
  14. data/benchmarks/server.rb +48 -0
  15. data/em-http-request-samesite-1.1.7.gem +0 -0
  16. data/em-http-request.gemspec +32 -0
  17. data/examples/.gitignore +1 -0
  18. data/examples/digest_auth/client.rb +25 -0
  19. data/examples/digest_auth/server.rb +28 -0
  20. data/examples/fetch.rb +30 -0
  21. data/examples/fibered-http.rb +51 -0
  22. data/examples/multi.rb +25 -0
  23. data/examples/oauth-tweet.rb +35 -0
  24. data/examples/socks5.rb +23 -0
  25. data/lib/em-http-request.rb +1 -0
  26. data/lib/em-http.rb +20 -0
  27. data/lib/em-http/client.rb +341 -0
  28. data/lib/em-http/core_ext/bytesize.rb +6 -0
  29. data/lib/em-http/decoders.rb +252 -0
  30. data/lib/em-http/http_client_options.rb +49 -0
  31. data/lib/em-http/http_connection.rb +321 -0
  32. data/lib/em-http/http_connection_options.rb +70 -0
  33. data/lib/em-http/http_encoding.rb +149 -0
  34. data/lib/em-http/http_header.rb +83 -0
  35. data/lib/em-http/http_status_codes.rb +57 -0
  36. data/lib/em-http/middleware/digest_auth.rb +112 -0
  37. data/lib/em-http/middleware/json_response.rb +15 -0
  38. data/lib/em-http/middleware/oauth.rb +40 -0
  39. data/lib/em-http/middleware/oauth2.rb +28 -0
  40. data/lib/em-http/multi.rb +57 -0
  41. data/lib/em-http/request.rb +23 -0
  42. data/lib/em-http/version.rb +5 -0
  43. data/lib/em/io_streamer.rb +49 -0
  44. data/spec/client_fiber_spec.rb +23 -0
  45. data/spec/client_spec.rb +1000 -0
  46. data/spec/digest_auth_spec.rb +48 -0
  47. data/spec/dns_spec.rb +41 -0
  48. data/spec/encoding_spec.rb +49 -0
  49. data/spec/external_spec.rb +150 -0
  50. data/spec/fixtures/google.ca +16 -0
  51. data/spec/fixtures/gzip-sample.gz +0 -0
  52. data/spec/gzip_spec.rb +91 -0
  53. data/spec/helper.rb +31 -0
  54. data/spec/http_proxy_spec.rb +268 -0
  55. data/spec/middleware/oauth2_spec.rb +15 -0
  56. data/spec/middleware_spec.rb +143 -0
  57. data/spec/multi_spec.rb +104 -0
  58. data/spec/pipelining_spec.rb +66 -0
  59. data/spec/redirect_spec.rb +430 -0
  60. data/spec/socksify_proxy_spec.rb +60 -0
  61. data/spec/spec_helper.rb +25 -0
  62. data/spec/ssl_spec.rb +71 -0
  63. data/spec/stallion.rb +334 -0
  64. data/spec/stub_server.rb +45 -0
  65. metadata +266 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8ea216d5238086682cc941478c2bf05e70cdb7ea16b59e09950c885b1e512394
4
+ data.tar.gz: 4376ef9d9761cf806488d4fed8494c2d51838902d7abcd63b5927036f3869aab
5
+ SHA512:
6
+ metadata.gz: 5d2ec4884affa48bab23cdd3dba528858123c27549c7ccbad3829007d810aee7afd0f8d8a8169ef35c4e73113647f95bacaaa85d31549d6cdc60255874bf3a8c
7
+ data.tar.gz: 0a9696c7951bbcd4a6065ed3de205a01fa991ab9c981d7bfc2819b80f80c0060e10479e7ae5f7a5a7240a34342d2c85158f39c088ee4da608daa658ac8ab05cd
data/.gemtest ADDED
File without changes
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ *.bundle
2
+ *.o
3
+ Makefile
4
+ mkmf.log
5
+ Gemfile.lock
6
+ misc
7
+ gems/
8
+ vendor/
9
+ .idea
data/.rspec ADDED
File without changes
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.4
4
+ script: bundle exec rake spec
5
+ notifications:
6
+ email:
7
+ - ilya@igvita.com
data/Changelog.md ADDED
@@ -0,0 +1,68 @@
1
+ # Changelog
2
+
3
+ ## master
4
+
5
+ - User-Agent header is now removed if set to nil.
6
+
7
+ ## 1.0.0.beta.1 / 2011-02-20 - The big rewrite
8
+
9
+ - Switched parser from Ragel to http_parser.rb
10
+ - Removed em_buffer C extension
11
+ - Added support for HTTP keepalive
12
+ - Added support for HTTP pipelining
13
+ - ~60% performance improvement across the board: less GC time!
14
+ - Refactored & split all tests
15
+ - Basic 100-Continue handling on POST/PUT
16
+
17
+ ## 0.3.0 / 2011-01-15
18
+
19
+ - IMPORTANT: default to non-persistent connections (timeout => 0 now requires :keepalive => true)
20
+ - see: https://github.com/igrigorik/em-http-request/commit/1ca5b608e876c18fa6cfa318d0685dcf5b974e09
21
+
22
+ - added escape_utils dependency to fix slow encode on long string escapes
23
+
24
+ - bugfix: proxy authorization headers
25
+ - bugfix: default to Encoding.default_external on invalid encoding in response
26
+ - bugfix: do not normalize URI's internally
27
+ - bugfix: more robust Encoding detection
28
+
29
+
30
+ ## 0.2.15 / 2010-11-18
31
+
32
+ - bugfix: follow redirects on missing content-length
33
+ - bugfix: fixed undefined warnings when running in strict mode
34
+
35
+ ## 0.2.14 / 2010-10-06
36
+
37
+ - bugfix: form-encode keys/values of ruby objects passed in as body
38
+
39
+ ## 0.2.13 / 2010-09-25
40
+
41
+ - added SOCKS5 proxy support
42
+ - bugfix: follow redirects on HEAD requests
43
+
44
+ ## 0.2.12 / 2010-09-12
45
+
46
+ - added headers callback (http.headers {|h| p h})
47
+ - added .close method on client obj to terminate session (accepts message)
48
+
49
+ - bugfix: report 0 for response status on 1.9 on timeouts
50
+ - bugfix: handle bad Location host redirects
51
+ - bugfix: reset host override on connect
52
+
53
+ ## 0.2.11 / 2010-08-16
54
+
55
+ - all URIs are now normalized prior to dispatch (and on redirect)
56
+ - default to direct proxy (instead of CONNECT handshake) - better performance
57
+ - specify :proxy => {:tunnel => true} if you need to force CONNECT route
58
+ - MultiRequest accepts block syntax for dispatching parallel requests (see specs)
59
+ - MockHttpRequest accepts block syntax (see Mock wiki page)
60
+
61
+
62
+ - bugfix: nullbyte frame for websockets
63
+ - bugfix: set @uri on DNS resolve failure
64
+ - bugfix: handle bad hosts in absolute redirects
65
+ - bugfix: reset seen content on redirects (doh!)
66
+ - bugfix: invalid multibyte escape in websocket regex (1.9.2+)
67
+ - bugfix: report etag and last_modified headers correctly
68
+
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :benchmark do
6
+ gem 'curb'
7
+ gem 'excon'
8
+ gem 'httparty'
9
+ gem 'rest-client'
10
+ gem 'sinatra'
11
+ gem 'streamly_ffi'
12
+ gem 'tach', '>= 0.0.8'
13
+ gem 'typhoeus'
14
+ end
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # EM-HTTP-Request
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/em-http-request.svg)](http://rubygems.org/gems/em-http-request) [![Build Status](https://travis-ci.org/igrigorik/em-http-request.svg)](https://travis-ci.org/igrigorik/em-http-request)
4
+
5
+ Async (EventMachine) HTTP client, with support for:
6
+
7
+ - Asynchronous HTTP API for single & parallel request execution
8
+ - Keep-Alive and HTTP pipelining support
9
+ - Auto-follow 3xx redirects with max depth
10
+ - Automatic gzip & deflate decoding
11
+ - Streaming response processing
12
+ - Streaming file uploads
13
+ - HTTP proxy and SOCKS5 support
14
+ - Basic Auth & OAuth
15
+ - Connection-level & global middleware support
16
+ - HTTP parser via [http_parser.rb](https://github.com/tmm1/http_parser.rb)
17
+ - Works wherever EventMachine runs: Rubinius, JRuby, MRI
18
+
19
+ ## Getting started
20
+
21
+ gem install em-http-request
22
+
23
+ - Introductory [screencast](http://everburning.com/news/eventmachine-screencast-em-http-request)
24
+ - [Issuing GET/POST/etc requests](https://github.com/igrigorik/em-http-request/wiki/Issuing-Requests)
25
+ - [Issuing parallel requests with Multi interface](https://github.com/igrigorik/em-http-request/wiki/Parallel-Requests)
26
+ - [Handling Redirects & Timeouts](https://github.com/igrigorik/em-http-request/wiki/Redirects-and-Timeouts)
27
+ - [Keep-Alive and HTTP Pipelining](https://github.com/igrigorik/em-http-request/wiki/Keep-Alive-and-HTTP-Pipelining)
28
+ - [Stream processing responses & uploads](https://github.com/igrigorik/em-http-request/wiki/Streaming)
29
+ - [Issuing requests through HTTP & SOCKS5 proxies](https://github.com/igrigorik/em-http-request/wiki/Proxy)
30
+ - [Basic Auth & OAuth](https://github.com/igrigorik/em-http-request/wiki/Basic-Auth-and-OAuth)
31
+ - [GZIP & Deflate decoding](https://github.com/igrigorik/em-http-request/wiki/Compression)
32
+ - [EM-HTTP Middleware](https://github.com/igrigorik/em-http-request/wiki/Middleware)
33
+
34
+ ## Extensions
35
+
36
+ Several higher-order Ruby projects have incorporated em-http and other Ruby HTTP clients:
37
+
38
+ - [EM-Synchrony](https://github.com/igrigorik/em-synchrony) - Collection of convenience classes and primitives to help untangle evented code (Ruby 1.9 + Fibers).
39
+ - [Rack-Client](https://github.com/halorgium/rack-client) - Use Rack API for server, test, and client side. Supports Rack middleware!
40
+ - [Example in action](https://gist.github.com/802391)
41
+ - [Faraday](https://github.com/lostisland/faraday) - Modular HTTP client library using middleware heavily inspired by Rack.
42
+ - [Example in action](https://gist.github.com/802395)
43
+
44
+ ## Testing
45
+
46
+ - [WebMock](https://github.com/bblimke/webmock) - Library for stubbing and setting expectations on HTTP requests in Ruby.
47
+ - Example of [using WebMock, VCR & EM-HTTP](https://gist.github.com/802553)
48
+
49
+ ## Other libraries & applications using EM-HTTP
50
+
51
+ - [VMWare CloudFoundry](https://github.com/cloudfoundry) - The open platform-as-a-service project
52
+ - [PubSubHubbub](https://github.com/igrigorik/PubSubHubbub) - Asynchronous PubSubHubbub ruby client
53
+ - [em-net-http](https://github.com/jfairbairn/em-net-http) - Monkeypatching Net::HTTP to play ball with EventMachine
54
+ - [chirpstream](https://github.com/joshbuddy/chirpstream) - EM client for Twitters Chirpstream API
55
+ - [rsolr-async](https://github.com/mwmitchell/rsolr-async) - An asynchronus connection adapter for RSolr
56
+ - [Firering](https://github.com/EmmanuelOga/firering) - Eventmachine powered Campfire API
57
+ - [RDaneel](https://github.com/hasmanydevelopers/RDaneel) - Ruby crawler which respects robots.txt
58
+ - [em-eventsource](https://github.com/AF83/em-eventsource) - EventSource client for EventMachine
59
+ - and many others.. drop me a link if you want yours included!
60
+
61
+ ### License
62
+
63
+ (MIT License) - Copyright (c) 2011 Ilya Grigorik
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc "Run all RSpec tests"
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :default => :spec
10
+ task :test => [:spec]
@@ -0,0 +1,170 @@
1
+ $: << './benchmarks'
2
+ require 'server'
3
+
4
+ require 'excon'
5
+ require 'httparty'
6
+ require 'net/http'
7
+ require 'open-uri'
8
+ require 'rest_client'
9
+ require 'tach'
10
+ require 'typhoeus'
11
+
12
+ url = 'http://127.0.0.1:9292/data/10000'
13
+
14
+ with_server do
15
+ Tach.meter(100) do
16
+
17
+ tach('curb (persistent)') do |n|
18
+ curb = Curl::Easy.new
19
+
20
+ n.times do
21
+ curb.url = url
22
+ curb.http_get
23
+ curb.body_str
24
+ end
25
+ end
26
+
27
+ tach('em-http-request') do |n|
28
+ EventMachine.run {
29
+ count = 0
30
+ error = 0
31
+
32
+ n.times do
33
+ http = EventMachine::HttpRequest.new(url).get
34
+
35
+ http.callback {
36
+ count += 1
37
+ if count == n
38
+ p [count, error]
39
+ EM.stop
40
+ end
41
+ }
42
+
43
+ http.errback {
44
+ count += 1
45
+ error += 1
46
+ if count == n
47
+ p [count, error]
48
+ EM.stop
49
+ end
50
+ }
51
+ end
52
+ }
53
+ end
54
+
55
+ tach('em-http-request (persistent)') do |n|
56
+ EventMachine.run {
57
+ count = 0
58
+ error = 0
59
+
60
+ conn = EventMachine::HttpRequest.new(url)
61
+
62
+ n.times do
63
+ http = conn.get :keepalive => true
64
+ http.callback {
65
+ count += 1
66
+ if count == n
67
+ p [count, error]
68
+ EM.stop
69
+ end
70
+ }
71
+
72
+ http.errback {
73
+ count += 1
74
+ error += 1
75
+ if count == n
76
+ p [count, error]
77
+ EM.stop
78
+ end
79
+ }
80
+ end
81
+ }
82
+ end
83
+
84
+ tach('Excon') do
85
+ Excon.get(url).body
86
+ end
87
+
88
+ excon = Excon.new(url)
89
+ tach('Excon (persistent)') do
90
+ excon.request(:method => 'get').body
91
+ end
92
+
93
+ tach('HTTParty') do
94
+ HTTParty.get(url).body
95
+ end
96
+
97
+ uri = Addressable::URI.parse(url)
98
+ tach('Net::HTTP') do
99
+ Net::HTTP.start(uri.host, uri.port) {|http| http.get(uri.path).body }
100
+ end
101
+
102
+ uri = Addressable::URI.parse(url)
103
+ Net::HTTP.start(uri.host, uri.port) do |http|
104
+ tach('Net::HTTP (persistent)') do
105
+ http.get(uri.path).body
106
+ end
107
+ end
108
+
109
+ tach('open-uri') do
110
+ open(url).read
111
+ end
112
+
113
+ tach('RestClient') do
114
+ RestClient.get(url)
115
+ end
116
+
117
+ streamly = StreamlyFFI::Connection.new
118
+ tach('StreamlyFFI (persistent)') do
119
+ streamly.get(url)
120
+ end
121
+
122
+ tach('Typhoeus') do |n|
123
+ hydra = Typhoeus::Hydra.new( max_concurrency: 8 )
124
+ hydra.disable_memoization
125
+ count = 0
126
+ error = 0
127
+ n.times {
128
+ req = Typhoeus::Request.new( url )
129
+ req.on_complete do |res|
130
+ count += 1
131
+ error += 1 if !res.success?
132
+ p [count, error] if count == n
133
+
134
+ end
135
+ hydra.queue( req )
136
+ }
137
+ hydra.run
138
+ end
139
+
140
+ end
141
+ end
142
+
143
+
144
+ #+------------------------------+-----------+
145
+ #| tach | total |
146
+ #+------------------------------+-----------+
147
+ #| em-http-request (persistent) | 0.145512 |
148
+ #+------------------------------+-----------+
149
+ #| Excon | 0.181564 |
150
+ #+------------------------------+-----------+
151
+ #| RestClient | 0.253127 |
152
+ #+------------------------------+-----------+
153
+ #| Net::HTTP | 0.294412 |
154
+ #+------------------------------+-----------+
155
+ #| HTTParty | 0.305397 |
156
+ #+------------------------------+-----------+
157
+ #| open-uri | 0.307007 |
158
+ #+------------------------------+-----------+
159
+ #| Net::HTTP (persistent) | 0.313716 |
160
+ #+------------------------------+-----------+
161
+ #| Typhoeus | 0.514725 |
162
+ #+------------------------------+-----------+
163
+ #| curb (persistent) | 3.981700 |
164
+ #+------------------------------+-----------+
165
+ #| StreamlyFFI (persistent) | 3.989063 |
166
+ #+------------------------------+-----------+
167
+ #| Excon (persistent) | 4.018761 |
168
+ #+------------------------------+-----------+
169
+ #| em-http-request | 15.025291 |
170
+ #+------------------------------+-----------+
@@ -0,0 +1,87 @@
1
+ $: << './benchmarks'
2
+ require 'server'
3
+
4
+ url = 'http://127.0.0.1/10k.html'
5
+
6
+ with_server do
7
+ Tach.meter(100) do
8
+
9
+ excon = Excon.new(url)
10
+ tach('Excon (persistent)') do
11
+ excon.request(:method => 'get').body
12
+ end
13
+
14
+ tach('Excon') do
15
+ Excon.get(url).body
16
+ end
17
+
18
+ tach('em-http-request') do |n|
19
+ EventMachine.run {
20
+ count = 0
21
+ error = 0
22
+ n.times do
23
+ EM.next_tick do
24
+ http = EventMachine::HttpRequest.new(url, :connect_timeout => 1).get
25
+
26
+ http.callback {
27
+ count += 1
28
+ if count == n
29
+ p [count, error]
30
+ EM.stop
31
+ end
32
+ }
33
+
34
+ http.errback {
35
+ count += 1
36
+ error += 1
37
+ if count == n
38
+ p [count, error]
39
+ EM.stop
40
+ end
41
+ }
42
+ end
43
+ end
44
+ }
45
+ end
46
+
47
+ tach('em-http-request (persistent)') do |n|
48
+ EventMachine.run {
49
+ count = 0
50
+ error = 0
51
+ conn = EventMachine::HttpRequest.new(url)
52
+
53
+ n.times do
54
+ http = conn.get :keepalive => true
55
+ http.callback {
56
+ count += 1
57
+ if count == n
58
+ p [count, error]
59
+ EM.stop
60
+ end
61
+ }
62
+
63
+ http.errback {
64
+ count += 1
65
+ error += 1
66
+ if count == n
67
+ p [count, error]
68
+ EM.stop
69
+ end
70
+ }
71
+ end
72
+ }
73
+ end
74
+ end
75
+ end
76
+
77
+ # +------------------------------+----------+
78
+ # | tach | total |
79
+ # +------------------------------+----------+
80
+ # | em-http-request (persistent) | 0.018133 |
81
+ # +------------------------------+----------+
82
+ # | Excon (persistent) | 0.023975 |
83
+ # +------------------------------+----------+
84
+ # | Excon | 0.032877 |
85
+ # +------------------------------+----------+
86
+ # | em-http-request | 0.042891 |
87
+ # +------------------------------+----------+