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

Add all HTTP methods to route when the method is empty #2570

Merged
merged 5 commits into from
Mar 11, 2020

Conversation

minwoox
Copy link
Contributor

@minwoox minwoox commented Mar 11, 2020

Motivation:
Check out this code:

sb.decorator((delegate, ctx, req) -> {
    System.err.println(2);
    return delegate.serve(ctx, req);
});
sb.routeDecorator().pathPrefix("/").build((delegate, ctx, req) -> {
    System.err.println(1);
    return delegate.serve(ctx, req);
});
sb.decoratorUnder("/", (delegate, ctx, req) -> {
    System.err.println(3);
    return delegate.serve(ctx, req);
});

The executed order of decorators are a little messed becuase routeDecorator() has all HttpMethods set, but others don't.
If we set HttpMethods.knownMethods() when there's no method set for a route, the execution order of decorator will be the order they inserted.

Modifications:

  • Add HttpMethod.knownMethods() to the Route if it's empty.
    • However, the logger name and metric don't include it because it's verbose.

Result:

  • Right decoration order.

Motivation:
Check out this code:
```java
sb.decorator((delegate, ctx, req) -> {
    System.err.println(2);
    return delegate.serve(ctx, req);
});
sb.routeDecorator().pathPrefix("/").build((delegate, ctx, req) -> {
    System.err.println(1);
    return delegate.serve(ctx, req);
});
sb.decoratorUnder("/", (delegate, ctx, req) -> {
    System.err.println(3);
    return delegate.serve(ctx, req);
});
```
The executed order of decorators are a little messed becuase `routeDecorator()` has all `HttpMethod`s set, but others don't.
If we set `HttpMethods.knownMethods()` when there's no method set for a route, the execution order of decorator will be the order they inserted.

Modifications:
- Add `HttpMethod.knownMethods()` to the `Route` if it's empty.
  - However, the logger name and metric don't include it because it's verbose.

Result:
- Right decoration order.
@minwoox minwoox added the defect label Mar 11, 2020
@minwoox minwoox added this to the 0.99.0 milestone Mar 11, 2020
@minwoox minwoox requested review from ikhoon and trustin as code owners March 11, 2020 09:05
@codecov
Copy link

codecov bot commented Mar 11, 2020

Codecov Report

Merging #2570 into master will decrease coverage by 0.02%.
The diff coverage is 91.66%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2570      +/-   ##
============================================
- Coverage      73.4%   73.38%   -0.03%     
+ Complexity    10942    10933       -9     
============================================
  Files           957      958       +1     
  Lines         42146    42098      -48     
  Branches       5276     5261      -15     
============================================
- Hits          30938    30894      -44     
- Misses         8496     8505       +9     
+ Partials       2712     2699      -13
Impacted Files Coverage Δ Complexity Δ
...c/main/java/com/linecorp/armeria/server/Route.java 100% <ø> (ø) 2 <0> (ø) ⬇️
...main/java/com/linecorp/armeria/server/Routers.java 86.54% <ø> (-0.24%) 53 <0> (-1)
...java/com/linecorp/armeria/server/RouteBuilder.java 81.89% <100%> (+0.15%) 52 <0> (+1) ⬆️
...n/java/com/linecorp/armeria/common/HttpMethod.java 100% <100%> (ø) 4 <0> (ø) ⬇️
...java/com/linecorp/armeria/server/DefaultRoute.java 94.73% <88.88%> (-1.35%) 71 <0> (-3)
...om/linecorp/armeria/client/HttpSessionHandler.java 62.2% <0%> (-11.03%) 30% <0%> (-4%)
.../com/linecorp/armeria/client/ClientDecoration.java 81.81% <0%> (-8.19%) 13% <0%> (ø)
.../com/linecorp/armeria/server/RoutingPredicate.java 69.35% <0%> (-1.62%) 20% <0%> (-1%)
...a/common/grpc/protocol/ArmeriaMessageDeframer.java 71.21% <0%> (-1.47%) 46% <0%> (-2%)
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f0afb37...e6c8b53. Read the comment docs.

Copy link
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

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

Thanks, @minwoox !

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

Thanks!

@trustin trustin merged commit cf243d1 into line:master Mar 11, 2020
@minwoox minwoox deleted the add_all_methods branch March 12, 2020 01:33
fmguerreiro pushed a commit to fmguerreiro/armeria that referenced this pull request Sep 19, 2020
Motivation:
Check out this code:
```java
sb.decorator((delegate, ctx, req) -> {
    System.err.println(2);
    return delegate.serve(ctx, req);
});
sb.routeDecorator().pathPrefix("/").build((delegate, ctx, req) -> {
    System.err.println(1);
    return delegate.serve(ctx, req);
});
sb.decoratorUnder("/", (delegate, ctx, req) -> {
    System.err.println(3);
    return delegate.serve(ctx, req);
});
```
The executed order of decorators are a little messed becuase `routeDecorator()` has all `HttpMethod`s set, but others don't.
If we set `HttpMethods.knownMethods()` when there's no method set for a route, the execution order of decorator will be the order they inserted.

Modifications:
- Add `HttpMethod.knownMethods()` to the `Route` if it's empty.
  - However, the logger name and metric don't include it because it's verbose.

Result:
- Right decoration order.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants