drashland / drash

A microframework for building JavaScript HTTP applications. Runtime-agnostic. Strongly typed.

Home Page:https://drash.land/drash

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make requets.bodyParam try decode the returning value too

ebebbington opened this issue · comments

So people dont have to decode when getting body input - though, are bodies ever encoded? unless done so by the user/dev? if so then this probably isnt needed

like if it's a Uint8Array?

I mean like decodeUriComponent, like how we do for query strings and path params

actually they are when body is url encoded, but wonder if parsing the body foes that for us, need to investigate

Only encoded when explicitely done by the user/dev, and the fact that bodys can be objects, a N amoutn fo levels deep, it isn't practical for us to try decode the value

function bodyParam(value) {
  const val = this.body[value]
  if (val is a string) return decode(val)
  else loop a gazillion times through each key of the obj

And i'm sure this does happen, but very very rare, so i think we're good to just dismiss this, if that one user who encounters an obejct with encoded data, because a 3rd party dev sent it to them like that, they should decode it imo, because at least THEY'LLL know what keys it has, and just need to decode that