message_bus 3.3.3 → 3.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintrc.js +21 -0
- data/.github/workflows/ci.yml +71 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +3 -1
- data/CHANGELOG +36 -8
- data/DEV.md +7 -0
- data/Gemfile +0 -25
- data/LICENSE +1 -1
- data/README.md +34 -15
- data/Rakefile +13 -8
- data/assets/message-bus-ajax.js +4 -10
- data/assets/message-bus.js +69 -76
- data/bench/codecs/all_codecs.rb +39 -0
- data/bench/codecs/marshal.rb +11 -0
- data/bench/codecs/packed_string.rb +67 -0
- data/bench/codecs/string_hack.rb +47 -0
- data/bench/codecs_large_user_list.rb +29 -0
- data/bench/codecs_standard_message.rb +29 -0
- data/examples/bench/bench.lua +2 -2
- data/lib/message_bus/backends/base.rb +3 -5
- data/lib/message_bus/backends/memory.rb +0 -2
- data/lib/message_bus/backends/postgres.rb +7 -5
- data/lib/message_bus/backends/redis.rb +3 -5
- data/lib/message_bus/client.rb +3 -7
- data/lib/message_bus/codec/base.rb +18 -0
- data/lib/message_bus/codec/json.rb +15 -0
- data/lib/message_bus/codec/oj.rb +21 -0
- data/lib/message_bus/connection_manager.rb +1 -1
- data/lib/message_bus/distributed_cache.rb +2 -1
- data/lib/message_bus/http_client.rb +2 -2
- data/lib/message_bus/rack/diagnostics.rb +30 -8
- data/lib/message_bus/rack/middleware.rb +22 -16
- data/lib/message_bus/rack/thin_ext.rb +1 -1
- data/lib/message_bus/version.rb +1 -1
- data/lib/message_bus.rb +38 -23
- data/message_bus.gemspec +20 -5
- data/package-lock.json +3744 -0
- data/package.json +14 -4
- data/spec/assets/SpecHelper.js +6 -5
- data/spec/assets/message-bus.spec.js +9 -6
- data/spec/helpers.rb +17 -6
- data/spec/integration/http_client_spec.rb +1 -1
- data/spec/lib/message_bus/backend_spec.rb +12 -44
- data/spec/lib/message_bus/client_spec.rb +6 -6
- data/spec/lib/message_bus/distributed_cache_spec.rb +5 -7
- data/spec/lib/message_bus/multi_process_spec.rb +1 -1
- data/spec/lib/message_bus/rack/middleware_spec.rb +16 -5
- data/spec/lib/message_bus_spec.rb +18 -7
- data/spec/spec_helper.rb +8 -9
- data/spec/support/jasmine-browser.json +16 -0
- metadata +230 -13
- data/.travis.yml +0 -17
- data/lib/message_bus/em_ext.rb +0 -6
- data/spec/assets/support/jasmine.yml +0 -126
- data/spec/assets/support/jasmine_helper.rb +0 -11
- data/vendor/assets/javascripts/message-bus-ajax.js +0 -44
- data/vendor/assets/javascripts/message-bus.js +0 -556
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16601ac02268a477a94bf0347922162f66ce17dfdba1c4c655d576b46e78a79c
|
4
|
+
data.tar.gz: 746e2295f873d9cfe75c28b079b406bb42329a992146d414c63292c2148a8f48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d048dde14c63d5abdda283571cb9c2be1b7fc809a94c7f0b4ec2eaa4785da03bc47535264741f65cfa1d66c75e1b0169ea0de39449456b9c791ba91518d62e9
|
7
|
+
data.tar.gz: 0cfbed1cab954e33805c94c7662c9094276615d5f338168da48d26f033da0f42685024b87aaee64d221e192d0592cd655fba7473da8d973616b218ce2858b045
|
data/.eslintrc.js
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
/*global module*/
|
2
|
+
module.exports = {
|
3
|
+
env: {
|
4
|
+
browser: true,
|
5
|
+
es2021: false,
|
6
|
+
},
|
7
|
+
extends: 'eslint:recommended',
|
8
|
+
parserOptions: {
|
9
|
+
ecmaVersion: 2015,
|
10
|
+
sourceType: 'module',
|
11
|
+
},
|
12
|
+
rules: {},
|
13
|
+
ignorePatterns: [
|
14
|
+
'/vendor',
|
15
|
+
'/doc',
|
16
|
+
'/assets/babel.min.js',
|
17
|
+
'/assets/jquery-1.8.2.js',
|
18
|
+
'/assets/react-dom.js',
|
19
|
+
'/assets/react.js',
|
20
|
+
],
|
21
|
+
};
|
@@ -0,0 +1,71 @@
|
|
1
|
+
name: Message Bus Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
push:
|
6
|
+
branches:
|
7
|
+
- main
|
8
|
+
|
9
|
+
env:
|
10
|
+
PGHOST: localhost
|
11
|
+
PGPORT: 5432
|
12
|
+
PGPASSWORD: postgres
|
13
|
+
PGUSER: postgres
|
14
|
+
|
15
|
+
jobs:
|
16
|
+
build:
|
17
|
+
runs-on: ubuntu-latest
|
18
|
+
name: Ruby ${{ matrix.ruby }} (redis ${{ matrix.redis }})
|
19
|
+
timeout-minutes: 10
|
20
|
+
|
21
|
+
services:
|
22
|
+
postgres:
|
23
|
+
image: postgres:14.0
|
24
|
+
env:
|
25
|
+
POSTGRES_PASSWORD: postgres
|
26
|
+
ports:
|
27
|
+
- 5432:5432
|
28
|
+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
29
|
+
redis:
|
30
|
+
image: ${{ format('redis:{0}', matrix.redis) }}
|
31
|
+
ports:
|
32
|
+
- 6379:6379
|
33
|
+
options: >-
|
34
|
+
--health-cmd "redis-cli ping"
|
35
|
+
--health-interval 10s
|
36
|
+
--health-timeout 5s
|
37
|
+
--health-retries 5
|
38
|
+
|
39
|
+
strategy:
|
40
|
+
fail-fast: false
|
41
|
+
matrix:
|
42
|
+
ruby: ["3.0", "2.7", "2.6"]
|
43
|
+
redis: ["5", "6"]
|
44
|
+
|
45
|
+
steps:
|
46
|
+
- uses: actions/checkout@v2
|
47
|
+
|
48
|
+
- uses: ruby/setup-ruby@v1
|
49
|
+
with:
|
50
|
+
ruby-version: ${{ matrix.ruby }}
|
51
|
+
bundler-cache: true # 'bundle install' and cache
|
52
|
+
|
53
|
+
- name: Set up Node.js
|
54
|
+
uses: actions/setup-node@v2
|
55
|
+
with:
|
56
|
+
node-version: 16
|
57
|
+
cache: npm
|
58
|
+
|
59
|
+
- name: Setup npm
|
60
|
+
run: npm install
|
61
|
+
|
62
|
+
- name: Create Database
|
63
|
+
run: |
|
64
|
+
createdb message_bus_test
|
65
|
+
|
66
|
+
- name: Tests
|
67
|
+
run: bundle exec rake
|
68
|
+
timeout-minutes: 3
|
69
|
+
|
70
|
+
- name: Linting
|
71
|
+
run: npx eslint .
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG
CHANGED
@@ -1,4 +1,32 @@
|
|
1
|
-
-
|
1
|
+
15-12-2021
|
2
|
+
|
3
|
+
- Version 3.3.7
|
4
|
+
|
5
|
+
- FIX: Prevent simple polling from clobbering the session
|
6
|
+
- SECURITY: Fix path traversal on diagnostics route.
|
7
|
+
|
8
|
+
31-05-2021
|
9
|
+
|
10
|
+
- Version 3.3.6
|
11
|
+
|
12
|
+
- FEATURE: Introduce support for transport codecs
|
13
|
+
- FIX: event subscription leak in JS after start/stop/start sequence
|
14
|
+
- FEATURE: MessageBus.onVisibilityChange() can be used to trigger a visibility change check by hand
|
15
|
+
|
16
|
+
28-04-2021
|
17
|
+
|
18
|
+
- Version 3.3.5
|
19
|
+
|
20
|
+
- PERF: Optimised CORS preflight handling
|
21
|
+
- FEATURE: Enable CORS preflight caching
|
22
|
+
- FEATURE: Removed trailing cache buster from message bus polls
|
23
|
+
- PERF: Improved delay poll timeout for cases where a tab moves in and out of the background
|
24
|
+
|
25
|
+
02-10-2020
|
26
|
+
|
27
|
+
- Version 3.3.4
|
28
|
+
|
29
|
+
- FIX: Remove trailing comma incorrectly added in ec60d8865.
|
2
30
|
|
3
31
|
18-09-2020
|
4
32
|
|
@@ -41,7 +69,7 @@
|
|
41
69
|
|
42
70
|
- Version 3.2.0
|
43
71
|
|
44
|
-
- FIX:
|
72
|
+
- FIX: compatibility with Rails 6.0.3, note: apps without ActionDispatch::Flash may stop working after this upgrade
|
45
73
|
to correct this disable middleware injection with `config.skip_message_bus_middleware = true` and configure middleware by hand with `app.middleware.use(MessageBus::Rack::Middleware)`
|
46
74
|
|
47
75
|
28-04-2020
|
@@ -168,7 +196,7 @@
|
|
168
196
|
|
169
197
|
- Version 2.1.6
|
170
198
|
|
171
|
-
- FEATURE: `
|
199
|
+
- FEATURE: `MessageBus.publish` accepts option `site_id` to publish to a site
|
172
200
|
- FEATURE: Added MessageBus::DistributedCache for cross process caching
|
173
201
|
- PERF: Use monotonic times in timer thread
|
174
202
|
- FEATURE: min poll interval is now configurable client side
|
@@ -232,7 +260,7 @@
|
|
232
260
|
|
233
261
|
- Version 2.0.6
|
234
262
|
|
235
|
-
- Fix: correct after_fork so it correctly
|
263
|
+
- Fix: correct after_fork so it correctly disconnects redis
|
236
264
|
- Fix: correct message_bus #destroy used in tests to clean up spec (deadlock)
|
237
265
|
- Fix: deliver backlog unconditionally when polling (and not long polling)
|
238
266
|
|
@@ -302,7 +330,7 @@
|
|
302
330
|
|
303
331
|
- Version 2.0.0.beta.6
|
304
332
|
|
305
|
-
- Feature: Support standalone
|
333
|
+
- Feature: Support standalone operation without depending on jQuery @nathanstitt
|
306
334
|
- Feature: Support a noconflict mode @nathanstitt
|
307
335
|
- Feature: Support JSON POST payload @nathanstitt
|
308
336
|
|
@@ -348,7 +376,7 @@
|
|
348
376
|
- Version 1.1.0
|
349
377
|
- Fix: keep track of client sequence on server, abandon old subscribes
|
350
378
|
- Fix: rare concurrency issue when subscribing concurrently
|
351
|
-
-
|
379
|
+
- Feature: remove most jQuery dependency from message-bus.js
|
352
380
|
|
353
381
|
09-07-2015
|
354
382
|
- Version 1.0.16
|
@@ -372,7 +400,7 @@
|
|
372
400
|
|
373
401
|
28-05-2015
|
374
402
|
- Version 1.0.12
|
375
|
-
- Feature: Support client_id
|
403
|
+
- Feature: Support client_id targeted message
|
376
404
|
|
377
405
|
06-05-2015
|
378
406
|
- Version 1.0.11
|
@@ -381,7 +409,7 @@
|
|
381
409
|
01-05-2015
|
382
410
|
- Version: 1.0.10
|
383
411
|
- Feature: no longer depends on EventMachine (only used for Thin backend)
|
384
|
-
- Feature:
|
412
|
+
- Feature: reliable pub sub will queue messages in memory if redis is readonly, configurable
|
385
413
|
- Fix: if redis is flushed we will continue to deliver messages
|
386
414
|
|
387
415
|
23-03-2015
|
data/DEV.md
ADDED
data/Gemfile
CHANGED
@@ -3,28 +3,3 @@ source 'https://rubygems.org'
|
|
3
3
|
|
4
4
|
# Specify your gem's dependencies in message_bus.gemspec
|
5
5
|
gemspec
|
6
|
-
|
7
|
-
group :test do
|
8
|
-
gem 'minitest'
|
9
|
-
gem 'minitest-hooks'
|
10
|
-
gem 'minitest-global_expectations'
|
11
|
-
gem 'rake'
|
12
|
-
gem 'http_parser.rb'
|
13
|
-
gem 'thin'
|
14
|
-
gem 'rack-test', require: 'rack/test'
|
15
|
-
gem 'jasmine'
|
16
|
-
gem 'puma'
|
17
|
-
end
|
18
|
-
|
19
|
-
group :test, :development do
|
20
|
-
gem 'byebug'
|
21
|
-
end
|
22
|
-
|
23
|
-
group :development do
|
24
|
-
gem 'yard'
|
25
|
-
gem 'rubocop-discourse', require: false
|
26
|
-
gem 'rubocop-rspec', require: false
|
27
|
-
end
|
28
|
-
|
29
|
-
gem 'rack'
|
30
|
-
gem 'concurrent-ruby' # for distributed-cache
|
data/LICENSE
CHANGED
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -10,15 +10,9 @@ MessageBus is implemented as Rack middleware and can be used by any Rails / Sina
|
|
10
10
|
|
11
11
|
Read the generated docs: <https://www.rubydoc.info/gems/message_bus>
|
12
12
|
|
13
|
-
## Try it out!
|
14
|
-
|
15
|
-
Live chat demo per [examples/chat](https://github.com/SamSaffron/message_bus/tree/master/examples/chat) is at:
|
16
|
-
|
17
|
-
### http://chat.samsaffron.com
|
18
|
-
|
19
13
|
## Ruby version support
|
20
14
|
|
21
|
-
MessageBus only support officially supported versions of Ruby; as of [
|
15
|
+
MessageBus only support officially supported versions of Ruby; as of [2021-03-31](https://www.ruby-lang.org/en/downloads/branches/) this means we only support Ruby version 2.6 and up.
|
22
16
|
|
23
17
|
## Can you handle concurrent requests?
|
24
18
|
|
@@ -74,19 +68,19 @@ id = MessageBus.last_id("/channel")
|
|
74
68
|
MessageBus.backlog "/channel", id
|
75
69
|
```
|
76
70
|
|
77
|
-
###
|
71
|
+
### Targeted messages
|
78
72
|
|
79
|
-
Messages can be
|
73
|
+
Messages can be targeted to particular clients by supplying the `client_ids` option when publishing a message.
|
80
74
|
|
81
75
|
```ruby
|
82
76
|
MessageBus.publish "/channel", "hello", client_ids: ["XXX", "YYY"] # (using MessageBus.clientId)
|
83
77
|
```
|
84
78
|
|
85
|
-
By configuring the `user_id_lookup` and `group_ids_lookup` options with a Proc or Lambda which will be called with a [Rack specification environment](https://github.com/rack/rack/blob/master/SPEC.rdoc#the-environment-), messages can be
|
79
|
+
By configuring the `user_id_lookup` and `group_ids_lookup` options with a Proc or Lambda which will be called with a [Rack specification environment](https://github.com/rack/rack/blob/master/SPEC.rdoc#the-environment-), messages can be targeted to particular clients users or groups by supplying either the `user_ids` or `group_ids` options when publishing a message.
|
86
80
|
|
87
81
|
```ruby
|
88
82
|
MessageBus.configure(user_id_lookup: proc do |env|
|
89
|
-
# this lookup occurs on JS-client
|
83
|
+
# this lookup occurs on JS-client polling, so that server can retrieve backlog
|
90
84
|
# for the client considering/matching/filtering user_ids set on published messages
|
91
85
|
# if user_id is not set on publish time, any user_id returned here will receive the message
|
92
86
|
# return the user id here
|
@@ -104,7 +98,7 @@ end)
|
|
104
98
|
MessageBus.publish "/channel", "hello", group_ids: [1, 2, 3]
|
105
99
|
|
106
100
|
# example of MessageBus to set user_ids from an initializer in Rails and Devise:
|
107
|
-
# config/
|
101
|
+
# config/initializers/message_bus.rb
|
108
102
|
MessageBus.user_id_lookup do |env|
|
109
103
|
req = Rack::Request.new(env)
|
110
104
|
|
@@ -115,13 +109,13 @@ MessageBus.user_id_lookup do |env|
|
|
115
109
|
end
|
116
110
|
```
|
117
111
|
|
118
|
-
If both `user_ids` and `group_ids` options are supplied when publishing a message, the message will be
|
112
|
+
If both `user_ids` and `group_ids` options are supplied when publishing a message, the message will be targeted at clients with lookup return values that matches on either the `user_ids` **or** the `group_ids` options.
|
119
113
|
|
120
114
|
```ruby
|
121
115
|
MessageBus.publish "/channel", "hello", user_ids: [1, 2, 3], group_ids: [1, 2, 3]
|
122
116
|
```
|
123
117
|
|
124
|
-
If the `client_ids` option is supplied with either the `user_ids` or `group_ids` options when
|
118
|
+
If the `client_ids` option is supplied with either the `user_ids` or `group_ids` options when publishing a message, the `client_ids` option will be applied unconditionally and messages will be filtered further using `user_id` or `group_id` clauses.
|
125
119
|
|
126
120
|
```ruby
|
127
121
|
MessageBus.publish "/channel", "hello", client_ids: ["XXX", "YYY"], user_ids: [1, 2, 3], group_ids: [1, 2, 3]
|
@@ -251,7 +245,7 @@ end)
|
|
251
245
|
MessageBus.publish "/channel", "some message"
|
252
246
|
|
253
247
|
# you can also choose to pass the `:site_id`.
|
254
|
-
# This takes
|
248
|
+
# This takes precedence over whatever `site_id_lookup`
|
255
249
|
# returns
|
256
250
|
MessageBus.publish "/channel", "some message", site_id: "site-id"
|
257
251
|
|
@@ -441,6 +435,31 @@ MessageBus.configure(backend: :memory)
|
|
441
435
|
|
442
436
|
The `:clear_every` option supported by the PostgreSQL backend is also supported by the in-memory backend.
|
443
437
|
|
438
|
+
|
439
|
+
### Transport codecs
|
440
|
+
|
441
|
+
By default MessageBus serializes messages to the backend using JSON. Under most situation this performs extremely well.
|
442
|
+
|
443
|
+
In some exceptional cases you may consider a different transport codec. To configure a custom codec use:
|
444
|
+
|
445
|
+
```ruby
|
446
|
+
MessageBus.configure(transport_codec: codec)
|
447
|
+
```
|
448
|
+
|
449
|
+
A codec class must implement MessageBus::Codec::Base. Specifically an `encode` and `decode` method.
|
450
|
+
|
451
|
+
See the `bench` directory for examples where the default JSON codec can perform poorly. A specific examples may be
|
452
|
+
attempting to distribute a message to a restricted list of thousands of users. In cases like this you may consider
|
453
|
+
using a packed string encoder.
|
454
|
+
|
455
|
+
Keep in mind, much of MessageBus internals and supporting tools expect data to be converted to JSON and back, if you use a naive (and fast) `Marshal` based codec you may need to limit the features you use. Specifically the Postgresql backend expects the codec never to return a string with `\u0000`, additionally some classes like DistributedCache expect keys to be converted to Strings.
|
456
|
+
|
457
|
+
Another example may be very large and complicated messages where Oj in compatibility mode outperforms JSON. To opt for the Oj codec use:
|
458
|
+
|
459
|
+
```
|
460
|
+
MessageBus.configure(transport_codec: MessageBus::Codec::Oj.new)
|
461
|
+
```
|
462
|
+
|
444
463
|
### Forking/threading app servers
|
445
464
|
|
446
465
|
If you're using a forking or threading app server and you're not getting immediate delivery of published messages, you might need to configure your web server to re-connect to the message_bus backend
|
data/Rakefile
CHANGED
@@ -4,12 +4,8 @@ require 'rake/testtask'
|
|
4
4
|
require 'bundler'
|
5
5
|
require 'bundler/gem_tasks'
|
6
6
|
require 'bundler/setup'
|
7
|
-
require 'jasmine'
|
8
|
-
|
9
|
-
ENV['JASMINE_CONFIG_PATH'] ||= File.join(Dir.pwd, 'spec', 'assets', 'support', 'jasmine.yml')
|
10
|
-
load 'jasmine/tasks/jasmine.rake'
|
11
|
-
|
12
7
|
require 'rubocop/rake_task'
|
8
|
+
|
13
9
|
RuboCop::RakeTask.new
|
14
10
|
|
15
11
|
require 'yard'
|
@@ -35,7 +31,14 @@ module Bundler
|
|
35
31
|
end
|
36
32
|
end
|
37
33
|
|
38
|
-
|
34
|
+
namespace :jasmine do
|
35
|
+
desc "Run Jasmine tests in headless mode"
|
36
|
+
task 'ci' do
|
37
|
+
if !system("npx jasmine-browser-runner runSpecs")
|
38
|
+
exit 1
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
39
42
|
|
40
43
|
backends = Dir["lib/message_bus/backends/*.rb"].map { |file| file.match(%r{backends/(?<backend>.*).rb})[:backend] } - ["base"]
|
41
44
|
|
@@ -57,6 +60,8 @@ namespace :spec do
|
|
57
60
|
|
58
61
|
desc "Run integration tests"
|
59
62
|
task :integration do
|
63
|
+
require "socket"
|
64
|
+
|
60
65
|
def port_available?(port)
|
61
66
|
server = TCPServer.open("0.0.0.0", port)
|
62
67
|
server.close
|
@@ -78,7 +83,7 @@ namespace :spec do
|
|
78
83
|
end
|
79
84
|
|
80
85
|
desc "Run tests on all backends, plus client JS tests"
|
81
|
-
task spec: backends.map { |backend| "spec:#{backend}" } + [:
|
86
|
+
task spec: backends.map { |backend| "spec:#{backend}" } + ["jasmine:ci", "spec:integration"]
|
82
87
|
|
83
88
|
desc "Run performance benchmarks on all backends"
|
84
89
|
task :performance do
|
@@ -94,5 +99,5 @@ desc "Run all tests, link checks and confirms documentation compiles without err
|
|
94
99
|
task default: [:spec, :rubocop, :test_doc]
|
95
100
|
|
96
101
|
Rake::Task['release'].enhance do
|
97
|
-
sh "
|
102
|
+
sh "yarn publish"
|
98
103
|
end
|
data/assets/message-bus-ajax.js
CHANGED
@@ -2,27 +2,21 @@
|
|
2
2
|
// as a fallback if jQuery is not present
|
3
3
|
//
|
4
4
|
// Only implements methods & options used by MessageBus
|
5
|
-
(function(global
|
5
|
+
(function(global) {
|
6
6
|
'use strict';
|
7
7
|
if (!global.MessageBus){
|
8
8
|
throw new Error("MessageBus must be loaded before the ajax adapter");
|
9
9
|
}
|
10
10
|
|
11
|
-
var cacheBuster = Math.random() * 10000 | 0;
|
12
|
-
|
13
11
|
global.MessageBus.ajax = function(options){
|
14
12
|
var XHRImpl = (global.MessageBus && global.MessageBus.xhrImplementation) || global.XMLHttpRequest;
|
15
13
|
var xhr = new XHRImpl();
|
16
14
|
xhr.dataType = options.dataType;
|
17
|
-
|
18
|
-
if (!options.cache){
|
19
|
-
url += ((-1 == url.indexOf('?')) ? '?' : '&') + '_=' + (cacheBuster++)
|
20
|
-
}
|
21
|
-
xhr.open('POST', url);
|
15
|
+
xhr.open('POST', options.url);
|
22
16
|
for (var name in options.headers){
|
23
17
|
xhr.setRequestHeader(name, options.headers[name]);
|
24
18
|
}
|
25
|
-
xhr.setRequestHeader('Content-Type', 'application/
|
19
|
+
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
26
20
|
if (options.messageBus.chunked){
|
27
21
|
options.messageBus.onProgressListener(xhr);
|
28
22
|
}
|
@@ -37,7 +31,7 @@
|
|
37
31
|
options.complete();
|
38
32
|
}
|
39
33
|
}
|
40
|
-
xhr.send(
|
34
|
+
xhr.send(new URLSearchParams(options.data).toString());
|
41
35
|
return xhr;
|
42
36
|
};
|
43
37
|
|