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 more clear specification. #944

Merged
merged 8 commits into from Nov 20, 2017
Merged

Conversation

Nyholm
Copy link
Member

@Nyholm Nyholm commented Oct 22, 2017

Im trying to address @joelwurtz comment and part of php-http#34

response. When there is an error during sending the request or an error with network an
exception should be thrown.
response. The HTTP client MAY modify the response from the server before returning
the PSR-7 response.
Copy link
Member

Choose a reason for hiding this comment

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

Something like this (minus typo ^^) would be better IMO:

"The HTTP client MAY modify the request, given by the user and sent to the server or the response from the server before returning. In this case the request and the response must be consistent between the body and headers. I.e. a server may return a gzip encoded body and the client may know how to decode this, when it decodes the body the client MUST also remove the header that specify this encoding."

Copy link
Member

Choose a reason for hiding this comment

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

if this is what we mean by this, then yes lets give this example to illustrate what we actually mean.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you.

Copy link
Member

@dbu dbu left a comment

Choose a reason for hiding this comment

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

thank you!

response. When there is an error during sending the request or an error with network an
exception should be thrown.
response. The HTTP client MAY modify the response from the server before returning
the PSR-7 response.
Copy link
Member

Choose a reason for hiding this comment

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

if this is what we mean by this, then yes lets give this example to illustrate what we actually mean.

the server or the response from the server before returning. In this case the
request and the response must be consistent between the body and headers. I.e. a
server may return a gzip encoded body and the client may know how to decode this,
when it decodes the body the client MUST also remove the header that specify this
Copy link
Member

Choose a reason for hiding this comment

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

i think this line mixes singular and plural. either "remove the headers that specify" or "remove the header that specifies". i think the second makes more sense, the encoding example would have just one header.

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks

Copy link
Member

@dbu dbu left a comment

Choose a reason for hiding this comment

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

thank you!

@@ -12,8 +12,12 @@ interpreted as described in [RFC 2119](http://tools.ietf.org/html/rfc2119).
### Client

An HTTP client has the responsibility to send a PSR-7 request and return a PSR-7
response. The HTTP client MAY modify the response from the server before returning
the PSR-7 response.
response. The HTTP client MAY modify the request, given by the user and sent to
Copy link
Member

Choose a reason for hiding this comment

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

"Under the hood the HTTP client MAY modify the request/response received from the user/server."

How does that sound?

This part tries to make it clear that under the contract surface anything could happen to request/response objects and there is no assurance that they will remain the same objects on the instance level, right?

the PSR-7 response.
response. The HTTP client MAY modify the request, given by the user and sent to
the server or the response from the server before returning. In this case the
request and the response must be consistent between the body and headers. I.e. a
Copy link
Member

Choose a reason for hiding this comment

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

I.e. -> "For example," ?

the server or the response from the server before returning. In this case the
request and the response must be consistent between the body and headers. I.e. a
server may return a gzip encoded body and the client may know how to decode this,
when it decodes the body the client MUST also remove the header that specify this
Copy link
Member

Choose a reason for hiding this comment

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

specify the encoding?

Copy link
Member

@sagikazarmark sagikazarmark left a comment

Choose a reason for hiding this comment

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

Sorry, chose the wrong option, see my outdated comments above.

`Psr\Http\Client\Exception\RequestException`.

When there is an error with the network or the remote server cannot be reached, the
HTTP client SHOULD thrown a `Psr\Http\Client\Exception\NetworkException`. If the
Copy link
Member

Choose a reason for hiding this comment

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

thrown -> throw

Generally as a rule, SHOULD is recommended against as it cannot be relied upon by a client anymore. Is there rationale as to why this isn't a MUST?

Copy link
Member

Choose a reason for hiding this comment

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

in some circumstances it might be difficult to know what kind of error happened. there will probably always be some fuzzyness around the exception type. however, we are specific as to which things cause a network exception, so i think MUST should be fine here.

Copy link
Member

Choose a reason for hiding this comment

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

can you fix the thrown throw please?

ok if we say MUST here?

exception should be thrown.
response. The HTTP client MAY modify the request, given by the user and sent to
the server or the response from the server before returning. In this case the
request and the response must be consistent between the body and headers. I.e. a
Copy link
Member

Choose a reason for hiding this comment

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

I.e. doesn't make much sense in this context. Perhaps use For example instead.

the server or the response from the server before returning. In this case the
request and the response must be consistent between the body and headers. I.e. a
server may return a gzip encoded body and the client may know how to decode this,
when it decodes the body the client MUST also remove the header that specifies this
Copy link
Member

Choose a reason for hiding this comment

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

using a MUST inside an example doesn't make much sense. Suggestion:
and the client may know how to decode this, however the client should then also mutate the headers that specify the encoding

Copy link
Member

Choose a reason for hiding this comment

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

hm, the MUST is important here. should we move that out of the example to say that if the client modifies the request or response, it MUST also adjust the headers accordingly? (i'd assume that if it gzips a request, it must also adjust the content-length header, for example)

Copy link
Member

Choose a reason for hiding this comment

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

👍

server may return a gzip encoded body and the client may know how to decode this,
when it decodes the body the client MUST also remove the header that specifies this
when it decodes the body the client MUST also remove the header that specifies the
encoding.
Copy link
Member

@joelwurtz joelwurtz Nov 15, 2017

Choose a reason for hiding this comment

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

and update the content length header. (cf @dbu comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you

Copy link
Member

@dbu dbu left a comment

Choose a reason for hiding this comment

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

if we add the section about when to throw exceptions, should we also say here to not throw exceptions for any http status?

`Psr\Http\Client\Exception\RequestException`.

When there is an error with the network or the remote server cannot be reached, the
HTTP client MUST thrown a `Psr\Http\Client\Exception\NetworkException`. If the
Copy link
Member

Choose a reason for hiding this comment

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

s/thrown/throw

When there is an error with the network or the remote server cannot be reached, the
HTTP client MUST thrown a `Psr\Http\Client\Exception\NetworkException`. If the
request is invalid and cannot be sent the HTTP client MUST throw a
`Psr\Http\Client\Exception\RequestException`. Smaller issues like wrong HTTP version
Copy link
Member

Choose a reason for hiding this comment

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

i would swap the 2 points, so they are more in order of when they happen (invalid request is detected first, network problem only later)

It SHOULD implement exceptions for `Psr\Http\Client\Exception\NetworkException` and
`Psr\Http\Client\Exception\RequestException`.

When there is an error with the network or the remote server cannot be reached, the
Copy link
Member

Choose a reason for hiding this comment

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

what about an invalid response, should we mention that here? like not proper http or such.

@Nyholm
Copy link
Member Author

Nyholm commented Nov 17, 2017

Thank you @dbu

Copy link
Member

@dbu dbu left a comment

Choose a reason for hiding this comment

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

thanks for the updates. now i only have nitpick comments left ;-)

It SHOULD implement exceptions for `Psr\Http\Client\Exception\NetworkException` and
`Psr\Http\Client\Exception\RequestException`.

When the client get a request that is invalid and cannot be sent, the HTTP client
Copy link
Member

Choose a reason for hiding this comment

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

When the HTTP client is passed a request that ... sent , the client

Smaller issues like wrong HTTP version is not blocking the HTTP client to send the
request and MUST not cause any exception.

No exception should be thrown if the remote server answers with an response that can
Copy link
Member

Choose a reason for hiding this comment

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

If the remote server answers with a response that can be parsed into a PSR-7 response, the client MUST NOT throw an exception. For example, response status codes in the 400 and 500 range MUST NOT cause an exception.

@Nyholm
Copy link
Member Author

Nyholm commented Nov 17, 2017

Thank you!

Copy link
Member

@dbu dbu left a comment

Choose a reason for hiding this comment

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

thank you. i am happy now.

@michaelcullum @sagikazarmark what do you think of this now? (as your status on this is "request changes")

@Nyholm
Copy link
Member Author

Nyholm commented Nov 20, 2017

I've addressed their issues. Im merging this to move forward. Feel free to open issues or PRs to make additional changes.

@Nyholm Nyholm merged commit 17b6378 into php-fig:master Nov 20, 2017
@Nyholm Nyholm deleted the specification branch November 20, 2017 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants