gock icon indicating copy to clipboard operation
gock copied to clipboard

http2 client mock support

Open ostronom opened this issue 8 years ago • 3 comments

Are there any plans to support http2 transport mocking?

ostronom avatar Apr 10 '17 07:04 ostronom

HTTP/2.0 should be transparently and implicitly supported. gock works at higher level than L7, then no network layer is actually involved.

Are you having any troubles?

h2non avatar Apr 10 '17 07:04 h2non

Yes, i do have trouble with http2 client.

func apnsMatcher(r *http.Request, g *gock.Request) (bool, error) {
	fmt.Printf("URL = %s", r.URL.Path)
	return true, nil
}

gock.New("https://api.push.apple.com").
		AddMatcher(apnsMatcher).
		Persist().
		Reply(200).
		JSON(result)

And when I do request anything at https://api.push.apple.com/some/path using apns2 client (it uses http2 transport), I see nothing in the console.

ostronom avatar Apr 10 '17 08:04 ostronom

Are you using a custom http.Client, instead of http.DefaultClient? In that case, you should instrument gock on it first. See: https://github.com/h2non/gock/blob/master/_examples/custom_client/client_test.go#L18-L20

tomas-fp avatar Apr 10 '17 12:04 tomas-fp