在项目中经常需要查看被访问的 HTTP 接口携带的 HTTP HEAD 接口.这里我们就可以采用 Whoami 来进行为简单的接收平台.

Hostname: 028c056bf96b
IP: 127.0.0.1
IP: ::1
IP: 192.168.215.5
RemoteAddr: 192.168.215.1:43620
GET / HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Accept-Encoding: gzip, deflate, br, zstd
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
Cache-Control: max-age=0
Connection: keep-alive
Sec-Ch-Ua: "Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"
Sec-Ch-Ua-Mobile: ?0
Sec-Ch-Ua-Platform: "macOS"
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Sec-Fetch-User: ?1
Upgrade-Insecure-Requests: 1

Docker化安装

docker run -idt -p 80:80 --name some-whoami  containous/whoami

使用

Paths
  • /data?size=n[&unit=u]: creates a response with a size n. The unit of measure, if specified, accepts the following values: KB, MB, GB, TB (optional, default: bytes).

  • /echo: webSocket echo.

  • /bench: always return the same response (1).

  • /[?wait=d]: returns the whoami information (request and network information). The optional wait query parameter can be provided to tell the server to wait before sending the response. The duration is expected in Go's time.Duration format (e.g. /?wait=100ms to wait 100 milliseconds).

  • /api: returns the whoami information as JSON.

  • /health: heath check

    • GET, HEAD, ...: returns a response with the status code defined by the POST

    • POST: changes the status code of the GET (HEAD, ...) response.

Flags
  • cert: give me a certificate.

  • key: give me a key.

  • port: give me a port number. (default: 80)

  • name: give me a name. (it can be also defined with WHOAMI_NAME environment variable)