Project

General

Profile

Http::Client twice GET with chunked response

Added by Emanuele Cappone almost 8 years ago

Hi,

with several test i noticed a severe bug with http client. If i make a GET request and the server response me with a chunked body, the client library repeat for the second time the same request.

This behavior is easily reproducible with two php script that return a chunked/non chunked response.

Someone else has experienced this behavior?


Replies (3)

RE: Http::Client twice GET with chunked response - Added by Wim Dumon almost 8 years ago

Hello Emanuele,

From a quick look at the code, the only point where I see a request that could cause a next request without API interaction is in the case of redirections. Can you post a complete test case so that we can reproduce this at our end?

Thank you,

Wim.

RE: Http::Client twice GET with chunked response - Added by Emanuele Cappone almost 8 years ago

Hi Wim,

thanks for your response. This is my minimal WApplication:

#include <Wt/Http/Client>
#include <Wt/WApplication>

using namespace std;
using namespace Wt;

class HelloApplication : public WApplication
{
public:
  HelloApplication(const WEnvironment& env);
  void handleMe(boost::system::error_code, const Http::Message&);
};

HelloApplication::HelloApplication(const WEnvironment& env) : WApplication(env)
{
    Http::Client *client = new Http::Client(WApplication::instance());
    client->setTimeout(15);
    client->setMaximumResponseSize(10 * 1024);

    client->done().connect(boost::bind(&HelloApplication::handleMe, this, _1, _2)); 

    //const char *UserInfoUrl = "http://192.168.69.57:8001/oauth2.php?client_id=945a4716c99845bf83098f022c4e6e2c";
    const char *UserInfoUrl = "http://192.168.69.57:8001/oauth2chunk.php?client_id=945a4716c99845bf83098f022c4e6e2c";

    client->get(UserInfoUrl);   
}

void HelloApplication::handleMe(boost::system::error_code err, const Http::Message& response)
{
    cout << "Message: " << response.body() << endl;
}

WApplication *createApplication(const WEnvironment& env)
{
  return new HelloApplication(env);
}

int main(int argc, char **argv)
{
  return WRun(argc, argv, &createApplication);
}

Follow the two scripts used for testing:

<?php
header("Content-Type: application/json; charset=utf-8");
header("Transfer-Encoding: chunked");

$text = <<<EOT
{"data":[{"consumer_id":"5ed0bf2f-6ad5-4fbc-8910-53cdcacf9070","client_id":"945a4716c99845bf83098f022c4e6e2c","id":"9cfbefb9-552f-4877-9578-32014190f4d2","created_at":1468602325000,"name":"myapp","redirect_uri":"[\"http:\\\/\\\/192.168.69.1:9001\"]","client_secret":"f30107e8cb4145b297965ea9ff135e73"}],"total":1}
EOT;

printf("%x\r\n%s\r\n", strlen($text), $text);
ob_flush();
print("0\r\n\r\n");
ob_flush();
flush();
?>

<?php
header("Content-Type: application/json; charset=utf-8");

$text = <<<EOT
{"data":[{"consumer_id":"5ed0bf2f-6ad5-4fbc-8910-53cdcacf9070","client_id":"945a4716c99845bf83098f022c4e6e2c","id":"9cfbefb9-552f-4877-9578-32014190f4d2","created_at":1468602325000,"name":"myapp","redirect_uri":"[\"http:\\\/\\\/192.168.69.1:9001\"]","client_secret":"f30107e8cb4145b297965ea9ff135e73"}],"total":1}
EOT;

echo $text;
?>

Regards,

RE: Http::Client twice GET with chunked response - Added by Roel Standaert over 7 years ago

Hello Emanuele,

There seemed to be an issue in Wt that caused the done() signal to be emitted twice in some cases. I just fixed that, so the fix should be GitHub soon. I'm still not sure why it's triggered in your example, and not with some other chunked responses. There might be something with the way the connection behaves in your case. There's no extra junk data being sent after the response, so I'm not sure what's going on.

Regards,

Roel

    (1-3/3)