Reactive-Extensions / RxJS-DOM

HTML DOM Bindings for the Reactive Extensions for JavaScript
http://reactivex.io
Other
438 stars 101 forks source link

Rx.DOM.ajax does not URL encode object body content #125

Open muj-beg opened 7 years ago

muj-beg commented 7 years ago

Calling Rx.DOM.ajax() with content type set to application/x-www-form-urlencoded and a body such as { name1: "value1&", name2: "value2" } sends the HTTP data as: name1=value1&&name2=value2. This is because the RxJs Ajax code does not URL encode values when converting a object body content to string payload.

matias-casal commented 7 years ago

+1

gilbarbara commented 7 years ago

@muj-beg did you found a way to fix this? Instead of passing an object to the body property, I just passed a string using a deparam module, like qs or query-string

muj-beg commented 7 years ago

@gilbarbara We ended up doing this:

const shouldUrlEncodeContent =
     request.body && typeof request.body !== 'string' && 
     request.headers && typeof request.headers['Content-Type'] === 'string' &&  
     request.headers['Content-Type'].indexOf('application/x-www-form-urlencoded') === 0;

if (shouldUrlEncodeContent) 
   request.body = QueryString.stringify(request.body);