Skip to content

Commit

Permalink
Merge branch 'master' into 342-Get-Instead-Of-Post-For-Single-Component
Browse files Browse the repository at this point in the history
  • Loading branch information
matteofigus authored Jan 17, 2017
2 parents 05a49df + f6b6926 commit 67bbebe
Show file tree
Hide file tree
Showing 24 changed files with 457 additions and 32 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## Change Log

### v0.33.31
- [#343](https://github.com/opentable/oc/pull/343) 333 - Implement customHeadersToSkipOnWeakVersion functionality
- [#349](https://github.com/opentable/oc/pull/349) Upgrade minimal-request
- [#348](https://github.com/opentable/oc/pull/348) [acceptance/registry] remove .only
- [#344](https://github.com/opentable/oc/pull/344) Package server script cleanup

### v0.33.30
- [#335](https://github.com/opentable/oc/pull/335) Add endpoint for getting list of components with their versions (#324)

Expand Down
4 changes: 2 additions & 2 deletions client/src/oc-client.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oc",
"version": "0.33.30",
"version": "0.33.31",
"description": "A framework for developing and distributing html components",
"main": "./src/index.js",
"bin": {
Expand Down
6 changes: 3 additions & 3 deletions src/components/oc-client/_package/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "oc-client",
"description": "The OpenComponents client-side javascript client",
"version": "0.33.30",
"version": "0.33.31",
"repository": "https://github.com/opentable/oc/tree/master/components/oc-client",
"author": "Matteo Figus <matteofigus@gmail.com>",
"oc": {
Expand All @@ -24,8 +24,8 @@
"src": "server.js"
}
},
"version": "0.33.30",
"version": "0.33.31",
"packaged": true,
"date": 1483464654178
"date": 1484679018714
}
}
4 changes: 2 additions & 2 deletions src/components/oc-client/_package/src/oc-client.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/components/oc-client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "oc-client",
"description": "The OpenComponents client-side javascript client",
"version": "0.33.30",
"version": "0.33.31",
"repository": "https://github.com/opentable/oc/tree/master/components/oc-client",
"author": "Matteo Figus <matteofigus@gmail.com>",
"oc": {
Expand Down
4 changes: 2 additions & 2 deletions src/components/oc-client/src/oc-client.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/registry/domain/options-sanitiser.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ module.exports = function(input){
options.verbosity = 0;
}

options.customHeadersToSkipOnWeakVersion = (options.customHeadersToSkipOnWeakVersion || [])
.map(function(s) { return s.toLowerCase(); });

options.port = process.env.PORT || options.port;

return options;
Expand Down
14 changes: 14 additions & 0 deletions src/registry/domain/validators/registry-configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,19 @@ module.exports = function(conf){
}
}

if (conf.customHeadersToSkipOnWeakVersion) {
if (!_.isArray(conf.customHeadersToSkipOnWeakVersion)) {
return returnError(strings.errors.registry.CONFIGURATION_HEADERS_TO_SKIP_MUST_BE_STRING_ARRAY);
}

var hasNonStringElements = conf.customHeadersToSkipOnWeakVersion.find(function(element) {
return typeof(element) !== 'string';
});

if (hasNonStringElements) {
return returnError(strings.errors.registry.CONFIGURATION_HEADERS_TO_SKIP_MUST_BE_STRING_ARRAY);
}
}

return response;
};
7 changes: 6 additions & 1 deletion src/registry/routes/component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var GetComponentHelper = require('./helpers/get-component');
var _ = require('underscore');

module.exports = function(conf, repository){

Expand All @@ -19,8 +20,12 @@ module.exports = function(conf, repository){
res.errorDetails = result.response.error;
}

if (result.response.headers) {
if (!_.isEmpty(result.response.headers)) {
res.set(result.response.headers);

if (req.method === 'GET') {
delete result.response.headers;
}
}

return res.json(result.status, result.response);
Expand Down
31 changes: 25 additions & 6 deletions src/registry/routes/helpers/get-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ module.exports = function(conf, repository){
});
}

var filterCustomHeaders = function(headers, requestedVersion, actualVersion) {
if (!_.isEmpty(headers) &&
!_.isEmpty(conf.customHeadersToSkipOnWeakVersion) &&
requestedVersion !== actualVersion)
{
headers = _.omit(headers, conf.customHeadersToSkipOnWeakVersion);
}
return headers;
};

var returnComponent = function(err, data){

if(componentCallbackDone){ return; }
Expand Down Expand Up @@ -162,6 +172,13 @@ module.exports = function(conf, repository){
renderMode: renderMode
});

if (responseHeaders) {
responseHeaders = filterCustomHeaders(responseHeaders, requestedComponent.version, component.version);
if (!_.isEmpty(responseHeaders)) {
response.headers = responseHeaders;
}
}

if (isUnrendered) {
callback({
status: 200,
Expand Down Expand Up @@ -202,10 +219,6 @@ module.exports = function(conf, repository){
});
}

if (responseHeaders) {
response.headers = responseHeaders;
}

callback({
status: 200,
response: _.extend(response, { html: html })
Expand Down Expand Up @@ -245,8 +258,14 @@ module.exports = function(conf, repository){
requestHeaders: options.headers,
staticPath: repository.getStaticFilePath(component.name, component.version, '').replace('https:', ''),
setHeader: function(header, value) {
responseHeaders = responseHeaders || {};
responseHeaders[header] = value;
if (!(typeof(header) === 'string' && typeof(value) === 'string')) {
throw strings.errors.registry.COMPONENT_SET_HEADER_PARAMETERS_NOT_VALID;
}

if (header && value) {
responseHeaders = responseHeaders || {};
responseHeaders[header.toLowerCase()] = value;
}
}
};

Expand Down
2 changes: 2 additions & 0 deletions src/resources/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = {
COMPONENT_VERSION_ALREADY_FOUND_CODE: 'already_exists',
COMPONENT_VERSION_NOT_VALID: 'Version "{0}" is not a valid semantic version.',
COMPONENT_VERSION_NOT_VALID_CODE: 'version_not_valid',
COMPONENT_SET_HEADER_PARAMETERS_NOT_VALID: 'context.setHeader parameters must be strings',
CONFIGURATION_DEPENDENCIES_MUST_BE_ARRAY: 'Registry configuration is not valid: dependencies must be an array',
CONFIGURATION_EMPTY: 'Registry configuration is empty',
CONFIGURATION_ONREQUEST_MUST_BE_FUNCTION: 'Registry configuration is not valid: registry.on\'s callback must be a function',
Expand All @@ -37,6 +38,7 @@ module.exports = {
CONFIGURATION_ROUTES_NOT_VALID: 'Registry configuration is not valid: each route should contain route, method and handler',
CONFIGURATION_ROUTES_MUST_BE_ARRAY: 'Registry configuration is not valid: routes must be an array',
CONFIGURATION_S3_NOT_VALID: 'Registry configuration is not valid: S3 configuration is not valid',
CONFIGURATION_HEADERS_TO_SKIP_MUST_BE_STRING_ARRAY: 'Registry configuration is not valid: customHeadersToSkipOnWeakVersion must be an array of strings',
DATA_OBJECT_IS_UNDEFINED: 'data object is undefined',
DEPENDENCY_NOT_FOUND: 'Component is trying to use unavailable dependencies: {0}',
DEPENDENCY_NOT_FOUND_CODE: 'DEPENDENCY_MISSING_FROM_REGISTRY',
Expand Down
Loading

0 comments on commit 67bbebe

Please sign in to comment.