Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Commit

Permalink
closes #30
Browse files Browse the repository at this point in the history
  • Loading branch information
Adven27 committed Feb 17, 2022
1 parent dda1962 commit 767b33a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Stability: Maintenance](https://masterminds.github.io/stability/maintenance.svg)](https://masterminds.github.io/stability/maintenance.html)
[![Docker Cloud Build Status](https://img.shields.io/docker/cloud/build/adven27/grpc-wiremock?label=build&logo=docker)](https://hub.docker.com/repository/docker/adven27/grpc-wiremock/builds)
[![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/adven27/grpc-wiremock/1.3.4?logo=docker)](https://hub.docker.com/repository/docker/adven27/grpc-wiremock/general)
[![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/adven27/grpc-wiremock/1.3.6?logo=docker)](https://hub.docker.com/repository/docker/adven27/grpc-wiremock/general)

# Overview
grpc-wiremock is a **mock server** for **GRPC** services implemented as a wrapper around the [WireMock](http://wiremock.org) http server.
Expand Down Expand Up @@ -71,19 +71,19 @@ Stubbing should be done via [WireMock JSON API](http://wiremock.org/docs/stubbin

Default error (not `200 OK`) mapping is based on https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto :

| HTTP Status Code | GRPC Status |
| ------------------------ |:-----------------:|
| 400 Bad Request | INVALID_ARGUMENT |
| 401 Unauthorized | UNAUTHENTICATED |
| 403 Forbidden | PERMISSION_DENIED |
| 404 Not Found | NOT_FOUND |
| 409 Conflict | ALREADY_EXISTS |
| 429 Too Many Requests | RESOURCE_EXHAUSTED|
| 499 Client Closed Request| CANCELLED |
| 500 Internal Server Error| INTERNAL |
| 501 Not Implemented | UNIMPLEMENTED |
| 503 Service Unavailable | UNAVAILABLE |
| 504 Gateway Timeout | DEADLINE_EXCEEDED |
| HTTP Status Code | GRPC Status |
|---------------------------|:-------------------|
| 400 Bad Request | INVALID_ARGUMENT |
| 401 Unauthorized | UNAUTHENTICATED |
| 403 Forbidden | PERMISSION_DENIED |
| 404 Not Found | NOT_FOUND |
| 409 Conflict | ALREADY_EXISTS |
| 429 Too Many Requests | RESOURCE_EXHAUSTED |
| 499 Client Closed Request | CANCELLED |
| 500 Internal Server Error | INTERNAL |
| 501 Not Implemented | UNIMPLEMENTED |
| 503 Service Unavailable | UNAVAILABLE |
| 504 Gateway Timeout | DEADLINE_EXCEEDED |

And could be overridden or augmented by overriding or augmenting the following properties:
```yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,25 @@
import static java.util.stream.Collectors.toMap;

public class HeaderPropagationInterceptor implements ServerInterceptor {
public static final String X_GRPC_FULL_METHOD_NAME = "x-grpc-full-method-name";
public static final Context.Key<Map<String, String>> HEADERS = Context.key("GRPC_WIREMOCK_HEADERS");
private static final BaseEncoding BASE64_ENCODING_OMIT_PADDING = BaseEncoding.base64().omitPadding();

@Override
public <Req, Resp> ServerCall.Listener<Req> interceptCall(ServerCall<Req, Resp> call, final Metadata headers, ServerCallHandler<Req, Resp> next) {
return Contexts.interceptCall(
Context.current().withValue(HEADERS, asMap(headers)),
Context.current().withValue(HEADERS, enriched(asMap(headers), call)),
call,
headers,
next
);
}

private Map<String, String> enriched(Map<String, String> map, ServerCall call) {
map.put(X_GRPC_FULL_METHOD_NAME, call.getMethodDescriptor().getFullMethodName());
return map;
}

private Map<String, String> asMap(Metadata headers) {
return headers.keys().stream().collect(
toMap(
Expand Down

0 comments on commit 767b33a

Please sign in to comment.