Skip to content

Content-Length calculation causing HTML to be truncated #103

Description

@brucruz

Hello,

I have noticed that my app (GlobalDIal) receives truncated HTML when rendering any page on the development environment.

  • Version used: hotwire-spark (0.1.13)

I believe this is due to the current implementation of the "Content-Length" header in Hotwire::Spark::Middleware.

class Hotwire::Spark::Middleware
...

  def call(env)
      ...

      headers["Content-Length"] = html.bytesize.to_s if html
      response = [ html ]
    end

I could not yet find a reason why .bytesize method is not calculating the content length correctly, but I executed two tests that confirm the calculation is not correct:

  1. disabled hotwire-spark in my local development
  2. removed the "Content-Length" header from the response coming from the middleware and letting Rack provide that calculation to the response.

In both cases, the truncating problem was fixed.

My implementation then became:

class Hotwire::Spark::Middleware
...

  def call(env)
      ...

      headers.delete("Content-Length"])
      response = [ html ]
    end

Is anyone else facing similar issues? I opened a Pull Request to address this change and I hope it can help anyone else that might be facing the same situation.

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