Skip to content

SSG when generated index contains 0x0D characters server messes up content-length #29597

Closed as duplicate of#29567
@KonstantinasL

Description

@KonstantinasL

Which @angular/* package(s) are the source of the bug?

Don't known / other

Is this a regression?

No

Description

When using SSG (with server routes), if prerendered indexes contain 0x0D (CR - "carriage return") characters, the responses for these indexes contain wrong "Content-Length" headers, which causes the requests to remain "hanging" until the server times them out. As far as I can tell, AngularNodeAppEngine removes these "CR" characters from the response body but sets the "Content-Length" header to be the same as the original index.html file size (as if no modification was performed).

To reproduce the problem:

  1. Create a fresh Angular project with SSR and server routing;
  2. Run build;
  3. Go to the dist folder and add some CRs (or CRLFs) to index.html and index_html.mjs files;
  4. Run serve:ssr:[project-name];
  5. Make a request for a modified index.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

PS C:\Projects> curl http://localhost:4000


StatusCode        : 200
StatusDescription : OK
Content           : <!DOCTYPE html><html lang="en" data-beasties-container><head>
                      <meta charset="utf-8">
                      <title>IndexErrorDemo</title>
                      <base href="https://github.com/">
                      <meta name="viewport" content="width=device-width, initial-sc...
RawContent        : HTTP/1.1 200 OK
                    Connection: keep-alive
                    Keep-Alive: timeout=5
                    Content-Length: 20846
                    Content-Type: text/html;charset=UTF-8
                    Date: Mon, 10 Feb 2025 11:43:56 GMT
                    ETag: "536bee0b8da5b269d2e6bcd77f7d1d...
Forms             : {}
Headers           : {[Connection, keep-alive], [Keep-Alive, timeout=5], [Content-Length, 20846], [Content-Type, text/html;charset=UTF-8]...}
Images            : {}
InputFields       : {}
Links             : {@{innerHTML=<SPAN _ngcontent-ng-c245922056>Explore the Docs</SPAN><?XML:NAMESPACE PREFIX = "[default] http://www.w3.org/2000/svg" NS = "http://www.w3.org/2000/svg" /><svg _
                    ngcontent-ng-c245922056="" fill="currentColor" viewBox="0 -960 960 960" xmlns="http://www.w3.org/2000/svg" width="14" height="14"><path _ngcontent-ng-c245922056="" d="M200-1
                    20q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h280v80H200v560h560v-280h80v280q0 33-23.5 56.5T760-120H200Zm188-212-56-56 372-372H560v-80h280v280h-80v-144L388-332Z"></
                    path></svg>; innerText=Explore the Docs; outerHTML=<A class=pill href="https://angular.dev" rel=noopener target=_blank _ngcontent-ng-c245922056><SPAN _ngcontent-ng-c24592205
                    6>Explore the Docs</SPAN><?XML:NAMESPACE PREFIX = "[default] http://www.w3.org/2000/svg" NS = "http://www.w3.org/2000/svg" /><svg _ngcontent-ng-c245922056="" fill="currentCo
                    lor" viewBox="0 -960 960 960" xmlns="http://www.w3.org/2000/svg" width="14" height="14"><path _ngcontent-ng-c245922056="" d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-
                    56.5T200-840h280v80H200v560h560v-280h80v280q0 33-23.5 56.5T760-120H200Zm188-212-56-56 372-372H560v-80h280v280h-80v-144L388-332Z"></path></svg></A>; outerText=Explore the Doc
                    s; tagName=A; class=pill; href=https://angular.dev; rel=noopener; target=_blank; _ngcontent-ng-c245922056=}, @{innerHTML=<SPAN _ngcontent-ng-c245922056>Learn with Tutorials<
                    /SPAN><?XML:NAMESPACE PREFIX = "[default] http://www.w3.org/2000/svg" NS = "http://www.w3.org/2000/svg" /><svg _ngcontent-ng-c245922056="" fill="currentColor" viewBox="0 -96
                    0 960 960" xmlns="http://www.w3.org/2000/svg" width="14" height="14"><path _ngcontent-ng-c245922056="" d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h280v80
                    H200v560h560v-280h80v280q0 33-23.5 56.5T760-120H200Zm188-212-56-56 372-372H560v-80h280v280h-80v-144L388-332Z"></path></svg>; innerText=Learn with Tutorials; outerHTML=<A cla
                    ss=pill href="https://angular.dev/tutorials" rel=noopener target=_blank _ngcontent-ng-c245922056><SPAN _ngcontent-ng-c245922056>Learn with Tutorials</SPAN><?XML:NAMESPACE PR
                    EFIX = "[default] http://www.w3.org/2000/svg" NS = "http://www.w3.org/2000/svg" /><svg _ngcontent-ng-c245922056="" fill="currentColor" viewBox="0 -960 960 960" xmlns="http:/
                    /www.w3.org/2000/svg" width="14" height="14"><path _ngcontent-ng-c245922056="" d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h280v80H200v560h560v-280h80v280
                    q0 33-23.5 56.5T760-120H200Zm188-212-56-56 372-372H560v-80h280v280h-80v-144L388-332Z"></path></svg></A>; outerText=Learn with Tutorials; tagName=A; class=pill; href=https://
                    angular.dev/tutorials; rel=noopener; target=_blank; _ngcontent-ng-c245922056=}, @{innerHTML=<SPAN _ngcontent-ng-c245922056>CLI Docs</SPAN><?XML:NAMESPACE PREFIX = "[default]
                     http://www.w3.org/2000/svg" NS = "http://www.w3.org/2000/svg" /><svg _ngcontent-ng-c245922056="" fill="currentColor" viewBox="0 -960 960 960" xmlns="http://www.w3.org/2000/
                    svg" width="14" height="14"><path _ngcontent-ng-c245922056="" d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h280v80H200v560h560v-280h80v280q0 33-23.5 56.5T7
                    60-120H200Zm188-212-56-56 372-372H560v-80h280v280h-80v-144L388-332Z"></path></svg>; innerText=CLI Docs; outerHTML=<A class=pill href="https://angular.dev/tools/cli" rel=noop
                    ener target=_blank _ngcontent-ng-c245922056><SPAN _ngcontent-ng-c245922056>CLI Docs</SPAN><?XML:NAMESPACE PREFIX = "[default] http://www.w3.org/2000/svg" NS = "http://www.w3
                    .org/2000/svg" /><svg _ngcontent-ng-c245922056="" fill="currentColor" viewBox="0 -960 960 960" xmlns="http://www.w3.org/2000/svg" width="14" height="14"><path _ngcontent-ng-
                    c245922056="" d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h280v80H200v560h560v-280h80v280q0 33-23.5 56.5T760-120H200Zm188-212-56-56 372-372H560v-80h280v28
                    0h-80v-144L388-332Z"></path></svg></A>; outerText=CLI Docs; tagName=A; class=pill; href=https://angular.dev/tools/cli; rel=noopener; target=_blank; _ngcontent-ng-c245922056=
                    }, @{innerHTML=<SPAN _ngcontent-ng-c245922056>Angular Language Service</SPAN><?XML:NAMESPACE PREFIX = "[default] http://www.w3.org/2000/svg" NS = "http://www.w3.org/2000/svg
                    " /><svg _ngcontent-ng-c245922056="" fill="currentColor" viewBox="0 -960 960 960" xmlns="http://www.w3.org/2000/svg" width="14" height="14"><path _ngcontent-ng-c245922056=""
                     d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h280v80H200v560h560v-280h80v280q0 33-23.5 56.5T760-120H200Zm188-212-56-56 372-372H560v-80h280v280h-80v-144L38
                    8-332Z"></path></svg>; innerText=Angular Language Service; outerHTML=<A class=pill href="https://angular.dev/tools/language-service" rel=noopener target=_blank _ngcontent-ng
                    -c245922056><SPAN _ngcontent-ng-c245922056>Angular Language Service</SPAN><?XML:NAMESPACE PREFIX = "[default] http://www.w3.org/2000/svg" NS = "http://www.w3.org/2000/svg" /
                    ><svg _ngcontent-ng-c245922056="" fill="currentColor" viewBox="0 -960 960 960" xmlns="http://www.w3.org/2000/svg" width="14" height="14"><path _ngcontent-ng-c245922056="" d=
                    "M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h280v80H200v560h560v-280h80v280q0 33-23.5 56.5T760-120H200Zm188-212-56-56 372-372H560v-80h280v280h-80v-144L388-3
                    32Z"></path></svg></A>; outerText=Angular Language Service; tagName=A; class=pill; href=https://angular.dev/tools/language-service; rel=noopener; target=_blank; _ngcontent-n
                    g-c245922056=}...}
ParsedHtml        : System.__ComObject
RawContentLength  : 20845

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 19.1.6
Node: 22.7.0
Package Manager: npm 10.8.2
OS: win32 x64

Angular: 19.1.5
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1901.6
@angular-devkit/build-angular   19.1.6
@angular-devkit/core            19.1.6
@angular-devkit/schematics      19.1.6
@angular/cli                    19.1.6
@angular/ssr                    19.1.6
@schematics/angular             19.1.6
rxjs                            7.8.1
typescript                      5.7.3
zone.js                         0.15.0

Anything else?

In error example pay attention that:
Content-Length: 20846
RawContentLength : 20845

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions