Giter Club home page Giter Club logo

Comments (5)

clue avatar clue commented on May 17, 2024

The stream handling logic has been implemented as part of the v0.6.0 release, see the changelog for more details: https://github.com/reactphp/http/blob/master/CHANGELOG.md#060-2016-03-09

As such, you're highly recommended to use the latest version of this package.

I hope this helps 👍

from http.

hotrush avatar hotrush commented on May 17, 2024

I'm happy to update, but it is impossible because of depending on lot of other libraries.

Is there any way to handle post data in 0.4 version?

from http.

clue avatar clue commented on May 17, 2024

I would suggest making sure everything is compatible with the latest versions and file issues and PRs for all libraries that may not be compatible yet. Updating each library should usually not take more than a few minutes, so I wonder what libraries you're referring to?

Our focus is currently on supporting the latest features in the latest tagged releases, but I suppose we would accept PRs that backport relevant functionality to old release branches as long as BC is preserved 👍

from http.

hotrush avatar hotrush commented on May 17, 2024

I have found a workaround that works for me:

$loop = \React\EventLoop\Factory::create();
$socket = new \React\Socket\Server(8080, $loop);
$http = new \React\Http\Server($socket);
$http->on('request', function (\React\Http\Request $request, \React\Http\Response $response) {

    if ($request->hasHeader('Content-Length') && $request->getHeader('Content-Length')[0] > 0) {
        $request->on('data', function ($data) use ($response) {
            echo 'Data'.PHP_EOL;
            $response->writeHead(200, array('Content-Type' => 'text/plain'));
            $response->end("The length of the submitted request body is: " . serialize($data));
        });
    } else {
        echo 'End'.PHP_EOL;
        $response->writeHead(200, array('Content-Type' => 'text/plain'));
        $response->end('No data provided');
    }

    // an error occures e.g. on invalid chunked encoded data or an unexpected 'end' event
    $request->on('error', function (\Exception $exception) use ($response, &$contentLength) {
        echo 'Error'.PHP_EOL;
        $response->writeHead(400, array('Content-Type' => 'text/plain'));
        $response->end("An error occured while reading at length: " . $contentLength);
    });

});
$loop->run();

At now i have not enough time to pr, but need to make this work very soon) Thanks

from http.

clue avatar clue commented on May 17, 2024

Happy to hear to this works for you 👍 This may or may not work for some smaller request bodies, but will certainly break for larger bodies or using chunked transfer encoding. See also the referenced release notes and all tickets linked to this release to see why we decided to bump the major version here.

from http.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.