Skip to content

refactor: avoid http_methods dependency#514

Open
Deepak8858 wants to merge 1 commit intodart-lang:masterfrom
Deepak8858:fix/issue-512-remove-http-methods
Open

refactor: avoid http_methods dependency#514
Deepak8858 wants to merge 1 commit intodart-lang:masterfrom
Deepak8858:fix/issue-512-remove-http-methods

Conversation

@Deepak8858
Copy link
Copy Markdown

Fixes #512

Replaced the external http_methods dependency with a local isHttpMethod implementation in shelf_router and shelf_router_generator to reduce unnecessary external dependencies.

Replaced the external http_methods dependency with a local isHttpMethod
implementation in shelf_router and shelf_router_generator.
@google-cla
Copy link
Copy Markdown

google-cla bot commented Mar 19, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 refactors the shelf_router and shelf_router_generator packages to reduce their reliance on external dependencies. By internalizing the isHttpMethod functionality, the project aims for a more self-contained and potentially lighter codebase, improving maintainability and reducing the external attack surface.

Highlights

  • Dependency Reduction: The external http_methods dependency has been removed from both shelf_router and shelf_router_generator packages.
  • Local Implementation: A local isHttpMethod utility function has been implemented directly within shelf_router/lib/src/router.dart and shelf_router_generator/lib/src/shelf_router_generator.dart to replace the functionality provided by the removed dependency.
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.

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 removes the http_methods dependency by inlining the isHttpMethod function in both shelf_router and shelf_router_generator. While this achieves the goal, it introduces code duplication. My review includes a suggestion to refactor the implementation in shelf_router to use a Set for better readability, and more importantly, to eliminate the code duplication in shelf_router_generator by importing the function from shelf_router, since a dependency already exists. This will improve the maintainability of the code.

Comment on lines +24 to +39
bool isHttpMethod(String method) {
switch (method.toUpperCase()) {
case 'GET':
case 'HEAD':
case 'POST':
case 'PUT':
case 'DELETE':
case 'CONNECT':
case 'OPTIONS':
case 'TRACE':
case 'PATCH':
return true;
default:
return false;
}
}
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

For better readability and maintainability, you could use a Set of HTTP methods for this check. Using a const set is efficient and makes the collection of valid methods explicit and easier to manage.

bool isHttpMethod(String method) {
  const validHttpMethods = <String>{
    'GET',
    'HEAD',
    'POST',
    'PUT',
    'DELETE',
    'CONNECT',
    'OPTIONS',
    'TRACE',
    'PATCH',
  };
  return validHttpMethods.contains(method.toUpperCase());
}

Comment on lines +31 to +47
/// Returns true if [method] is a valid HTTP method.
bool isHttpMethod(String method) {
switch (method.toUpperCase()) {
case 'GET':
case 'HEAD':
case 'POST':
case 'PUT':
case 'DELETE':
case 'CONNECT':
case 'OPTIONS':
case 'TRACE':
case 'PATCH':
return true;
default:
return false;
}
}
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

To avoid code duplication, you should import the isHttpMethod function from the shelf_router package instead of redefining it here. The shelf_router_generator package already has a dependency on shelf_router.

You can remove this function and add the following import at the top of the file:

import 'package:shelf_router/src/router.dart' show isHttpMethod; // ignore: implementation_imports

This follows the existing pattern in this file of importing from shelf_router's src directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid http_methods dependency

2 participants