mschwartz / SilkJS

V8 Based JavaScript Swiss Army Knife (and HTTP Server!)
https://github.com/decafjs/decaf
Other
323 stars 37 forks source link

Allow access to raw POST data #21

Closed wboayue closed 12 years ago

wboayue commented 12 years ago

When a POST request is submitted to the silkjs sever, the request is properly decoded if the content-type is multipart/form-data or application/x-www-form-urlencoded. Data from other content types is discarded.

Data from an unknown content type could be put in req.data.post.

When using models in Ext JS 4 with the rest proxy, data is posted as application/json. There is no way to access this data in the request object.

mschwartz commented 12 years ago

Can you send me a raw post using application/json? I mean headers and body and all.

I will implement it within minutes.

On Apr 17, 2012, at 7:46 AM, Wil Boayue wrote:

When a POST request is submitted to the silkjs sever, the request is properly decoded if the content-type is multipart/form-data or application/x-www-form-urlencoded. Data from other content types is discarded.

Data from an unknown content type could be put in req.data.post.

When using models in Ext JS 4 with the rest proxy, data is posted as application/json. There is no way to access this data in the request object.


Reply to this email directly or view it on GitHub: https://github.com/mschwartz/SilkJS/issues/21

mschwartz commented 12 years ago

OK, I found a WWW page that talks about application/json posts. req.data.post makes sense. Should it be automatically JSON decoded or the string?

On Apr 17, 2012, at 7:46 AM, Wil Boayue wrote:

When a POST request is submitted to the silkjs sever, the request is properly decoded if the content-type is multipart/form-data or application/x-www-form-urlencoded. Data from other content types is discarded.

Data from an unknown content type could be put in req.data.post.

When using models in Ext JS 4 with the rest proxy, data is posted as application/json. There is no way to access this data in the request object.


Reply to this email directly or view it on GitHub: https://github.com/mschwartz/SilkJS/issues/21

mschwartz commented 12 years ago

I pushed the change. See if it works for you. The string is stored in req.data.post.

On Apr 17, 2012, at 7:46 AM, Wil Boayue wrote:

When a POST request is submitted to the silkjs sever, the request is properly decoded if the content-type is multipart/form-data or application/x-www-form-urlencoded. Data from other content types is discarded.

Data from an unknown content type could be put in req.data.post.

When using models in Ext JS 4 with the rest proxy, data is posted as application/json. There is no way to access this data in the request object.


Reply to this email directly or view it on GitHub: https://github.com/mschwartz/SilkJS/issues/21

wboayue commented 12 years ago

That works. Is the exact patch I made locally. Thanks.

jlerouge commented 11 years ago

The issue has reappeared, because of an extra line of code (httpd/request.js, line 143) :

142: } 143: req.data = data; 144: 145: return true;

It overrides the post variable, stored at line 139 ( req.data.post = post; ). I commented out the line 143, and it works again.

jlerouge commented 11 years ago

Actually, would be better to write :

else { if( typeof(data) == undefined ) { var data = new Object(); } req.data = data; req.data.post = post; }

instead of

else { req.data.post = post; }

(and still leave commented previously line 143)

mschwartz commented 11 years ago

Feel free to offer pull requests.

Thanks!