Skip to content

Commit df81b3d

Browse files
authored
Merge pull request #193 from michal1106/master
Add support for 206 response with its relevant headers + add Accept-R…
2 parents 426eb01 + faf3f16 commit df81b3d

File tree

5 files changed

+305
-26
lines changed

5 files changed

+305
-26
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This Serverless Framework plugin supports the AWS service proxy integration feat
2323
- [Customize the Path Override in API Gateway](#customize-the-path-override-in-api-gateway)
2424
- [Can use greedy, for deeper Folders](#can-use-greedy--for-deeper-folders)
2525
- [Customizing responses](#customizing-responses-1)
26+
- [Allow Bindary Types](#allow-binary-type)
2627
- [SNS](#sns)
2728
- [Customizing responses](#customizing-responses-2)
2829
- [DynamoDB](#dynamodb)
@@ -403,7 +404,18 @@ custom:
403404
serverError: |-
404405
{ "message": "there was an error handling your request" }
405406
```
407+
#### Allow Binary Type
406408
409+
In order to allow the browser to recognize binary type (e.g. images), add the following.
410+
411+
This would impact Rest API [settings](https://github.com/serverless/serverless/blob/main/lib/plugins/aws/package/compile/events/api-gateway/lib/rest-api.js#8,21) which is [called](https://github.com/serverless-operations/serverless-apigateway-service-proxy/blob/9f41894cd2e458263d3128116aa6af19ec2b333b/lib/index.js#7,81) by our plugin
412+
413+
```yml
414+
#provider.apiGateway.binaryMediaTypes
415+
provider:
416+
apiGateway:
417+
binaryMediaTypes: "*/*"
418+
```
407419
### SNS
408420
409421
Sample syntax for SNS proxy in `serverless.yml`.

lib/apiGateway/methods.js

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ module.exports = {
2424
}
2525
}
2626

27+
if (http && http.partialContent) {
28+
methodResponse.Properties.MethodResponses.push({
29+
ResponseParameters: {},
30+
ResponseModels: {},
31+
StatusCode: 206
32+
})
33+
}
34+
2735
if (http && http.cors) {
2836
let origin = http.cors.origin
2937
if (http.cors.origins && http.cors.origins.length) {

lib/package/s3/compileMethodsToS3.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222
RestApiId: this.provider.getApiGatewayRestApiId()
2323
}
2424
}
25-
25+
event.http.partialContent = true
2626
_.merge(
2727
template,
2828
this.getS3MethodIntegration(event.http),
@@ -88,7 +88,9 @@ module.exports = {
8888
getIntegrationRequestParameters(http) {
8989
switch (http.action) {
9090
case 'GetObject':
91-
return {}
91+
return {
92+
'integration.request.header.Range': 'method.request.header.Range'
93+
}
9294
case 'PutObject':
9395
return {
9496
'integration.request.header.x-amz-acl': "'authenticated-read'",
@@ -104,7 +106,11 @@ module.exports = {
104106
case 'GetObject':
105107
return {
106108
'method.response.header.content-type': 'integration.response.header.content-type',
107-
'method.response.header.Content-Type': 'integration.response.header.Content-Type'
109+
'method.response.header.Content-Type': 'integration.response.header.Content-Type',
110+
'method.response.header.accept-ranges': 'integration.response.header.accept-ranges',
111+
'method.response.header.Accept-Ranges': 'integration.response.header.Accept-Ranges',
112+
'method.response.header.content-range': 'integration.response.header.content-range',
113+
'method.response.header.Content-Range': 'integration.response.header.Content-Range'
108114
}
109115
case 'PutObject':
110116
return {
@@ -187,7 +193,13 @@ module.exports = {
187193
},
188194
{
189195
StatusCode: 200,
190-
SelectionPattern: '2\\d{2}',
196+
SelectionPattern: '2(?!06)\\d{2}',
197+
ResponseParameters: responseParams,
198+
ResponseTemplates: this.getS3IntegrationResponseTemplate(http, 'success')
199+
},
200+
{
201+
StatusCode: 206,
202+
SelectionPattern: '206',
191203
ResponseParameters: responseParams,
192204
ResponseTemplates: this.getS3IntegrationResponseTemplate(http, 'success')
193205
}

0 commit comments

Comments
 (0)