Skip to content

feature: Refine HttpStatus and HttpContent with additional utility methods#329

Merged
xerial merged 3 commits intomainfrom
feature/http-refine-methods
Jan 18, 2026
Merged

feature: Refine HttpStatus and HttpContent with additional utility methods#329
xerial merged 3 commits intomainfrom
feature/http-refine-methods

Conversation

@xerial
Copy link
Copy Markdown
Member

@xerial xerial commented Jan 18, 2026

Summary

  • Add static classification methods to HttpStatus companion object (isUnknownState, isInformational, isSuccessful, isRedirection, isClientError, isServerError) for use without creating HttpStatus instances
  • Add isUnknownState instance method to detect invalid status codes (< 100 or >= 600)
  • Improve Other case reason phrases with category context (e.g., "Unknown 5xx (550)" instead of "Other(550)")
  • Add direct value accessors to HttpContent: toContentString, toContentBytes, and contentHash

Test plan

  • All existing tests pass
  • Added tests for static classification methods
  • Added tests for isUnknownState method
  • Added tests for improved Other reason phrases
  • Added tests for toContentString, toContentBytes, contentHash on all HttpContent types

🤖 Generated with Claude Code

…thods

Add static classification methods to HttpStatus companion object for use
without creating instances, add isUnknownState method, and improve Other
case reason phrases with category context. Enhance HttpContent with
toContentString, toContentBytes, and contentHash methods for direct
value access.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the feature New feature label Jan 18, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @xerial, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the HttpStatus and HttpContent utilities by introducing new methods that enhance usability and provide more robust handling of HTTP-related data. The changes aim to simplify common operations like status code classification and content retrieval, making the API more convenient and explicit for developers by offering direct accessors and clearer status code interpretations.

Highlights

  • HttpStatus Enhancements: Introduced static classification methods (e.g., isSuccessful, isClientError) to the HttpStatus companion object, allowing status code checks without requiring an instance.
  • Unknown HttpStatus Detection: Added an isUnknownState instance method to HttpStatus for identifying invalid or out-of-range status codes (less than 100 or greater than or equal to 600).
  • Improved Other HttpStatus Reasons: Enhanced the reason phrases for HttpStatus.Other cases to include category context (e.g., "Unknown 5xx (550)" instead of "Other(550)").
  • HttpContent Direct Accessors: Added toContentString, toContentBytes, and contentHash methods to the HttpContent trait and its implementations for direct, non-Option based content access and hashing.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces several useful utility methods to HttpContent and HttpStatus, along with comprehensive tests. The changes are well-implemented. My review includes a couple of suggestions for HttpStatus.scala to improve code clarity and reduce duplication, making the code more maintainable.

Comment on lines +97 to +111
code match
case c if c < 100 =>
s"Unknown (${code})"
case c if c < 200 =>
s"Unknown 1xx (${code})"
case c if c < 300 =>
s"Unknown 2xx (${code})"
case c if c < 400 =>
s"Unknown 3xx (${code})"
case c if c < 500 =>
s"Unknown 4xx (${code})"
case c if c < 600 =>
s"Unknown 5xx (${code})"
case _ =>
s"Unknown (${code})"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The match expression for generating the reason phrase for Other status codes can be simplified. Using integer division for codes between 100 and 599 can make the logic more concise and easier to read.

        code match
          case c if c >= 100 && c < 600 =>
            s"Unknown ${c / 100}xx (${code})"
          case _ =>
            s"Unknown (${code})"

Comment on lines +114 to +119
def isInformational: Boolean = code >= 100 && code < 200
def isSuccessful: Boolean = code >= 200 && code < 300
def isRedirection: Boolean = code >= 300 && code < 400
def isClientError: Boolean = code >= 400 && code < 500
def isServerError: Boolean = code >= 500 && code < 600
def isUnknownState: Boolean = code < 100 || code >= 600
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

There's some code duplication between the new static classification methods in the HttpStatus companion object and the corresponding instance methods. To follow the Don't Repeat Yourself (DRY) principle, the instance methods can be updated to call the static methods, centralizing the classification logic.

  def isInformational: Boolean = HttpStatus.isInformational(code)
  def isSuccessful: Boolean    = HttpStatus.isSuccessful(code)
  def isRedirection: Boolean   = HttpStatus.isRedirection(code)
  def isClientError: Boolean   = HttpStatus.isClientError(code)
  def isServerError: Boolean   = HttpStatus.isServerError(code)
  def isUnknownState: Boolean  = HttpStatus.isUnknownState(code)

- Use integer division for Other case reason phrase generation
- Instance classification methods now delegate to static methods

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the doc Improvements or additions to documentation label Jan 18, 2026
@xerial xerial enabled auto-merge (squash) January 18, 2026 22:20
@xerial xerial merged commit 406c3a0 into main Jan 18, 2026
10 checks passed
@xerial xerial deleted the feature/http-refine-methods branch January 18, 2026 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Improvements or additions to documentation feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant