# Rails truncating raw\_post\_data?

**URL:** <https://www.ruby-forum.com/t/rails-truncating-raw-post-data/112589>\
**Category:** Rails\
**Created:** [August 21, 2007, 5:45am UTC](https://www.ruby-forum.com/t/rails-truncating-raw-post-data/112589 "2007-08-21T05:45:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [August 21, 2007, 5:45am UTC](https://www.ruby-forum.com/t/rails-truncating-raw-post-data/112589/1 "2007-08-21T05:45:13Z")

</div>

Has anyone ever run into any problems with rails truncating  
raw\_post\_data. My situation is this: I’m the developer for RubyAMF  
([wiki.rubyamf.org](http://wiki.rubyamf.org)). Which is a flash remoting application server. With  
the rails plugin, it allows flash to talk to a controller and return AMF  
data…

So long story short, the flash player makes a request to a rails  
controller sending AMF binary format in the raw\_post, but I’m having  
inconsistent behavior with AMF data being incomplete.

I’ve narrowed it rails now and am looking for a foot in the right  
direction. Either in debugging this myself, or if someone has run into  
this…

Right now I grab the raw request like so: request.env[“RAW\_POST\_DATA”].  
This is what is being inconsistent in rails.

I’ve verified this because I can run RubyAMF as a standalone application  
server, (takes rails out of the process), and this one bug (incomplete  
AMF) that I’m running into NEVER happens. meaning the flash player is  
always sending correct AMF, RubyAMF is handling it perfect. But now with  
the rails plugin AMF data is being truncated at some point, for some  
random reason.

So, does anyone have any ideas? run into this? where to debug??

-Thanks  
Aaron

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [August 21, 2007, 8:29pm UTC](https://www.ruby-forum.com/t/rails-truncating-raw-post-data/112589/2 "2007-08-21T20:29:37Z")

</div>

Hi,

I may be way off beam, but if you are using lighttpd:-

I recall having a problem with my raw post data being truncated after  
an update to lighttpd, this occurred because I didnt have the mimetype  
listed.

just a thought  
Tonypm

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [August 21, 2007, 8:55pm UTC](https://www.ruby-forum.com/t/rails-truncating-raw-post-data/112589/3 "2007-08-21T20:55:43Z")

</div>

tonypm wrote:

> Hi,
> 
> I may be way off beam, but if you are using lighttpd:-
> 
> I recall having a problem with my raw post data being truncated after  
> an update to lighttpd, this occurred because I didnt have the mimetype  
> listed.
> 
> just a thought  
> Tonypm

not off base, good though. At least I know someone else has seen this.

So far it happens with webrick, mongrel, and i"m guessing it will with  
lighttpd. I’ll lighttpd tonight.

What kind of route did you go to debug this? It seems like more of an  
issue with Rails, as it’s happening with two of the servers.

I’m going to dig into rails and see where the “request” variable is  
being setup. I’m thinking I can put some debugging there… Double  
checking that the raw post is correctly coming through the request from  
all servers… if it is, then somewhere in rails it’s being truncated.

thanks  
-Aaron

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [August 21, 2007, 9:25pm UTC](https://www.ruby-forum.com/t/rails-truncating-raw-post-data/112589/4 "2007-08-21T21:25:06Z")

</div>

I actually just found my problem. It’s a “bug fix” in actionpack  
raw\_post\_data\_fix.rb#read\_body. There is this line:

# Fix for Safari Ajax postings that always append \000

content.chop! if content[-1] == 0

But AMF data always appends a \000 as well. So this was causing it to be  
truncated.

Now to talk to whomever develops actionpack.

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [September 9, 2007, 6:58am UTC](https://www.ruby-forum.com/t/rails-truncating-raw-post-data/112589/5 "2007-09-09T06:58:27Z")

</div>

I’m seeing the same problem with attachment\_fu when saving the image  
to the database. When I try to display the image, only 40k appears in  
the browser and with some images even that much is not visible (just  
garbage when I view source).

Have you heard anything further regarding the bug fix to ActionPack?

-Dave

On Aug 21, 12:25 pm, Aaron S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [September 9, 2007, 7:34pm UTC](https://www.ruby-forum.com/t/rails-truncating-raw-post-data/112589/6 "2007-09-09T19:34:44Z")

</div>

Thanks for the reply. I’ll bring it up as a new topic and see if  
anyone else has run into this.

Cheers,  
Dave

On Sep 9, 12:26 am, Aaron S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [September 9, 2007, 8:25pm UTC](https://www.ruby-forum.com/t/rails-truncating-raw-post-data/112589/7 "2007-09-09T20:25:09Z")

</div>

Dave Dumaresq wrote:

> Thanks for the reply. I’ll bring it up as a new topic and see if  
> anyone else has run into this.
> 
> Cheers,  
> Dave
> 
> On Sep 9, 12:26 am, Aaron S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Cool, let me know if you find anything. I’m wondering if this is fixed  
in edge rails. I’ll take a peek at some point this week.

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [October 7, 2007, 5:51pm UTC](https://www.ruby-forum.com/t/rails-truncating-raw-post-data/112589/8 "2007-10-07T17:51:49Z")

</div>

Aaron S. wrote:

> But AMF data always appends a \000 as well. So this was causing it to be  
> truncated.
> 
> Now to talk to whomever develops actionpack.

Thanks a million for identifying this. I’ve just spent n hours trying to  
fix the same problem - funnily enough, also with a Ruby AMF parser I’ve  
written - and had just decided on the solution of appending a null byte  
to the end of the data. I’m reassured to find that this won’t just be a  
quick-and-dirty fix and that there’s actually a real bug that causes me  
to do that. 🙂

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [September 9, 2007, 9:26am UTC](https://www.ruby-forum.com/t/rails-truncating-raw-post-data/112589/9 "2007-09-09T09:26:08Z")

</div>

Dave Dumaresq wrote:

> I’m seeing the same problem with attachment\_fu when saving the image  
> to the database. When I try to display the image, only 40k appears in  
> the browser and with some images even that much is not visible (just  
> garbage when I view source).
> 
> Have you heard anything further regarding the bug fix to ActionPack?
> 
> -Dave
> 
> On Aug 21, 12:25 pm, Aaron S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

I know it was a registered bug in the Rails trac system. That’s about as  
far as I went. In the plugin that I wrote for rails I just handled the  
one case where this was causing an issue.
