Skip to content

Commit

Permalink
fix(conditions): use url.parse directly
Browse files Browse the repository at this point in the history
  • Loading branch information
dominique-pfister committed Feb 25, 2020
1 parent 2556169 commit 8a9bbe0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Condition.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

/* eslint-disable max-classes-per-file */
const url = require('url');
const { parse } = require('url');
const YAML = require('yaml');
const utils = require('./utils.js');

Expand Down Expand Up @@ -264,7 +264,7 @@ function urlPrefixCompose(name, value) {

function urlPrefixMatch(actual, value) {
if (actual === value || actual.startsWith(`${value}/`)) {
const baseURL = url.parse(value).path;
const baseURL = parse(value).path;
return baseURL !== '/' ? { baseURL } : true;
}
return false;
Expand All @@ -277,21 +277,21 @@ const propertyMap = {
url: {
vcl: 'req.http.X-Full-URL',
prefixCompose: (name, value) => {
const uri = url.parse(value);
const uri = parse(value);
if (uri.path === '/') {
// root path, no composition necessary
return `${name} ~ "^${value}"`;
}
return urlPrefixCompose(name, value);
},
getSubPath: (value) => {
const uri = url.parse(value);
const uri = parse(value);
if (uri.path !== '/') {
return uri.path;
}
return '';
},
evaluate: (req) => `${req.protocol}://${req.headers.host}${req.originalUrl}`,
evaluate: (req) => `${req.protocol}://${req.headers.host}${req.path}`,
prefixMatch: urlPrefixMatch,
type: 'string',
allowed_ops: '=~',
Expand Down Expand Up @@ -448,6 +448,8 @@ class Condition {
if (this._top && this._top.evaluate) {
req.headers = req.headers || {};
req.params = req.params || {};
req.protocol = req.protocol || 'http';
req.path = req.path || '/';

return this._top.evaluate(req);
}
Expand Down

0 comments on commit 8a9bbe0

Please sign in to comment.