-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Replace #status_code with #status #7247
Conversation
When starting with a fresh PR, could you please squash the commits into logical pieces (probably similar to your bullet points)? That makes it much easier to review and follow the individual changes. Thanks 👍 |
Update some relevant specs Fix method call Update expectations Convert class to enum Revert to hard-coded messages Actually revert to class method Fix overload implementation Rename StatusCode to Status
Flip methdos back to instance methods Actually flip methods Update more uses Rename #message to #description
Update file comment Co-Authored-By: dwightwatson <[email protected]> Replace #status_code with #status Update OAuth2::Client
This looks good! There is however still an issue with creating a new # Create a new `HTTP::Status` instance from *status_code* number.
# The values are not limited to defined enum members, but also allow to use custom status codes. Any number in the range 100..999 is allowed.
def HTTP::Status.from_code(status_code : Int32)
raise "Invalid status code" unless 100 <= status_code <= 999
new(status_code)
end
|
status_message = pieces[2]? ? pieces[2].chomp : "" | ||
|
||
body_type = HTTP::BodyType::OnDemand | ||
body_type = HTTP::BodyType::Mandatory if mandatory_body?(status_code) | ||
body_type = HTTP::BodyType::Mandatory if mandatory_body?(status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could move this method to a body_mandatory?
in the HTTP::Status
enum (it could be done in a separate PR).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to tackle that one separately.
In light of #7266 suggest to rename NOTE: Implementing this needs a very recent compiler build from master. |
Co-Authored-By: dwightwatson <[email protected]>
@straight-shoota Do you mean replace And is this the sort of implementation you'd expect - defining def self.new(status_code : Int32)
raise ArgumentError.new("Invalid HTTP status code: #{status_code}") unless 100 <= status_code <= 999
previous_def(status_code)
end |
Seems like the tests fail now (but work fine locally). Do the tests not run with a fresh build of Crystal? |
Specs must pass with latest compiler release and a fresh build from current master. This is to ensure every compiler release can be build with the previous one. |
@dwightwatson I notice you are already merging from master. Once you make the CI happy we need a 👍 from @asterite / @RX14 before saquash merging this PR. Thanks! |
Needs a rebase to make CI (with Crystal 0.27.1) green. |
Back to green now, please let me know if there is anything more I can do to get this merged in. |
Btw, is this GTG already? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are ready to (squash) merge this PR.
With the current status I don't think there is a breaking-change, am I wrong?
@bcardiff |
@bcardiff It also changes it from a number to an enum (once you rename |
@asterite but |
@bcardiff It currently removes the public |
@bcardiff You are right, sorry for the confusion |
Thank you @dwightwatson ❤️ |
This is a follow-up to #7231 but broken out into another PR because the direction changed a bit from the discussion over there - thought it might be wise in case that direction is reversed. This basically introduces a number of breaking changes:
#status_code
on the response object is replaced with#status
which is an instance ofHTTP::Status
. It encapsulates everything needed to do with HTTP status codes.HTTP.default_status_message_for
was replaced by theHTTP::Status
object'sdescription
and it will now returnnil
instead of an empty string when it doesn't have an answer.status_code=
if you like, and it will be mapped under the hood to an instance ofHTTP::Status
.*
HTTP::Status
has#code
so can callstatus.code
to get the integer value instead of needing to know to callstatus.value
.Open to more guidance and feedback here. Hope it's going in the direction you'd like to see - there were a lot of comments on the last PR and I've tried to take it all into consideration.