middleman: Build failure with `asset_host` config and rack >=2.1.0 with `Content-Length header` error
Expected behavior and actual behavior
middleman build succeeds
Steps to reproduce the problem (from a clean middleman installation)
gem install middlemanmiddleman init- add
activate :asset_host, host: 'http://assets.example.com'toconfig.rb middleman build --verbose
Observe build fails.
Additionally, if you downgrade rack you can observe that the build will succeed:
rm -f Gemfile.lockecho "gem 'rack', '2.0.8'" >> Gemfilemiddleman build --verbose
Observe the build succeeds
Additional information
- Ruby version: ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
- Middleman version: 4.3.5
- OS version: Mac OS 10.14.6
Code example:
https://github.com/lsirivong/middleman-example (build fails on master branch) https://github.com/lsirivong/middleman-example/tree/rack-2.0.8 (build succeeding on this branch)
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 18 (11 by maintainers)
Commits related to this issue
- Regress to rack 2.0.8 because of build problem see https://github.com/middleman/middleman/issues/2309\#issuecomment-575607760 — committed to bigtestjs/bigtestjs.io by taras 4 years ago
- Deprecate old website (#74) * Add deprecated banner component and update webpack * Add deprecation notice for index page * Regress to rack 2.0.8 because of build problem see https://github.c... — committed to bigtestjs/bigtestjs.io by minkimcello 4 years ago
- Update Ruby deps — committed to speedy1812/daysinukraine.com by speedy1812 4 years ago
- This upgrade causes an error in Rack. Rack [passed the buck on the issue](https://github.com/rack/rack/issues/1472) to [middleman](https://github.com/middleman/middleman/issues/2309) who fixed this p... — committed to cloudfoundry/uaa by srwaggon 4 years ago
- Version of rack reverted back to 2.0.8 due to the Middleman build failing due to the upgraded gem. https://github.com/middleman/middleman/issues/2309#issuecomment-580015535 Middleman creates static ... — committed to ministryofjustice/formbuilder-product-page by mattempty 4 years ago
Released as
v4.3.6Me and my colleague have investigated the issue and the culprit seems to be in the asset hash and asset host rewriting. Basically, the metaprogrammed method called
#rewrite_inline_urls(which was very hard to find the definition of) does change the contents of resources, but does not change the precomputedContent-Lengthheaders for them. We were not able to find how the result of the rewriting feeds back into the Rack response pipeline, so we opted for adding the following to ourconfig.rbfor Middleman to fix it:This forces recomputation of the Content-Length header leading to the correct result. I had serious trouble navigating the Contracts-based inheritance chain for the rewriters, so I hope someone more knowledgeable with Middleman internals can address this.
I’ve put up a patch in https://github.com/middleman/middleman/pull/2316 - can someone in thread test it? I do not have time to do so at the moment but I believe it should be sufficient.
Is this fixed?
Oh my word, @julik, thank you for this Content Length fix. I felt like I was going insane.
For further context / for anyone else searching for this bug for CSS (not Rack) reasons: This bug is also tripped by combining
relative_assetswith even one instance ofimage-url()in your styles. This bug prevents the CSS file from being generated.For me, downgrading to 2.0 from 2.1 wasn’t enough. I had to lock the version to 2.0.8 to resolve the content-length errors I was getting.