Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
14b1d69b
Commit
14b1d69b
authored
Jan 24, 2017
by
Regis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use gl.utils.normalizeHeaders in pipelines store
parent
30d5e9fa
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
11 deletions
+38
-11
app/assets/javascripts/lib/utils/common_utils.js.es6
app/assets/javascripts/lib/utils/common_utils.js.es6
+14
-0
app/assets/javascripts/vue_pipelines_index/store.js.es6
app/assets/javascripts/vue_pipelines_index/store.js.es6
+7
-11
spec/javascripts/lib/utils/common_utils_spec.js.es6
spec/javascripts/lib/utils/common_utils_spec.js.es6
+17
-0
No files found.
app/assets/javascripts/lib/utils/common_utils.js.es6
View file @
14b1d69b
...
@@ -159,5 +159,19 @@
...
@@ -159,5 +159,19 @@
if (!results[2]) return '';
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
return decodeURIComponent(results[2].replace(/\+/g, ' '));
};
};
/**
this will take in the headers from an API response and normalize them
this way we don't run into production issues when nginx gives us lowercased header keys
*/
w.gl.utils.normalizeHeaders = (headers) => {
const upperCaseHeaders = {};
Object.keys(headers).forEach((e) => {
upperCaseHeaders[e.toUpperCase()] = headers[e];
});
return upperCaseHeaders;
};
})(window);
})(window);
}).call(this);
}).call(this);
app/assets/javascripts/vue_pipelines_index/store.js.es6
View file @
14b1d69b
...
@@ -4,19 +4,15 @@
...
@@ -4,19 +4,15 @@
((gl) => {
((gl) => {
const pageValues = (headers) => {
const pageValues = (headers) => {
const normalizedHeaders = {};
const normalized = gl.utils.normalizeHeaders(headers);
Object.keys(headers).forEach((e) => {
normalizedHeaders[e.toUpperCase()] = headers[e];
});
const paginationInfo = {
const paginationInfo = {
perPage: +normalized
Headers
['X-PER-PAGE'],
perPage: +normalized['X-PER-PAGE'],
page: +normalized
Headers
['X-PAGE'],
page: +normalized['X-PAGE'],
total: +normalized
Headers
['X-TOTAL'],
total: +normalized['X-TOTAL'],
totalPages: +normalized
Headers
['X-TOTAL-PAGES'],
totalPages: +normalized['X-TOTAL-PAGES'],
nextPage: +normalized
Headers
['X-NEXT-PAGE'],
nextPage: +normalized['X-NEXT-PAGE'],
previousPage: +normalized
Headers
['X-PREV-PAGE'],
previousPage: +normalized['X-PREV-PAGE'],
};
};
return paginationInfo;
return paginationInfo;
...
...
spec/javascripts/lib/utils/common_utils_spec.js.es6
View file @
14b1d69b
...
@@ -52,5 +52,22 @@
...
@@ -52,5 +52,22 @@
expect(value).toBe(null);
expect(value).toBe(null);
});
});
});
});
describe('gl.utils.normalizedHeaders', () => {
it('should upperCase all the header keys to keep them consistent', () => {
const apiHeaders = {
'X-Something-Workhorse': { workhorse: 'ok' },
'x-something-nginx': { nginx: 'ok' },
};
const normalized = gl.utils.normalizeHeaders(apiHeaders);
const WORKHORSE = 'X-SOMETHING-WORKHORSE';
const NGINX = 'X-SOMETHING-NGINX';
expect(normalized[WORKHORSE].workhorse).toBe('ok');
expect(normalized[NGINX].nginx).toBe('ok');
});
});
});
});
})();
})();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment