WireMock.Net icon indicating copy to clipboard operation
WireMock.Net copied to clipboard

How to use HTTP2 - for grpc

Open sergioprates opened this issue 5 years ago • 8 comments

Hi, In wiremock, since release 2.25.0 has support to make http2 request, but I don't found instructions to do it with WireMock.net. Bellow is the link from release. Is it supported by WireMock.NET? Would be nice if does.

https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!searchin/wiremock-user/http$2F2%7Csort:date/wiremock-user/bxG2-yb-u-Y/YlRq94niBQAJ

sergioprates avatar Apr 10 '20 15:04 sergioprates

I did not add any code specific for http2, so I don't know if this works. I need to check.

StefH avatar Apr 10 '20 16:04 StefH

@StefH were you ever able to look into the HTTP/2 support (I'm particularly interested in simulating a gRPC api)

kharabasz avatar Dec 14 '20 11:12 kharabasz

From a preliminary look - It is possible to add support for Http2 in the Aspnetcore path by mutating the Protocols on the ListenerOptions. It is not as simple as setting Http1OrHttp2 as there are valid use cases for both that option and Http2 which leads me to think that Protocols should be bubbled up as an option on the WireMockServer.

For example (from Microsoft's gRPC docs):

When an HTTP/2 endpoint is configured without TLS, the endpoint's ListenOptions.Protocols must be set to HttpProtocols.Http2. HttpProtocols.Http1AndHttp2 can't be used because TLS is required to negotiate HTTP/2. Without TLS, all connections to the endpoint default to HTTP/1.1, and gRPC calls fail.

I am currently figuring out how to mock gRPC once HTTP2 support is enabled. I think it could work if I had access to return an HttpResponseMessage...

kharabasz avatar Dec 14 '20 20:12 kharabasz

To get mocking to work ResponseMessage would require some changes to support TrailingHeaders and support for stream bodies or HttpContent - this would require a fair bit of extension.

kharabasz avatar Dec 14 '20 20:12 kharabasz

Thanks for your investigation.

However, this is not yet on my prio list for now.

StefH avatar Dec 15 '20 19:12 StefH

I looked into this as well. For now, the best approach is probably to use Mountebank server with a Mountebank-grpc plug-in (written in JavaScript) and C# MbDotNet client library. This is obviously a lot of dependencies just to test grpc, but such is life with Google products in my experience: lots and lots of seemingly unnecessary dependencies. - Note: I don't plan to even bother with this as I know my teammates will ridicule me for introducing so many dependencies for stub testing one grpc service one vendor uses.

jzabroski avatar Apr 19 '23 14:04 jzabroski

I created a proxy generator that converts GRPC requests to HTTP and forwards them to WireMock. You might give it a shot. Any feedback you can give me is welcome. The project is available here https://github.com/cezarypiatek/GRPC-Mock-Server

cezarypiatek avatar Jun 07 '23 20:06 cezarypiatek

@jzabroski @kharabasz @sergioprates

See https://github.com/WireMock-Net/WireMock.Net/discussions/1045

StefH avatar Dec 29 '23 08:12 StefH

It's implemented. See also https://mstack.nl/blogs/wiremock-net-grpc/

StefH avatar Mar 12 '24 18:03 StefH