Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added note about async non-goal #31

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions proposed/http-client/http-client-meta.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ client will allow libraries to be decoupled from an implementation such as Guzzl
specify the default behaviours.
* The purpose is not to be opinionated about the use of middlewares (PSR-15).

#### Asynchronous HTTP client

The reason asynchronous support is a non-goal is because a PSR for HTTP clients
should not define Promises. That should be a separate PSR. Waiting for a such PSR
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should define neither promises nor an async-compatible version of PSR-7

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you tell me why PSR-7 is not async?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, because getContents() requires blocking, as does __toString().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is an implementation detail. ;)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's not. Blocking is an absolute no-go in fully async apps.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nowhere in the PSR-7 specification does it say that getContents has to use __toString. (In fact getContents and __toString has different behaviours. ) Nor does it say that it has to be blocking.

Im saying that you can implement PSR-7 with non-blocking. It is not a limitation in the interface but in the implementations.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course it doesn't say it has to be blocking, as that's the default for any IO operation in PHP. It has to be blocking, because the interface requires an immediate return on a call to these methods.

Im saying that you can implement PSR-7 with non-blocking.

Could you try to elaborate how that should be possible? See what React did.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @Nyholm here, the text LGTM and the discussion whether PSR-7 can be used in an async context is both an implementation detail and out of scope here 👍

(@kelunik IMO the last link adds little value here and its motivation is better described in the documentation (https://github.com/reactphp/http#request), rather than the code. As an alternative, PSR-7 does not prevent you from buffering the whole message in memory, in which case all accessors can be used perfectly fine even in an async program 👍)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clue It doesn't really matter as an async client is out of scope in any way, regardless of the wording here.

I completely understand the motivation behind that, but it doesn't really matter either. If it could be implemented sanely, I'm pretty sure you guys would have done that. It doesn't prevent buffering, of course not, but we both know that it doesn't fit for all bodies and is the exact reason why the request body isn't represented as a string, but a stream.

would delay the HTTP client PSR.

A separate interface for asynchronous requests can be defined in a separate PSR
once the promise PSR is accepted. The method signature for asynchronous requests
has to be different.

## Approaches

Expand Down