Coder Social home page Coder Social logo

I should depend on raw-body about body HOT 15 CLOSED

Raynos avatar Raynos commented on May 28, 2024
I should depend on raw-body

from body.

Comments (15)

jonathanong avatar jonathanong commented on May 28, 2024

probably depend - raw-body doesn't actually parse the string. i was thinking about making a body-parser module, but i guess this module is what that would be. people in connect/express just want too many options, it's pretty annoying.

i'm not sure what's the point of using the string decoder vs. buffer.toString() though. only issue i can think about that is getting the correct charset from the request body if it isn't utf8.

also, not including string parser is easier for me since then i can implement the string parser however i want. see: https://github.com/koajs/body-parser/blob/master/index.js

from body.

Raynos avatar Raynos commented on May 28, 2024

@jonathanong So I don't know whether string decoder of Buffer.concat(buffers) is better. should have a bench mark.

I copied @izs code from npm-www which uses StringDecoder which is used to handle two bytes UTF8 properly since body += String(chunk) is wrong if chunk has a trailing byte.

from body.

Raynos avatar Raynos commented on May 28, 2024

@jonathanong btw I'm going through express & connect and rewriting them using small modules. If you have any modules to recommend using you should add them to the wiki page !

from body.

jonathanong avatar jonathanong commented on May 28, 2024

yeah, i don't know which one is faster, but i prefer fewer lines of code. i doubt any performance differences are significant, though.

from body.

jonathanong avatar jonathanong commented on May 28, 2024

sick! i actually wanted to do that, but unfortunately a lot of the middleware rely on connect patches like res.on('header').

most of the remaining connect issues are sessions, but sessions right now are such a mess that i don't want to touch them. for koa, tj's been thinking about just making tests for a session "spec" which implementors can use instead of relying on connect.session(). it should be easier to make better session middleware that way. let me know if you're interesting in doing that for connect/express.

from body.

Raynos avatar Raynos commented on May 28, 2024

@jonathanong look at generic-session & redsess & level-session. that's what I use, I like them.

but of course it doesn't have that crazy asynchronously load session for each req before route and asynchronously save session for each res.end()

from body.

isaacs avatar isaacs commented on May 28, 2024

Buffer.concat is not better unless for some reason you already HAVE a list of buffers. If you're collecting a stream into a string, then StringDecoder is better in both time and space.

from body.

Raynos avatar Raynos commented on May 28, 2024

@isaacs I broke out your npm-www things, should I PR them back into npm-www ?

from body.

jonathanong avatar jonathanong commented on May 28, 2024

is the impact significant?

also, why even bother using string decoder then? why not just do req.setEncoding()?

from body.

Raynos avatar Raynos commented on May 28, 2024

@jonathanong req.setEncoding will set the encoding on the source namely the req. Using stringDecoder in body is setting the encoding on the destination, namely the streaming body parser.

If you pipe the req to multiple location then maybe not all locations want the data chunks to be UTF8

from body.

jonathanong avatar jonathanong commented on May 28, 2024

oh, that's true. there was a bug where someone decided to set the encoding for no reason.

from body.

jonathanong avatar jonathanong commented on May 28, 2024

actually, that wouldn't matter. you assume the data is in buffers as well.

either way, i'll add encoding support to raw-body.

from body.

Raynos avatar Raynos commented on May 28, 2024

@jonathanong I did a code review of raw-body and added some issues! Once those are handled I'll update this to depend on raw-body instead.

from body.

Raynos avatar Raynos commented on May 28, 2024

I updated the code to depend on Raynos/raw-body

Waiting for @jonathanong to publish a version of raw-body.

Added @jonathanong as a collaborator aswell. You can make alterations. If your not sure about stuff make PRs and I'll review it.

from body.

Raynos avatar Raynos commented on May 28, 2024

Now depends on raw-body form npm.

Published as v4.0.2

from body.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.