RejectedSoftware Forums

Sign up

std.net.curl.post, HTTPServerRequest.bodyReader.empty

Hi,

If I do a:

std.net.curl.post(someURL, "some string");

In my vibed post handler the req.bodyReader is empty, with leastSize == 0. I also couldn't find any data in the other properties of the HTTPServerRequest object that I looked. What am I doing wrong?

Luís

Re: std.net.curl.post, HTTPServerRequest.bodyReader.empty

On Thu, 19 Dec 2013 17:50:31 GMT, Luís Marques wrote:

If I do a:

std.net.curl.post(someURL, "some string");

In my vibed post handler the req.bodyReader is empty, with leastSize == 0. I also couldn't find any data in the other properties of the HTTPServerRequest object that I looked. What am I doing wrong?

Curiously, it works with a PUT method:

client: put(someURL, "some string");

server: assert(readAllUTF8(req.bodyReader, false, 0x1000) == "some string");

I'm using a PUT as a workaround for now.

Re: std.net.curl.post, HTTPServerRequest.bodyReader.empty

On Thu, 19 Dec 2013 17:50:31 GMT, Luís Marques wrote:

Hi,

If I do a:

std.net.curl.post(someURL, "some string");

In my vibed post handler the req.bodyReader is empty, with leastSize == 0. I also couldn't find any data in the other properties of the HTTPServerRequest object that I looked. What am I doing wrong?

Luís

The reason is that CURL sends "some string" with "Content-Type: application/x-www-form-urlencoded" by default and vibe.d enables HTTPOption.parseFormBody by default, which will result in vibe.d parsing the POST body as form data which will be put into req.form. Changing either of the two should make the raw data available.

Re: std.net.curl.post, HTTPServerRequest.bodyReader.empty

On Fri, 20 Dec 2013 18:43:56 GMT, Sönke Ludwig wrote:

The reason is that CURL sends "some string" with "Content-Type: application/x-www-form-urlencoded" by default and vibe.d enables HTTPOption.parseFormBody by default, which will result in vibe.d parsing the POST body as form data which will be put into req.form. Changing either of the two should make the raw data available.

But I had tried dumping req.form and it was also empty. Isn't that unexpected?

Re: std.net.curl.post, HTTPServerRequest.bodyReader.empty

Am 20.12.2013 19:52, schrieb Luís Marques:

On Fri, 20 Dec 2013 18:43:56 GMT, Sönke Ludwig wrote:

The reason is that CURL sends "some string" with "Content-Type: application/x-www-form-urlencoded" by default and vibe.d enables HTTPOption.parseFormBody by default, which will result in vibe.d parsing the POST body as form data which will be put into req.form. Changing either of the two should make the raw data available.

But I had tried dumping req.form and it was also empty. Isn't that unexpected?

Which string exactly did you send? For "some string" I get a single
field ["some string": ""].

Re: std.net.curl.post, HTTPServerRequest.bodyReader.empty

On Fri, 20 Dec 2013 20:09:04 +0100, Sönke Ludwig wrote:

Which string exactly did you send? For "some string" I get a single
field ["some string": ""].

Sorry for the late reply (holidays, etc...). I think what happened was the following. I was expecting the content of a curl request of the form `post(url, "somestring");' to be received through the req.bodyReader. When that didn't work, I tried all of the other places where the content could be coming from. I printed all of the input fields of the request object, including something like:

foreach(f; req.form)
    writeln(f);

I guess that implicit in this was that I was expecting the content to be in the form ["" : "somestring"]. That is, since I didn't specify any "field name" in the curl request I didn't expect the content to be the key -- I expected it to be the value! (or perhaps I didn't even realize it was an associative array. at the time). When I didn't see any output in all of my writeln's I wrongly concluded that the request did not at all include the content. :-)