「nghttp2」の版間の差分

提供: FreeBSD入門
移動: 案内検索
(ページの作成:「nghttp2 とは、 Hypertext Transfer Protocol バージョン 2 (HTTP2, HTTP/2)の実験的な実装です。 '''読み方''' ;nghttp2:えぬじー えいち て...」)
(相違点なし)

2015年4月10日 (金) 00:25時点における版

nghttp2 とは、 Hypertext Transfer Protocol バージョン 2 (HTTP2, HTTP/2)の実験的な実装です。

読み方

nghttp2
えぬじー えいち てぃー てぃーぴー つー

概要

nghttp2 は、HTTP2に対応したC言語ライブラリとサーバプログラムとクライアントプログラムを提供します。

インストール

pkgコマンドでインストールする場合

sudo pkg install nghttp2

インストールされるファイル

nghttp2-0.7.9:
        /usr/local/bin/deflatehd
        /usr/local/bin/h2load
        /usr/local/bin/inflatehd
        /usr/local/bin/nghttp
        /usr/local/bin/nghttpd
        /usr/local/bin/nghttpx
        /usr/local/include/nghttp2/asio_http2.h
        /usr/local/include/nghttp2/asio_http2_client.h
        /usr/local/include/nghttp2/asio_http2_server.h
        /usr/local/include/nghttp2/nghttp2.h
        /usr/local/include/nghttp2/nghttp2ver.h
        /usr/local/lib/libnghttp2.a
        /usr/local/lib/libnghttp2.so
        /usr/local/lib/libnghttp2.so.5
        /usr/local/lib/libnghttp2.so.5.7.2
        /usr/local/libdata/pkgconfig/libnghttp2.pc
        /usr/local/man/man1/h2load.1.gz
        /usr/local/man/man1/nghttp.1.gz
        /usr/local/man/man1/nghttpd.1.gz
        /usr/local/man/man1/nghttpx.1.gz
        /usr/local/share/doc/nghttp2/README.rst
        /usr/local/share/licenses/nghttp2-0.7.9/LICENSE
        /usr/local/share/licenses/nghttp2-0.7.9/MIT
        /usr/local/share/licenses/nghttp2-0.7.9/catalog.mk

コマンド

nghttpのコマンドラインオプション

Usage: nghttp [OPTIONS]... <URI>...
HTTP/2 experimental client
 
  <URI>       Specify URI to access.
Options:
  -v, --verbose
              Print   debug   information   such  as   reception   and
              transmission of frames and name/value pairs.  Specifying
              this option multiple times increases verbosity.
  -n, --null-out
              Discard downloaded data.
  -O, --remote-name
              Save  download  data  in  the  current  directory.   The
              filename is  dereived from URI.   If URI ends  with '/',
              'index.html'  is used  as a  filename.  Not  implemented
              yet.
  -t, --timeout=<SEC>
              Timeout each request after <SEC> seconds.
  -w, --window-bits=<N>
              Sets the stream level initial window size to 2**<N>-1.
  -W, --connection-window-bits=<N>
              Sets  the  connection  level   initial  window  size  to
              2**<N>-1.
  -a, --get-assets
              Download assets  such as stylesheets, images  and script
              files linked  from the downloaded resource.   Only links
              whose  origins are  the same  with the  linking resource
              will be downloaded.   nghttp prioritizes resources using
              HTTP/2 dependency  based priority.  The  priority order,
              from highest to lowest,  is html itself, css, javascript
              and images.
  -s, --stat  Print statistics.
  -H, --header=<HEADER>
              Add a header to the requests.  Example: -H':method: PUT'
  --trailer=<HEADER>
              Add a trailer header to the requests.  <HEADER> must not
              include pseudo header field  (header field name starting
              with ':').  To  send trailer, one must use  -d option to
              send request body.  Example: --trailer 'foo: bar'.
  --cert=<CERT>
              Use  the specified  client certificate  file.  The  file
              must be in PEM format.
  --key=<KEY> Use the  client private key  file.  The file must  be in
              PEM format.
  -d, --data=<FILE>
              Post FILE to server. If '-'  is given, data will be read
              from stdin.
  -m, --multiply=<N>
              Request each URI <N> times.  By default, same URI is not
              requested twice.  This option disables it too.
  -u, --upgrade
              Perform HTTP Upgrade for HTTP/2.  This option is ignored
              if the request URI has https scheme.  If -d is used, the
              HTTP upgrade request is performed with OPTIONS method.
  -p, --weight=<WEIGHT>
              Sets priority group weight.  The valid value range is
              [1, 256], inclusive.
              Default: 16
  -M, --peer-max-concurrent-streams=<N>
              Use  <N>  as  SETTINGS_MAX_CONCURRENT_STREAMS  value  of
              remote endpoint as if it  is received in SETTINGS frame.
              The default is large enough as it is seen as unlimited.
  -c, --header-table-size=<SIZE>
              Specify decoder header table size.
  -b, --padding=<N>
              Add at  most <N>  bytes to a  frame payload  as padding.
              Specify 0 to disable padding.
  -r, --har=<FILE>
              Output HTTP  transactions <FILE> in HAR  format.  If '-'
              is given, data is written to stdout.
  --color     Force colored log output.
  --continuation
              Send large header to test CONTINUATION.
  --no-content-length
              Don't send content-length header field.
  --no-dep    Don't send dependency based priority hint to server.
  --dep-idle  Use idle streams as anchor nodes to express priority.
  --hexdump   Display the  incoming traffic in  hexadecimal (Canonical
              hex+ASCII display).  If SSL/TLS  is used, decrypted data
              are used.
  --version   Display version information and exit.
  -h, --help  Display this help and exit.
 
  The <SIZE> argument is an integer and an optional unit (e.g., 10K is
  10 * 1024).  Units are K, M and G (powers of 1024).

nghttpdのコマンドラインオプション

Usage: nghttpd [OPTION]... <PORT> [<PRIVATE_KEY> <CERT>]
HTTP/2 experimental server
 
  <PORT>      Specify listening port number.
  <PRIVATE_KEY>
              Set  path  to  server's private  key.   Required  unless
              --no-tls is specified.
  <CERT>      Set  path  to  server's  certificate.   Required  unless
              --no-tls is specified.
Options:
  -a, --address=<ADDR>
              The address to bind to.  If not specified the default IP
              address determined by getaddrinfo is used.
  -D, --daemon
              Run in a background.  If -D is used, the current working
              directory is  changed to '/'.  Therefore  if this option
              is used, -d option must be specified.
  -V, --verify-client
              The server  sends a client certificate  request.  If the
              client did  not return  a certificate, the  handshake is
              terminated.   Currently,  this  option just  requests  a
              client certificate and does not verify it.
  -d, --htdocs=<PATH>
              Specify document root.  If this option is not specified,
              the document root is the current working directory.
  -v, --verbose
              Print debug information  such as reception/ transmission
              of frames and name/value pairs.
  --no-tls    Disable SSL/TLS.
  -c, --header-table-size=<SIZE>
              Specify decoder header table size.
  --color     Force colored log output.
  -p, --push=<PATH>=<PUSH_PATH,...>
              Push  resources <PUSH_PATH>s  when <PATH>  is requested.
              This option  can be used repeatedly  to specify multiple
              push  configurations.    <PATH>  and   <PUSH_PATH>s  are
              relative  to   document  root.   See   --htdocs  option.
              Example: -p/=/foo.png -p/doc=/bar.css
  -b, --padding=<N>
              Add at  most <N>  bytes to a  frame payload  as padding.
              Specify 0 to disable padding.
  -n, --workers=<N>
              Set the number of worker threads.
              Default: 1
  -e, --error-gzip
              Make error response gzipped.
  --dh-param-file=<PATH>
              Path to file that contains  DH parameters in PEM format.
              Without  this   option,  DHE   cipher  suites   are  not
              available.
  --early-response
              Start sending response when request HEADERS is received,
              rather than complete request is received.
  --trailer=<HEADER>
              Add a trailer  header to a response.   <HEADER> must not
              include pseudo header field  (header field name starting
              with ':').  The  trailer is sent only if  a response has
              body part.  Example: --trailer 'foo: bar'.
  --hexdump   Display the  incoming traffic in  hexadecimal (Canonical
              hex+ASCII display).  If SSL/TLS  is used, decrypted data
              are used.
  --version   Display version information and exit.
  -h, --help  Display this help and exit.
 
  The <SIZE> argument is an integer and an optional unit (e.g., 10K is
  10 * 1024).  Units are K, M and G (powers of 1024).

使い方

サーバサイド

echo 'Hello HTTP2' > index.html
$ nghttpd -v --no-tls 8080
IPv6: listen :::8080
IPv4: listen 0.0.0.0:8080
[id=1] [  6.597] send SETTINGS frame <length=6, flags=0x00, stream_id=0>
          (niv=1)
          [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
[id=1] [  6.597] recv SETTINGS frame <length=12, flags=0x00, stream_id=0>
          (niv=2)
          [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
          [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
[id=1] [  6.597] recv (stream_id=1) :method: GET
[id=1] [  6.597] recv (stream_id=1) :path: /
[id=1] [  6.597] recv (stream_id=1) :scheme: http
[id=1] [  6.597] recv (stream_id=1) :authority: localhost:8080
[id=1] [  6.597] recv (stream_id=1) accept: */*
[id=1] [  6.597] recv (stream_id=1) accept-encoding: gzip, deflate
[id=1] [  6.597] recv (stream_id=1) user-agent: nghttp2/0.7.9
[id=1] [  6.597] recv HEADERS frame <length=33, flags=0x05, stream_id=1>
          ; END_STREAM | END_HEADERS
          (padlen=0)
          ; Open new stream
[id=1] [  6.597] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>
          ; ACK
          (niv=0)
[id=1] [  6.597] send SETTINGS frame <length=0, flags=0x01, stream_id=0>
          ; ACK
          (niv=0)
[id=1] [  6.597] send HEADERS frame <length=82, flags=0x04, stream_id=1>
          ; END_HEADERS
          (padlen=0)
          ; First response header
          :status: 200
          server: nghttpd nghttp2/0.7.9
          content-length: 38
          cache-control: max-age=3600
          date: Thu, 09 Apr 2015 15:20:54 GMT
          last-modified: Thu, 09 Apr 2015 15:20:36 GMT
[id=1] [  6.597] send DATA frame <length=38, flags=0x01, stream_id=1>
          ; END_STREAM
[id=1] [  6.597] stream_id=1 closed
[id=1] [  6.598] recv GOAWAY frame <length=8, flags=0x00, stream_id=0>
          (last_stream_id=0, error_code=NO_ERROR(0x00), opaque_data(0)=[])
[id=1] [  6.598] closed

クライアント

$ nghttp http://localhost:8080
Hello HTTP2
薫 $ nghttp -v http://localhost:8080
[  0.001] Connected
[  0.001] 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.001] send HEADERS frame <length=33, flags=0x05, stream_id=1>
          ; END_STREAM | END_HEADERS
          (padlen=0)
          ; Open new stream
          :method: GET
          :path: /
          :scheme: http
          :authority: localhost:8080
          accept: */*
          accept-encoding: gzip, deflate
          user-agent: nghttp2/0.7.9
[  0.001] recv SETTINGS frame <length=6, flags=0x00, stream_id=0>
          (niv=1)
          [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
[  0.001] send SETTINGS frame <length=0, flags=0x01, stream_id=0>
          ; ACK
          (niv=0)
[  0.002] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>
          ; ACK
          (niv=0)
[  0.002] recv (stream_id=1) :status: 200
[  0.002] recv (stream_id=1) server: nghttpd nghttp2/0.7.9
[  0.002] recv (stream_id=1) content-length: 38
[  0.002] recv (stream_id=1) cache-control: max-age=3600
[  0.002] recv (stream_id=1) date: Thu, 09 Apr 2015 15:22:36 GMT
[  0.002] recv (stream_id=1) last-modified: Thu, 09 Apr 2015 15:20:36 GMT
[  0.002] recv HEADERS frame <length=82, flags=0x04, stream_id=1>
          ; END_HEADERS
          (padlen=0)
          ; First response header
Hello HTTP2
[  0.002] recv DATA frame <length=38, flags=0x01, stream_id=1>
          ; END_STREAM
[  0.002] send GOAWAY frame <length=8, flags=0x00, stream_id=0>
          (last_stream_id=0, error_code=NO_ERROR(0x00), opaque_data(0)=[])


サーバサイド

$ nghttpd -v --no-tls 8080
IPv6: listen :::8080
IPv4: listen 0.0.0.0:8080
[id=1] [ 34.155] send SETTINGS frame <length=6, flags=0x00, stream_id=0>
          (niv=1)
          [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
[id=1] [ 34.156] recv SETTINGS frame <length=12, flags=0x00, stream_id=0>
          (niv=2)
          [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
          [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
[id=1] [ 34.156] recv (stream_id=1) :method: GET
[id=1] [ 34.156] recv (stream_id=1) :path: /
[id=1] [ 34.156] recv (stream_id=1) :scheme: http
[id=1] [ 34.156] recv (stream_id=1) :authority: localhost:8080
[id=1] [ 34.156] recv (stream_id=1) accept: */*
[id=1] [ 34.156] recv (stream_id=1) accept-encoding: gzip, deflate
[id=1] [ 34.156] recv (stream_id=1) user-agent: nghttp2/0.7.9
[id=1] [ 34.156] recv HEADERS frame <length=33, flags=0x05, stream_id=1>
          ; END_STREAM | END_HEADERS
          (padlen=0)
          ; Open new stream
[id=1] [ 34.157] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>
          ; ACK
          (niv=0)
[id=1] [ 34.157] send SETTINGS frame <length=0, flags=0x01, stream_id=0>
          ; ACK
          (niv=0)
[id=1] [ 34.157] send HEADERS frame <length=62, flags=0x04, stream_id=1>
          ; END_HEADERS
          (padlen=0)
          ; First response header
          :status: 404
          server: nghttpd nghttp2/0.7.9
          date: Thu, 09 Apr 2015 15:18:04 GMT
          content-type: text/html; charset=UTF-8
[id=1] [ 34.157] send DATA frame <length=126, flags=0x01, stream_id=1>
          ; END_STREAM
[id=1] [ 34.157] stream_id=1 closed
[id=1] [ 34.158] recv GOAWAY frame <length=8, flags=0x00, stream_id=0>
          (last_stream_id=0, error_code=NO_ERROR(0x00), opaque_data(0)=[])
[id=1] [ 34.158] closed

クライアント

$ nghttp http://localhost:8080
404

404


nghttpd nghttp2/0.7.9 at port 8080
%

関連項目