Can httptest be used to test HTTP/2?
Asked Answered
G

2

13

I'm wondering if this (httptest) package can be used to test HTTP/2 specific features.
Can anyone point me to some examples maybe?

I'm aware of the tool h2i, but it's an interactive tool.
I'm looking for something which is programmable.

EDIT:
What I'm really looking for is a tool, where for example I can initiate a server push and test it on the client side.
So, using this package, how do I have access to the underlying HTTP/2 stuff it uses by default?

EDIT 2:
Found some examples in the nghttp2 source: https://github.com/tatsuhiro-t/nghttp2/tree/master/integration-tests

EDIT 3: For me it looks like that the package net/http2 isn't meant to be used directly by anyone. I'll experiment with this one.

Gree answered 22/2, 2016 at 15:46 Comment(5)
If you're on go 1.6, support for HTTP/2 to is transparently added to net/http for HTTPS (and, I suppose, consequently to net/http/httptest too).Democracy
What exactly do you want to do? What are you testing? Like muru said, httptest uses the http package.Stiegler
Following may help you.How to test http calls in go using httptestConservative
This package is built on top of httptest and may interest you.Pigskin
you are using http, not testing http implements.Bakki
E
1

General testing tip (to avoid frustration)!

Don't use Fiddler to test it, it gets in between your browser and the server and breaks the HTTP2 connection.

No HTTP2 - no push.

Earley answered 6/9, 2018 at 1:53 Comment(3)
Do you know if BurpSuite does the same way?Multitude
I’ve never heard of it but I’d imagine anything in between would do the same unless it explicitly says it can handle it. I’d imagine maybe someday fiddler would add http/2 debugging functionality (if they haven’t already). Also everything will still work except for the server push and single connection. So just disable it during testing and use the browser’s network tab to verify push is working.Earley
Thanks for the explanation.Multitude
C
0

https://github.com/summerwind/h2spec is a go program that tests whether a server implementation conforms to RFC 7540. It allows to craft individual HTTP/2 frames such as:

    settings := http2.Setting{http2.SettingInitialWindowSize, 0}
    http2Conn.fr.WriteSettings(settings)

or

    var hp http2.HeadersFrameParam
    hp.StreamID = 1
    hp.EndStream = false
    hp.EndHeaders = true
    hp.BlockFragment = http2Conn.EncodeHeader(hdrs)
    http2Conn.fr.WriteHeaders(hp)
Claudioclaudius answered 21/11, 2016 at 5:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.