@fastify/reply-from 9.1.0 → 9.2.0

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.
package/README.md CHANGED
@@ -246,9 +246,9 @@ fastify.register(FastifyReplyFrom, {
246
246
 
247
247
  ---
248
248
 
249
- #### `destoryAgent`
249
+ #### `destroyAgent`
250
250
 
251
- If set to `true`, it will destory all agents when the Fastify is closed.
251
+ If set to `true`, it will destroy all agents when the Fastify is closed.
252
252
  If set to `false`, it will not destroy the agents.
253
253
 
254
254
  By Default: `false`
package/lib/utils.js CHANGED
@@ -57,6 +57,12 @@ function stripHttp1ConnectionHeaders (headers) {
57
57
  // issue ref: https://github.com/fastify/fast-proxy/issues/42
58
58
  function buildURL (source, reqBase) {
59
59
  let baseOrigin = reqBase ? new URL(reqBase).href : undefined
60
+
61
+ // To make sure we don't accidentally override the base path
62
+ if (baseOrigin && source.length > 1 && source[0] === '/' && source[1] === '/') {
63
+ source = '.' + source
64
+ }
65
+
60
66
  const dest = new URL(source, reqBase)
61
67
 
62
68
  // if base is specified, source url should not override it
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastify/reply-from",
3
- "version": "9.1.0",
3
+ "version": "9.2.0",
4
4
  "description": "forward your HTTP request to another server, for fastify",
5
5
  "main": "index.js",
6
6
  "types": "types/index.d.ts",
@@ -42,12 +42,19 @@ test('should handle default port in base', (t) => {
42
42
  t.equal(url.href, 'https://localhost/hi')
43
43
  })
44
44
 
45
+ test('should append instead of override base', (t) => {
46
+ t.plan(2)
47
+ let url = buildURL('//10.0.0.10/hi', 'http://localhost')
48
+ t.equal(url.href, 'http://localhost//10.0.0.10/hi')
49
+
50
+ url = buildURL('//httpbin.org/hi', 'http://localhost')
51
+ t.equal(url.href, 'http://localhost//httpbin.org/hi')
52
+ })
53
+
45
54
  const errorInputs = [
46
- { source: '//10.0.0.10/hi', base: 'http://localhost' },
47
55
  { source: 'http://10.0.0.10/hi', base: 'http://localhost' },
48
56
  { source: 'https://10.0.0.10/hi', base: 'http://localhost' },
49
57
  { source: 'blah://10.0.0.10/hi', base: 'http://localhost' },
50
- { source: '//httpbin.org/hi', base: 'http://localhost' },
51
58
  { source: 'urn:foo:bar', base: 'http://localhost' },
52
59
  { source: 'http://localhost/private', base: 'http://localhost/exposed/' },
53
60
  { source: 'http://localhost/exposed-extra', base: 'http://localhost/exposed' },