RejectedSoftware Forums

Sign up

Getting raw body of HTTP request

As an exercise, I'm trying to write a kind of proxy server that logs requests, passes them to another endpoint and send response back to the client (i.e. client -> localhost:8080/some/path -> some.real.api/some/path -> localhost:8080 -> client).

However, I couldn't find a way to get raw body of HTTP request in vibe.d. Depending of request's content type it's either in form data, or in JSON or in body. It there a simple way to have the raw body and send it to some other URL in vibe.d (without iterating on possible content types)?

Re: Getting raw body of HTTP request

Am 25.02.2017 um 10:51 schrieb Paweł Świątkowski:

As an exercise, I'm trying to write a kind of proxy server that logs requests, passes them to another endpoint and send response back to the client (i.e. client -> localhost:8080/some/path -> some.real.api/some/path -> localhost:8080 -> client).

However, I couldn't find a way to get raw body of HTTP request in vibe.d. Depending of request's content type it's either in form data, or in JSON or in body. It there a simple way to have the raw body and send it to some other URL in vibe.d (without iterating on possible content types)?

If you remove the parseFormBody, parseJsonBody and
parseMultiPartBody options from HTTPServerSettings.options (or just
set it to none for a pure proxy application), the body contents will
always be available in req.bodyReader. However, content and transfer
encoding will always be applied automatically (if required, at least
content encoding could also be turned into an option).