Node.jsで、HTTP のステータスコードをすばやくしらべる!
これ以上短くできるかなぁ?
追記: やっぱり Object.key で回さなくて素直に for in ですかねぇ。(前の消しました)
#!/usr/bin/env node var a = process.argv[2]; var o = require('http').STATUS_CODES; for(var k in o) { if (!a || !k.indexOf(a) || o[k].indexOf(a) > -1) console.log(k, o[k]); }
結果
> ./httpstatus.js 4 400 Bad Request 401 Unauthorized 402 Payment Required 403 Forbidden 404 Not Found 405 Method Not Allowed 406 Not Acceptable 407 Proxy Authentication Required 408 Request Time-out 409 Conflict 410 Gone 411 Length Required 412 Precondition Failed 413 Request Entity Too Large 414 Request-URI Too Large 415 Unsupported Media Type 416 Requested Range Not Satisfiable 417 Expectation Failed 418 I'm a teapot 422 Unprocessable Entity 423 Locked 424 Failed Dependency 425 Unordered Collection 426 Upgrade Required 428 Precondition Required 429 Too Many Requests 431 Request Header Fields Too Large
> ./httpstatus.js 500 500 Internal Server Error
> ./httpstatus.js Bad 400 Bad Request 502 Bad Gateway