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

Decouple from HTTP::Server::Context #49

Merged
merged 2 commits into from
Jul 15, 2024

Conversation

Blacksmoke16
Copy link
Contributor

This PR does a bit of a refactor to decouple an exception page from a HTTP::Server::Context, making it more flexible. E.g. for use in frameworks where that object is not directly available, but all the required information is.

Opening this is a draft to allow time for discussion before moving forward:

  • Cookies, headers, and params are now proper HTTP::* types vs hashes
  • Added HTTP::Status as an ivar
  • Dropped @query ivar in favor of @params
    • @query was simply @params.to_s
  • Constructors changed a bit
    • Dropped .for_runtime_exception in favor of .new
    • Dropped an overload with the context, message, title, and frames

Resolves #48

@@ -47,7 +47,7 @@ class MyErrorHandler
raise SomeError.new("Something went wrong")
rescue e
context.response.status_code = 500
context.response.print MyApp::ExceptionPage.for_runtime_exception(context, e).to_s
context.response.print MyApp::ExceptionPage.new context, e
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to call to_s on this since response.print will do it automatically?

Copy link
Contributor Author

@Blacksmoke16 Blacksmoke16 Apr 20, 2024

Choose a reason for hiding this comment

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

Correct, with the added benefit of not having to load the entire string into memory since I'm pretty sure it'll be written directly to the response IO.

I.e. https://crystal-lang.org/reference/1.12/guides/performance.html#dont-create-intermediate-strings-when-writing-to-an-io

@jwoertink
Copy link
Contributor

I like the concept. Seems straight forward. Let's ping @crimson-knight and @sdogruyol too since Kemal and Amber also use this and see if they have any thoughts.

Copy link

@crimson-knight crimson-knight left a comment

Choose a reason for hiding this comment

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

Would this be considered a breaking change?

It doesn't appear to be, and I think it makes sense.

@Blacksmoke16
Copy link
Contributor Author

Blacksmoke16 commented Apr 22, 2024

It definitely is a breaking change. Two of the constructor overload's signatures changed, an ivar was removed, and the expected type of some constructor args changed. So anyone using those overloads or ivar in custom template wouldn't work.

@jwoertink
Copy link
Contributor

Yeah, Lucky for sure would need to be re-worked, but thankfully I don't think it would really be a "user" facing breaking change in terms of devs building (Lucky) apps.

@Blacksmoke16 Blacksmoke16 marked this pull request as ready for review June 6, 2024 14:59
@Blacksmoke16
Copy link
Contributor Author

Not sure who has review/merging rights in this repo, but bump.

Copy link
Contributor

@jwoertink jwoertink left a comment

Choose a reason for hiding this comment

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

My bad, forgot to come back to this 😅 I think it's good. Maybe instead of doing a patch bump, we just make it a minor bump just to make sure it doesn't break too many things

@jwoertink jwoertink merged commit 32ef885 into crystal-loot:master Jul 15, 2024
4 checks passed
@Blacksmoke16 Blacksmoke16 deleted the decouple branch July 15, 2024 17:34
stakach added a commit to spider-gazelle/action-controller that referenced this pull request Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Decouple from HTTP:ServerContext
3 participants