disable chunked transfer-encoding

35 views
Skip to first unread message

dorian taylor

unread,
May 23, 2019, 12:11:12 PM5/23/19
to Rack Development
Hi,

I'm trying to use Rack as a FastCGI authorizer (cf https://github.com/fast-cgi/spec/blob/master/spec.md#63-authorizer ) in conjunction with Apache mod_authnz_fcgi (https://httpd.apache.org/docs/2.4/mod/mod_authnz_fcgi.html ). My problem is that mod_authnz_fcgi insists on a 200 status code and only a 200 status code to communicate any results from the fastcgi script back up the line. This is where Rack::Chunked is ruining my day: it forces the choice of either a Content-Length header (which is transmitted upstream and truncates the output), or a Transfer-Encoding: chunked header where the accompanying token is removed upstream, resulting in a protocol error.

I would like to be able to express an HTTP 200 response that has neither a Content-Length nor a Transfer-Encoding header. Is there any way to disable Rack::Chunked for certain responses?

James Tucker

unread,
May 23, 2019, 12:15:24 PM5/23/19
to Rack Development
Such a response is only valid in http 1.0, not http 1.1.

In this regard rack won't help you much, as it isn't trying to provide for that case.

Have you considered not including this middleware for these requests?

--

---
You received this message because you are subscribed to the Google Groups "Rack Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rack-devel+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rack-devel/ab1058ab-ba08-4843-9489-86bcc55bde19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

dorian taylor

unread,
May 23, 2019, 12:16:14 PM5/23/19
to Rack Development
Never mind, looks like after rummaging through handler/fastcgi.rb, the answer is to set a Content-Length header to the empty string. This tricks Rack::Chunked which only tests for the presence of the header, not its content. I'm a bit apprehensive about this solution but for now it works.

dorian taylor

unread,
May 23, 2019, 12:18:42 PM5/23/19
to Rack Development


On Thursday, May 23, 2019 at 9:15:24 AM UTC-7, raggi wrote:

Such a response is only valid in http 1.0, not http 1.1.

In this regard rack won't help you much, as it isn't trying to provide for that case.

Have you considered not including this middleware for these requests?


Do I get a choice in the matter? If I start the script with rackup it seems to add it all by itself:


#<Rack::ContentLength:0x000055d0e32f7f60
 
@app=
 
#<Rack::Chunked:0x000055d0e32f7fb0
   
@app=
   
#<Rack::TempfileReaper:0x000055d0e2a07db0
     
@app=#<LazyAuth::App:0x000055d0e315e910>>>>
#<LazyAuth::App:0x000055d0e315e910>



James Tucker

unread,
May 23, 2019, 12:42:06 PM5/23/19
to Rack Development
rackup is an opinionated tool that is good for 90% of use cases and adds those middleware to meet that goal.

I would say the behavior you need falls out of that use case set, and you should consider writing your fastcgi spawner using the library primitives.




--

---
You received this message because you are subscribed to the Google Groups "Rack Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rack-devel+...@googlegroups.com.

James Tucker

unread,
May 23, 2019, 12:44:36 PM5/23/19
to Rack Development


On Thu, May 23, 2019, 9:41 AM James Tucker <jftu...@gmail.com> wrote:


On Thu, May 23, 2019, 9:18 AM dorian taylor <dorian...@gmail.com> wrote:


On Thursday, May 23, 2019 at 9:15:24 AM UTC-7, raggi wrote:

Such a response is only valid in http 1.0, not http 1.1.

In this regard rack won't help you much, as it isn't trying to provide for that case.

Have you considered not including this middleware for these requests?


Do I get a choice in the matter? If I start the script with rackup it seems to add it all by itself:


#<Rack::ContentLength:0x000055d0e32f7f60
 
@app=
 
#<Rack::Chunked:0x000055d0e32f7fb0
   
@app=
   
#<Rack::TempfileReaper:0x000055d0e2a07db0
     
@app=#<LazyAuth::App:0x000055d0e315e910>>>>
#<LazyAuth::App:0x000055d0e315e910>



rackup is an opinionated tool that is good for 90% of use cases and adds those middleware to meet that goal.

I would say the behavior you need falls out of that use case set, and you should consider writing your fastcgi spawner using the library primitives.



It's been a long while, but I think if you pass the "none" environment these middleware will be elided.

dorian taylor

unread,
May 23, 2019, 12:54:11 PM5/23/19
to Rack Development


On Thursday, May 23, 2019 at 9:42:06 AM UTC-7, raggi wrote:

rackup is an opinionated tool that is good for 90% of use cases and adds those middleware to meet that goal.

I would say the behavior you need falls out of that use case set, and you should consider writing your fastcgi spawner using the library primitives.


Ah, yes, thanks. It'll probably end up that way; I'm just sketching it out right now: https://github.com/doriantaylor/rb-lazyauth

Also the 'none' environment indeed seems to skip the stock middleware. Thanks!
Reply all
Reply to author
Forward
0 new messages