popomore / koa-proxy

Proxy middleware for koa
223 stars 102 forks source link

Pass the request body (don't assume this.request.body set) #9

Open kenkunz opened 10 years ago

kenkunz commented 10 years ago

This addresses the same issue as pull request #8, but with a different approach.

A proxy should preserve the original request as much as possible. It's not safe to assume what body parser (if any) an application is using, and it's not ideal to re-stringify a body that's already been parsed to an object. Instead, it seems preferable to get the original, raw request body and pass it through to the destination server.

I took a slightly different approach to testing this as well. The key thing to validate is that the original request is passed-through to the destination server unchanged – so rather than validate a response from the server, I just validate the request body in the destination app's middleware. (This required creating a separate destination app than the one in the setup).

Let me know what you think.

coveralls commented 10 years ago

Coverage Status

Coverage remained the same when pulling ba5d44268b7553d9466808fee23c721856f6b515 on kenkunz:master into d650dbc0daad3ab986c4d2f6160e6928f93b2285 on popomore:master.

kenkunz commented 10 years ago

Any thoughts on merging this?

Thanks, Ken

kenkunz commented 10 years ago

I see you merged #8. Did you consider this as an alternative? (solves the same problem by passing-through the original raw request body rather than re-srtingifying it)

popomore commented 10 years ago

@kenkunz can you rebase master? you can getRawBody in getParsedBody function, I'll review it.