Skip to content

Commit

Permalink
Fix: Service responses are not compressed (#6360)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsotirho-ucsc committed Jul 17, 2024
1 parent e4eaade commit 771dba5
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
1 change: 0 additions & 1 deletion lambdas/indexer/.chalice/config.json.template.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"manage_iam_role": False,
"iam_role_arn": "${aws_iam_role.%s.arn}" % app_name,
"environment_variables": config.lambda_env,
"minimum_compression_size": config.minimum_compression_size,
"lambda_timeout": config.api_gateway_lambda_timeout,
"lambda_memory_size": 128,
**chalice.vpc_lambda_config(app_name),
Expand Down
1 change: 1 addition & 0 deletions lambdas/indexer/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"description": "\nThis is the internal API for Azul's indexer component.\n",
"version": "1.0"
},
"x-amazon-apigateway-minimum-compression-size": 1024,
"paths": {
"/openapi": {
"get": {
Expand Down
1 change: 0 additions & 1 deletion lambdas/service/.chalice/config.json.template.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"manage_iam_role": False,
"iam_role_arn": "${aws_iam_role.%s.arn}" % app_name,
"environment_variables": config.lambda_env,
"minimum_compression_size": config.minimum_compression_size,
"lambda_timeout": config.api_gateway_lambda_timeout,
"lambda_memory_size": 2048,
**chalice.vpc_lambda_config(app_name),
Expand Down
1 change: 1 addition & 0 deletions lambdas/service/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"description": "\nDescribes various aspects of the Azul service\n"
}
],
"x-amazon-apigateway-minimum-compression-size": 1024,
"paths": {
"/openapi": {
"get": {
Expand Down
1 change: 1 addition & 0 deletions src/azul/chalice.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def __init__(self,
self.non_interactive_routes: set[tuple[str, str]] = set()
if spec is not None:
assert 'paths' not in spec, 'The top-level spec must not define paths'
spec['x-amazon-apigateway-minimum-compression-size'] = config.minimum_compression_size
self._specs: Optional[MutableJSON] = copy_json(spec)
self._specs['paths'] = {}
else:
Expand Down
23 changes: 17 additions & 6 deletions test/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,16 @@ def app(self, spec):
return AzulChaliceApp('testing', '/app.py', spec=spec)

def test_top_level_spec(self):
spec = {'foo': 'bar'}
spec = {
'foo': 'bar',
'x-amazon-apigateway-minimum-compression-size': 1024
}
app = self.app(spec)
self.assertEqual(app._specs, {'foo': 'bar', 'paths': {}}, "Confirm 'paths' is added")
self.assertEqual(app._specs, {
'foo': 'bar',
'x-amazon-apigateway-minimum-compression-size': 1024,
'paths': {}
}, "Confirm 'paths' is added")
spec['new key'] = 'new value'
self.assertNotIn('new key', app.spec(), 'Changing input object should not affect specs')

Expand All @@ -54,7 +61,8 @@ def route():
'foo': 'bar',
'paths': {},
'tags': [],
'servers': [{'url': 'https://fake.url/'}]
'servers': [{'url': 'https://fake.url/'}],
'x-amazon-apigateway-minimum-compression-size': 1024
}
self.assertEqual(app.spec(), expected)

Expand All @@ -74,7 +82,8 @@ def route():
}
},
'tags': [],
'servers': [{'url': 'https://fake.url/'}]
'servers': [{'url': 'https://fake.url/'}],
'x-amazon-apigateway-minimum-compression-size': 1024
}
self.assertEqual(app.spec(), expected_spec)

Expand All @@ -91,7 +100,8 @@ def route():
'/foo': {'a': 'b'}
},
'tags': [],
'servers': [{'url': 'https://fake.url/'}]
'servers': [{'url': 'https://fake.url/'}],
'x-amazon-apigateway-minimum-compression-size': 1024
}
self.assertEqual(app.spec(), expected_spec)

Expand Down Expand Up @@ -130,7 +140,8 @@ def route():
}
},
'tags': [],
'servers': [{'url': 'https://fake.url/'}]
'servers': [{'url': 'https://fake.url/'}],
'x-amazon-apigateway-minimum-compression-size': 1024
}
self.assertEqual(app.spec(), expected_specs)

Expand Down

0 comments on commit 771dba5

Please sign in to comment.