WireMock-Net / WireMock.Net

WireMock.Net is a flexible product for stubbing and mocking web HTTP responses using advanced request matching and response templating. Based on the functionality from http://WireMock.org, but extended with more functionality.
Apache License 2.0
1.41k stars 209 forks source link

How to use HTTP2 - for grpc #450

Closed sergioprates closed 7 months ago

sergioprates commented 4 years ago

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

StefH commented 4 years ago

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

kharabasz commented 3 years ago

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

kharabasz commented 3 years ago

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 commented 3 years ago

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.

StefH commented 3 years ago

Thanks for your investigation.

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

jzabroski commented 1 year ago

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.

cezarypiatek commented 1 year ago

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

StefH commented 10 months ago

@jzabroski @kharabasz @sergioprates

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

StefH commented 7 months ago

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