Search code examples
ctestinghttp2

Simple tool to test my h2c implementation


As a part of my studies, I decided to write an HTTP/2 server that is capable of simply serving static files. I have to write it in C, which I have very little experience with, so I decided to go with h2c (uses TCP), not h2 (uses TLS). I need some tool to test my server, but I cannot use neither Chrome, nor Firefox, because both of them support only h2.

What is the easiest way to test my server? Maybe there is some h2c implementation for other language, like python or js (node), where I can quickly assemble a test client?

I still consider implementing h2, if nothing comes up, but after looking at this OpenSSL TLS client example, I am sort of scared, because it's only a simple GET and its size is 4 times the code I have written so far.


Solution

  • Since you work in C, you can use nghttp2 to test your h2c implementation.

    I just tried it against a Jetty HTTP/2 server, and this is the output:

    $ nghttp -v http://localhost:8080
    [  0.000] send SETTINGS frame <length=12, flags=0x00, stream_id=0>
          (niv=2)
          [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
          [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
    [  0.000] send HEADERS frame <length=33, flags=0x05, stream_id=1>
          ; END_STREAM | END_HEADERS
          (padlen=0)
          ; Open new stream
          :authority: localhost:8080
          :method: GET
          :path: /
          :scheme: http
          accept: */*
          accept-encoding: gzip, deflate
          user-agent: nghttp2/0.6.7
    [  0.104] recv SETTINGS frame <length=12, flags=0x00, stream_id=0>
          (niv=2)
          [SETTINGS_HEADER_TABLE_SIZE(0x01):4096]
          [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
    [  0.104] send SETTINGS frame <length=0, flags=0x01, stream_id=0>
          ; ACK
          (niv=0)
    [  0.105] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>
          ; ACK
          (niv=0)
    [  0.121] recv (stream_id=1, noind=0) :status: 200
    [  0.121] recv (stream_id=1, noind=0) server: Jetty(9.3.z-SNAPSHOT)
    [  0.121] recv (stream_id=1, noind=0) date: Wed, 17 Feb 2016 19:11:17 GMT
    [  0.121] recv (stream_id=1, noind=0) custom: Value
    [  0.121] recv (stream_id=1, noind=0) content-type: text/plain
    [  0.121] recv (stream_id=1, noind=0) content-length: 72
    [  0.121] recv HEADERS frame <length=70, flags=0x04, stream_id=1>
          ; END_HEADERS
          (padlen=0)
          ; First response header
    Hello from Jetty using HTTP/2.0
    uri=/
    date=Wed Feb 17 20:11:17 CET 2016
    [  0.121] recv DATA frame <length=72, flags=0x01, stream_id=1>
          ; END_STREAM
    [  0.121] send GOAWAY frame <length=8, flags=0x00, stream_id=0>
          (last_stream_id=0, error_code=NO_ERROR(0x00), opaque_data(0)=[])