Skip to content

Commit

Permalink
Refactor download method using SkipResponseBodyEncodeDecode
Browse files Browse the repository at this point in the history
  • Loading branch information
sevein committed Jul 7, 2023
1 parent e912d5e commit de217eb
Show file tree
Hide file tree
Showing 19 changed files with 462 additions and 509 deletions.
3 changes: 1 addition & 2 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ func HTTPServer(
var collectionEndpoints *collection.Endpoints = collection.NewEndpoints(colsvc.Goa())
collectionErrorHandler := errorHandler(logger, "Collection error.")
var collectionServer *collectionsvr.Server = collectionsvr.New(collectionEndpoints, mux, dec, enc, collectionErrorHandler, nil, websocketUpgrader, nil)
// Intercept request in Download endpoint so we can serve the file directly.
collectionServer.Download = writeTimeout(colsvc.HTTPDownload(mux, dec), 0)
collectionServer.Download = writeTimeout(collectionServer.Download, 0)
collectionsvr.Mount(mux, collectionServer)

// Swagger service.
Expand Down
14 changes: 12 additions & 2 deletions internal/api/design/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,21 @@ var _ = Service("collection", func() {
Attribute("id", UInt, "Identifier of collection to look up")
Required("id")
})
Result(Bytes)
Result(func() {
Attribute("content_type", String)
Attribute("content_length", Int64)
Attribute("content_disposition", String)
Required("content_type", "content_length", "content_disposition")
})
Error("not_found", CollectionNotFound, "Collection not found")
HTTP(func() {
GET("/{id}/download")
Response(StatusOK)
SkipResponseBodyEncodeDecode()
Response(func() {
Header("content_type:Content-Type")
Header("content_length:Content-Length")
Header("content_disposition:Content-Disposition")
})
Response("not_found", StatusNotFound)
})
})
Expand Down
6 changes: 4 additions & 2 deletions internal/api/gen/collection/client.go

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

16 changes: 15 additions & 1 deletion internal/api/gen/collection/endpoints.go

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

10 changes: 9 additions & 1 deletion internal/api/gen/collection/service.go

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

20 changes: 10 additions & 10 deletions internal/api/gen/http/cli/enduro/cli.go

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

4 changes: 2 additions & 2 deletions internal/api/gen/http/collection/client/cli.go

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

8 changes: 7 additions & 1 deletion internal/api/gen/http/collection/client/client.go

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

37 changes: 30 additions & 7 deletions internal/api/gen/http/collection/client/encode_decode.go

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

11 changes: 11 additions & 0 deletions internal/api/gen/http/collection/client/types.go

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

13 changes: 9 additions & 4 deletions internal/api/gen/http/collection/server/encode_decode.go

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

11 changes: 10 additions & 1 deletion internal/api/gen/http/collection/server/server.go

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

2 changes: 1 addition & 1 deletion internal/api/gen/http/openapi.json

Large diffs are not rendered by default.

Loading

0 comments on commit de217eb

Please sign in to comment.