angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.77k stars 11.97k forks source link

Angular 13 sending application/octet-stream MIME type for unknown files #22091

Closed acalvo closed 2 years ago

acalvo commented 2 years ago

🐞 Bug report

Command (mark with an x)

Is this a regression?

Yes, the previous version in which this bug was not present was: 12.x ### Description Until now, a file without extension was served by Angular in dev mode (`ng serve`) with the `; charset=UTF8` `Content-Type` header, which enabled the MIME type sniffing making the browser treat it correctly. With Angular 13 the header changed to `application/octet-stream` which made the browser try to download it. We set the appropriate headers to file in production, but this can't be done in the dev server as long as I know, so we relied in MIME type sniffing for dev mode until now. ## 🔬 Minimal Reproduction Create any asset without extension (for example a simple html file without extension), run `ng serve` and navigate to that URL. In Angular12 it'll be displayed, in Angular13 the browser will ask to download it. ## 🔥 Exception or Error - ## 🌍 Your Environment

Angular CLI: 13.0.1
Node: 14.17.1
Package Manager: npm 7.24.1
OS: darwin x64
Angular: 13.0.0
... animations, cdk, common, compiler, compiler-cli, core, forms
... language-service, localize, material, platform-browser
... platform-browser-dynamic, router, service-worker
Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1202.7
@angular-devkit/build-angular   13.0.1
@angular-devkit/core            12.2.7
@angular-devkit/schematics      13.0.1
@angular/cli                    13.0.1
@schematics/angular             13.0.1
rxjs                            6.6.7
typescript                      4.4.4
**Anything else relevant?**
alan-agius4 commented 2 years ago

Hi @acalvo,

Using application/octet-stream in this case seems to be the correct behaviour for files without extensions, especially considering the webpack-dev-server uses Express engine under the hood. Related test in webpack-dev-middleware.

This also aligns with the spec found in https://tools.ietf.org/html/rfc2045

Any entity with an unrecognized Content-Transfer-Encoding must be treated as if it has a Content-Type of "application/octet-stream", regardless of what the Content-Type header field actually says.

Files without extensions are also handled different from one server engine to another, there is a good comparison here. I therefore don't recommand using a file without extension.

alan-agius4 commented 2 years ago

Closing as this seems to be working as design by Express engine.

angular-automatic-lock-bot[bot] commented 2 years ago

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.