Giter Club home page Giter Club logo

Comments (5)

clue avatar clue commented on May 17, 2024

Thanks for filing this ticket and sparking the discussion about our expect-continue feature (Expect: 100-continue) 👍

First things first, here's how this works in the first place:

  • This feature is specified as part of HTTP/1.1: https://tools.ietf.org/html/rfc7231#section-5.1.1
  • Clients MAY implement this feature but are not required to do so
  • Severs MAY implement this feature but are not required to do so
  • If the client includes a Expect: 100-continue header, the server MAY return an intermediary HTTP/1.1 100 Continue response after receiving the request headers, which causes the client to start transmitting the actual message body
  • If the client includes a Expect: 100-continue header, the server MAY reject the request with any "normal" error response message, which means the client never has to transmit the message body at all
  • Clients MUST support servers that do not implement this feature. This usually adds a few seconds of delay where the client waits for the intermediary HTTP/1.1 100 Continue response
  • Many common clients actually implement this feature when sending large requests only (usually a few KiB or MiB)

from http.

clue avatar clue commented on May 17, 2024

That being said, let's look into how this handled in React:
React has had this feature for a long time already, but it's currently completely undocumented. I'm currently adding documentation for this as part of #107. This means it's very likely this is hardly used at all.

This combined means that it may look like React is "slow" when consumers do not explicitly handle these headers. Other than this added delay, it actually works perfectly fine. This delay can be avoided by explicitly supporting this feature like this:

$http->on('request', function ($request, $response) {
    if ($request->expectsContinue()) {
        $response->writeContinue().
    }
    $response->writeHead(200, array('Content-Type' => 'text/plain'));
    $response->end("Hello World!\n");
});

This is necessary because this if block code could implement some custom application logic to check the request headers and such and we can't really provide a "default implementation" here.

For example, you may want to reject the request if it uses the wrong Content-Type or its Content-Length exceeds a certain threshold. In this case, a client would detect this error before even trying to upload the message body (which could possibly be multiple GiB).

from http.

kelunik avatar kelunik commented on May 17, 2024

This is necessary because this if block code could implement some custom application logic to check the request headers and such and we can't really provide a "default implementation" here.

While it can be used to check certain things ahead of the request body being sent, it generally increases the complexity for request handling and doesn't offer real benefits. It's fine if the server code handles it and the user code relies on the TCP buffer for back-pressure. The client will slow down if the receive buffer is full, so only 128KB or so will be buffered or the request body.

from http.

clue avatar clue commented on May 17, 2024

Progress update: I've added the v0.7.0 milestone because we're going to look into applying PSR-7 interfaces (#28) and will thus very likely ditch custom methods such as expectsContinue() and writeContinue() altogether.

@kelunik While I agree your suggestion would likely work for the 90% use case, I'm currently undecided about how exactly this will be implemented. Stay tuned :-)

Also, in case anybody else has any use for this feature, input is very much welcome! 👍

from http.

clue avatar clue commented on May 17, 2024

Closed via #144

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.