requestjs-rails 0.0.8 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24f3702ff02a882e27c6694c7ecdcb908055ff75fcc636f3e429192a17dbc80b
4
- data.tar.gz: a89e1130d35dcd74bc9f4b3317e6a6fb0ce3ca28861d46700e818dce82e9b709
3
+ metadata.gz: 3cfa027194b10b71958ba06f76e28d181ab6df698cbe26afd29295aec86146b5
4
+ data.tar.gz: 757283047d0579f8e32f8556b90e2b4e24bcda160590cd8de677ba64eb26e88e
5
5
  SHA512:
6
- metadata.gz: e004986d5fc3a2bcc3196ad690a9f1a776ccba8fda8b8648d5c9cffe1456bf47e9baf53d414e7f55d59115a71a318014bba7c091d48d9158d814695b4458c67b
7
- data.tar.gz: 6e38b179684ed39ac51084f981f532b632ea8f976ed4272ab00699cc5c3948d8377fa56bb18d48b71fd1305172e5eb55d4d75a309e7a043b6cf3750782a18056
6
+ metadata.gz: 9c12ab260f0c0a403c2c2666e35386f72c7637e5c33d71a312bf335ad02c90a261b544b211c3b30bdf06ba19fed84a458e77ac8cadb165482d4e44f7bc03b0fa
7
+ data.tar.gz: c0c5a9d7c6cb5963626672fe2866112fce7a75e11c6baf4edb942d27ff507a23499fda5d3d2f553d942b417ba65ab047ccebac449fbb8357110313de37ed8f54
@@ -105,7 +105,7 @@ function stringEntriesFromFormData(formData) {
105
105
  function mergeEntries(searchParams, entries) {
106
106
  for (const [name, value] of entries) {
107
107
  if (value instanceof window.File) continue;
108
- if (searchParams.has(name)) {
108
+ if (searchParams.has(name) && !name.includes("[]")) {
109
109
  searchParams.delete(name);
110
110
  searchParams.set(name, value);
111
111
  } else {
@@ -143,6 +143,16 @@ class FetchRequest {
143
143
  headers[key] = value;
144
144
  this.options.headers = headers;
145
145
  }
146
+ sameHostname() {
147
+ if (!this.originalUrl.startsWith("http:")) {
148
+ return true;
149
+ }
150
+ try {
151
+ return new URL(this.originalUrl).hostname === window.location.hostname;
152
+ } catch (_) {
153
+ return true;
154
+ }
155
+ }
146
156
  get fetchOptions() {
147
157
  return {
148
158
  method: this.method.toUpperCase(),
@@ -154,12 +164,15 @@ class FetchRequest {
154
164
  };
155
165
  }
156
166
  get headers() {
157
- return compact(Object.assign({
167
+ const baseHeaders = {
158
168
  "X-Requested-With": "XMLHttpRequest",
159
- "X-CSRF-Token": this.csrfToken,
160
169
  "Content-Type": this.contentType,
161
170
  Accept: this.accept
162
- }, this.additionalHeaders));
171
+ };
172
+ if (this.sameHostname()) {
173
+ baseHeaders["X-CSRF-Token"] = this.csrfToken;
174
+ }
175
+ return compact(Object.assign(baseHeaders, this.additionalHeaders));
163
176
  }
164
177
  get csrfToken() {
165
178
  return getCookie(metaContent("csrf-param")) || metaContent("csrf-token");
@@ -7,7 +7,9 @@ module Requestjs
7
7
  end
8
8
 
9
9
  initializer "requestjs.importmap", before: "importmap" do |app|
10
- app.config.importmap.paths << Engine.root.join("config/importmap.rb")
10
+ if Rails.application.respond_to?(:importmap)
11
+ app.config.importmap.paths << Engine.root.join("config/importmap.rb")
12
+ end
11
13
  end
12
14
  end
13
15
  end
@@ -1,3 +1,3 @@
1
1
  module Requestjs
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.10"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: requestjs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Lauxen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-04 00:00:00.000000000 Z
11
+ date: 2022-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubygems_version: 3.2.19
64
+ rubygems_version: 3.1.6
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: A tiny Fetch API wrapper that allows you to make http requests without need