Skip to content

Commit

Permalink
Merge pull request #193 from michal1106/master
Browse files Browse the repository at this point in the history
Add support for 206 response with its relevant headers + add Accept-R…
  • Loading branch information
lopburny authored Jan 12, 2023
2 parents 426eb01 + faf3f16 commit df81b3d
Show file tree
Hide file tree
Showing 5 changed files with 305 additions and 26 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This Serverless Framework plugin supports the AWS service proxy integration feat
- [Customize the Path Override in API Gateway](#customize-the-path-override-in-api-gateway)
- [Can use greedy, for deeper Folders](#can-use-greedy--for-deeper-folders)
- [Customizing responses](#customizing-responses-1)
- [Allow Bindary Types](#allow-binary-type)
- [SNS](#sns)
- [Customizing responses](#customizing-responses-2)
- [DynamoDB](#dynamodb)
Expand Down Expand Up @@ -403,7 +404,18 @@ custom:
serverError: |-
{ "message": "there was an error handling your request" }
```
#### Allow Binary Type
In order to allow the browser to recognize binary type (e.g. images), add the following.
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
```yml
#provider.apiGateway.binaryMediaTypes
provider:
apiGateway:
binaryMediaTypes: "*/*"
```
### SNS
Sample syntax for SNS proxy in `serverless.yml`.
Expand Down
8 changes: 8 additions & 0 deletions lib/apiGateway/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ module.exports = {
}
}

if (http && http.partialContent) {
methodResponse.Properties.MethodResponses.push({
ResponseParameters: {},
ResponseModels: {},
StatusCode: 206
})
}

if (http && http.cors) {
let origin = http.cors.origin
if (http.cors.origins && http.cors.origins.length) {
Expand Down
20 changes: 16 additions & 4 deletions lib/package/s3/compileMethodsToS3.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
RestApiId: this.provider.getApiGatewayRestApiId()
}
}

event.http.partialContent = true
_.merge(
template,
this.getS3MethodIntegration(event.http),
Expand Down Expand Up @@ -88,7 +88,9 @@ module.exports = {
getIntegrationRequestParameters(http) {
switch (http.action) {
case 'GetObject':
return {}
return {
'integration.request.header.Range': 'method.request.header.Range'
}
case 'PutObject':
return {
'integration.request.header.x-amz-acl': "'authenticated-read'",
Expand All @@ -104,7 +106,11 @@ module.exports = {
case 'GetObject':
return {
'method.response.header.content-type': 'integration.response.header.content-type',
'method.response.header.Content-Type': 'integration.response.header.Content-Type'
'method.response.header.Content-Type': 'integration.response.header.Content-Type',
'method.response.header.accept-ranges': 'integration.response.header.accept-ranges',
'method.response.header.Accept-Ranges': 'integration.response.header.Accept-Ranges',
'method.response.header.content-range': 'integration.response.header.content-range',
'method.response.header.Content-Range': 'integration.response.header.Content-Range'
}
case 'PutObject':
return {
Expand Down Expand Up @@ -187,7 +193,13 @@ module.exports = {
},
{
StatusCode: 200,
SelectionPattern: '2\\d{2}',
SelectionPattern: '2(?!06)\\d{2}',
ResponseParameters: responseParams,
ResponseTemplates: this.getS3IntegrationResponseTemplate(http, 'success')
},
{
StatusCode: 206,
SelectionPattern: '206',
ResponseParameters: responseParams,
ResponseTemplates: this.getS3IntegrationResponseTemplate(http, 'success')
}
Expand Down
Loading

0 comments on commit df81b3d

Please sign in to comment.