Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(common): extend streamable-file header support #9240

Merged
merged 2 commits into from
Mar 1, 2022

Conversation

davidschuette
Copy link
Contributor

@davidschuette davidschuette commented Feb 21, 2022

Provide option to specify additional headers when using StreamableFile.
No need to access the native response option.

BREAKING CHANGE: not specifying content-disposition header and
StreamableFile option disposition would send header value 'null'
instead of not sending the header at all.
This changes to not sending the header if no value is specified.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #9229

What is the new behavior?

More headers can be specified when using the StreamableFile class without needing to access the native response object.

Does this PR introduce a breaking change?

  • Yes
  • No

BREAKING CHANGE: not specifying content-disposition header and
StreamableFile option disposition would send header value 'null'
instead of not sending the header at all.
This changes to not sending the header if no value is specified.

Other information

Provide option to specify additional headers when using StreamableFile.
No need to access the native response option.

BREAKING CHANGE: not specifying content-disposition header and
StreamableFile option disposition would send header value 'null'
instead of not sending the header at all.
This changes to not sending the header if no value is specified.
This commit closes issue nestjs#9229.
@coveralls
Copy link

coveralls commented Feb 21, 2022

Pull Request Test Coverage Report for Build c59e21a2-4a17-496f-a5c6-8c268288f992

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 94.189%

Totals Coverage Status
Change from base Build 82baa335-ce7d-43f6-a7cd-d81418408f3d: 0.03%
Covered Lines: 5722
Relevant Lines: 6075

💛 - Coveralls

@micalevisk
Copy link
Member

any chance to make this feat backwards compatible? 👀

@davidschuette
Copy link
Contributor Author

any chance to make this feat backwards compatible? eyes

The (potentially) breaking change is more of a bug fix in my opinion, as I don't think sending 'null' as header value is a good practice. The rest of the changes is backwards compatible.
image

@davidschuette
Copy link
Contributor Author

I found another problem with the current implementation of the StreamableFile. Returning a StreamableFile object when using the @Res() decorator in the specifiy controller function results in a timeout.
I have created a branch of my repo to show the problem.
The route /:id works fine (although the headers are missing for this demo), but /:id/broken times out. The only difference is the reference to the response object.

@ApiOperation({ summary: 'Download a file.' })
@Get(':id')
downloadFile(
  @Param('id') id: string,
  @Req() request: Request,
  // @Res() response: Response,
) {
  return this.appService.download(id, request)
}

@ApiOperation({ summary: 'Download a file.' })
@Get(':id/broken')
downloadFileBroken(
  @Param('id') id: string,
  @Req() request: Request,
  @Res() response: Response,
) {
  return this.appService.download(id, request)
}

As a result using the response object to define headers and the StreamableFile class for the stream is not an option.

@kamilmysliwiec
Copy link
Member

Returning a StreamableFile object when using the @res() decorator in the specifiy controller function results in a timeout.

This is the expected behavior.

As a result using the response object to define headers and the StreamableFile class for the stream is not an option.

You shouldn't use both at the same time.

@davidschuette
Copy link
Contributor Author

The (potentially) breaking change is more of a bug fix in my opinion, as I don't think sending 'null' as header value is a good practice. The rest of the changes is backwards compatible.
image

@kamilmysliwiec Do you have an opinion on that "problem"?

@davidschuette
Copy link
Contributor Author

This is the expected behavior.

Ok.

You shouldn't use both at the same time.

I just looked it up again and tried with passthrough: true and it works.

Provide option to specify content-length headers when using StreamableFile.
No need to access the native response object.

BREAKING CHANGE: not specifying content-disposition header and
StreamableFile option disposition would send header value 'null'
instead of not sending the header at all.
This changes to not sending the header if no value is specified.
This commit closes issue nestjs#9229.
Copy link
Member

@jmcdo29 jmcdo29 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good. If anyone wants to add additional headers to the response, from here they can use the @Res({ passthrough: true }) approach to get access to the response object and its headers

@kamilmysliwiec
Copy link
Member

LGTM

@davidschuette davidschuette deleted the streamable-file-update branch March 6, 2022 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants