

1. 基础命令执行

```bash
shell2http /top "top -l 1 | head -10" \
           /date "date" \
           /ps "ps aux"
```

2. 环境变量管理

```bash
shell2http -export-all-vars \
  /env 'printenv | sort' \
  /env/path 'echo $PATH' \
  /env/gopath 'echo $GOPATH'

# 导出特定变量
shell2http -export-vars=GOPATH /get 'echo $GOPATH'
```

3. HTML页面生成

```bash
shell2http /cal_html 'echo "<html><body><h1>Calendar</h1>Date: <b>$(date)</b><br><pre>$(cal $(date +%Y))</pre></body></html>"'
```

4. 表单参数处理

```bash
# 处理查询参数 http://localhost:8080/form?from=10&to=100
shell2http -form /form 'echo $v_from, $v_to'
```

5. CGI模式运行

```bash
shell2http -cgi \
  /user_agent 'echo $HTTP_USER_AGENT' \
  /set 'touch file; echo "Location: /another_path\n"' \  # 重定向
  /404 'echo "Status: 404"; echo; echo "404 page"'      # 自定义HTTP状态码
```

6. 文件上传功能

```bash
shell2http -form \
  GET:/form 'echo "<html><body><form method=POST action=/file enctype=multipart/form-data><input type=file name=uplfile><input type=submit></form>"' \
  POST:/file 'cat $filepath_uplfile > uploaded_file.dat; echo Ok'
```

7. HTTP代理服务器

```bash
shell2http -log=/dev/null -cgi / 'echo $REQUEST_URI 1>&2; [ "$REQUEST_METHOD" == "POST" ] && post_param="-d@-"; curl -sL $post_param "$REQUEST_URI" -A "$HTTP_USER_AGENT"'
```

8. 慢速连接测试

```bash
shell2http -form /slow 'sleep ${v_duration:-1}; echo "sleep ${v_duration:-1} seconds"'
```

9. 缓存代理服务器

```bash
shell2http -form \
  /form 'echo "<html><form action=/get>URL: <input name=url><input type=submit>"' \
  /get 'MD5=$(printf "%s" $v_url | md5); cat cache_$MD5 || (curl -sL $v_url | tee cache_$MD5)'
```

10. Mac OS远程音量控制

```bash
shell2http \
  /get 'osascript -e "output volume of (get volume settings)"' \
  /up 'osascript -e "set volume output volume (($(osascript -e "output volume of (get volume settings)")+10))"' \
  /down 'osascript -e "set volume output volume (($(osascript -e "output volume of (get volume settings)")-10))"'
```

11. Vox播放器远程控制（Mac OS）

```bash
shell2http \
  /play_pause 'osascript -e "tell application \"Vox\" to playpause" && echo ok' \
  /get_info 'osascript -e "tell application \"Vox\"" -e "\"Artist: \" & artist & \"\n\" & \"Album: \" & album & \"\n\" & \"Track: \" & track" -e "end tell"'
```

12. JSON API模拟服务

```bash
# 创建JSON文件
echo '{"status": "ok"}' > 1.json

shell2http -cgi \
  /call1 'cat 1.json' \
  /call2 'echo "Content-Type: application/json\n"; echo "{\"error\": \"ok\"}"'
```

13. Windows环境示例

```cmd
shell2http.exe -form /test "echo %v_var%"
```

14. Docker容器运行示例

```dockerfile
# test.Dockerfile
FROM msoap/shell2http
CMD ["/date", "date"]
```

15. SSL/TLS安全连接

```bash
# 生成自签名证书
go run $(go env GOROOT)/src/crypto/tls/generate_cert.go -host localhost

# 运行HTTPS服务器
shell2http -cert=./cert.pem -key=./key.pem /date "date"
```

16. HTTP基本认证

```bash
shell2http -basic-auth="user:password" /secret "echo 'Secret content'"
```
