RejectedSoftware Forums

Sign up

POST identical received POST

I need to receive a POST, and in return POST the same fields in the same
order with the same encoding as the original (paypal API).

HTTPServerRequest of course provides access to .contentType and .form,
but how do I best use these to craft the response? (is foreach-ing over
the .form guaranteed to be in the same order as the POSTed fields?)

What is the best way to accomplish this?

Re: POST identical received POST

Am 08.10.2014 19:46, schrieb Lemonfiend:

I need to receive a POST, and in return POST the same fields in the same
order with the same encoding as the original (paypal API).

HTTPServerRequest of course provides access to .contentType and .form,
but how do I best use these to craft the response? (is foreach-ing over
the .form guaranteed to be in the same order as the POSTed fields?)

What is the best way to accomplish this?

Yes, the form fields are always stored in the same order as they are
received (I'll mention this in the documentation). You should be able to
use formEncode(req.form) to get an encoded form equivalent to the
original request.

Re: POST identical received POST

On Wed 08 Oct 22:01, Sönke Ludwig wrote:

Am 08.10.2014 19:46, schrieb Lemonfiend:

I need to receive a POST, and in return POST the same fields in the same
order with the same encoding as the original (paypal API).

HTTPServerRequest of course provides access to .contentType and .form,
but how do I best use these to craft the response? (is foreach-ing over
the .form guaranteed to be in the same order as the POSTed fields?)

What is the best way to accomplish this?

Yes, the form fields are always stored in the same order as they are
received (I'll mention this in the documentation). You should be able to
use formEncode(req.form) to get an encoded form equivalent to the
original request.

Great!

Is there also an alternative/better way for writing the body?

void post(HTTPServerRequest req, HTTPServerResponse res)
{

auto contentType = req_.contentType ~ `;` ~ req_.contentTypeParameters;

import vibe.inet.webform: formEncode;
auto form = `cmd=_notify-validate` ~ formEncode(req_.form);

auto formBytes = cast(ubyte[])form);

import vibe.d: requestHTTP, HTTPMethod;
requestHTTP(url,
	(scope request)
	{
		request.method = HTTPMethod.POST;
		request.contentType = contentType;
		request.writeBody(formBytes);
	},
	(scope response)
	{
		//etc.
	}
);

}