読者です 読者をやめる 読者になる 読者になる

Retry: httpstatusコマンドで、HTTPのステータスコードをすばやくしらべる!

一般的な Web Programmer ならば、HTTP Status code はすべて暗記していると聞きました。

しかし、僕は初心者なので、なかなか覚えきれていないので、HTTPのステータスコードをさがすのに便利なツールを用意しました。 httpstatus.ioです。Io処理系で動かせば動きます。

HTTPStatusList := List clone
HTTPStatusList append(List clone append("100", "Continue"))
HTTPStatusList append(List clone append("101", "Switching Protocols"))
HTTPStatusList append(List clone append("102", "Processing"))
HTTPStatusList append(List clone append("200", "OK"))
HTTPStatusList append(List clone append("201", "Created"))
HTTPStatusList append(List clone append("202", "Accepted"))
HTTPStatusList append(List clone append("203", "Non-Authoritative Information"))
HTTPStatusList append(List clone append("204", "No Content"))
HTTPStatusList append(List clone append("205", "Reset Content"))
HTTPStatusList append(List clone append("206", "Partial Content"))
HTTPStatusList append(List clone append("207", "Multi-Status"))
HTTPStatusList append(List clone append("208", "Already Reported"))
HTTPStatusList append(List clone append("300", "Multiple Choices"))
HTTPStatusList append(List clone append("301", "Moved Permanently"))
HTTPStatusList append(List clone append("302", "Found"))
HTTPStatusList append(List clone append("303", "See Other"))
HTTPStatusList append(List clone append("304", "Not Modified"))
HTTPStatusList append(List clone append("305", "Use Proxy"))
HTTPStatusList append(List clone append("307", "Temporary Redirect"))
HTTPStatusList append(List clone append("400", "Bad Request"))
HTTPStatusList append(List clone append("401", "Unauthorized"))
HTTPStatusList append(List clone append("402", "Payment Required"))
HTTPStatusList append(List clone append("403", "Forbidden"))
HTTPStatusList append(List clone append("404", "Not Found"))
HTTPStatusList append(List clone append("405", "Method Not Allowed"))
HTTPStatusList append(List clone append("406", "Not Acceptable"))
HTTPStatusList append(List clone append("407", "Proxy Authentication Required"))
HTTPStatusList append(List clone append("408", "Request Timeout"))
HTTPStatusList append(List clone append("409", "Conflict"))
HTTPStatusList append(List clone append("410", "Gone"))
HTTPStatusList append(List clone append("411", "Length Required"))
HTTPStatusList append(List clone append("412", "Precondition Failed"))
HTTPStatusList append(List clone append("413", "Request Entity Too Large"))
HTTPStatusList append(List clone append("414", "Request-URI Too Large"))
HTTPStatusList append(List clone append("415", "Unsupported Media Type"))
HTTPStatusList append(List clone append("416", "Request Range Not Satisfiable"))
HTTPStatusList append(List clone append("417", "Expectation Failed"))
HTTPStatusList append(List clone append("418", "I'm a teapot"))
HTTPStatusList append(List clone append("422", "Unprocessable Entity"))
HTTPStatusList append(List clone append("423", "Locked"))
HTTPStatusList append(List clone append("424", "Failed Dependency"))
HTTPStatusList append(List clone append("425", "No code"))
HTTPStatusList append(List clone append("426", "Upgrade Required"))
HTTPStatusList append(List clone append("428", "Precondition Required"))
HTTPStatusList append(List clone append("429", "Too Many Requests"))
HTTPStatusList append(List clone append("431", "Request Header Fields Too Large"))
HTTPStatusList append(List clone append("449", "Retry with"))
HTTPStatusList append(List clone append("500", "Internal Server Error"))
HTTPStatusList append(List clone append("501", "Not Implemented"))
HTTPStatusList append(List clone append("502", "Bad Gateway"))
HTTPStatusList append(List clone append("503", "Service Unavailable"))
HTTPStatusList append(List clone append("504", "Gateway Timeout"))
HTTPStatusList append(List clone append("505", "HTTP Version Not Supported"))
HTTPStatusList append(List clone append("506", "Variant Also Negotiates"))
HTTPStatusList append(List clone append("507", "Insufficient Storage"))
HTTPStatusList append(List clone append("509", "Bandwidth Limit Exceeded"))
HTTPStatusList append(List clone append("510", "Not Extended"))
HTTPStatusList append(List clone append("511", "Network Authentication Required"))

showStatus := method(
  validator := call evalArgAt(0)
  HTTPStatusList foreach(key, s,
     if(validator call(s),
      (s join(" ")) println
    )
  )
)
main := method(
 if(System args size != 2) then(
   showStatus(block(s, true))
 ) else (
   arg1 := System args at(1)
   if(arg1 asNumber isNan) then(
     showStatus(block(s, if (s at(1) containsSeq(arg1), true, false)))
   ) else (
     showStatus(block(s, if (s at(0) exSlice(0, arg1 size) containsSeq(arg1), true, false)))
   )
 )
)

main

Retry


oh.../(^o^)\

先日書いた自分のコードが糞コードだったので書き直しです。id:ymotongpooさんのコードをリスペクトしています。

改善点

  • Iolanguageではmethod()でクロージャを実現することはどうやら無理そうです。block()を使えば容易に実現できることを理解しました。ただしmethod()と違いblock()はcallメッセージで呼び出さないといけません。
  • 関数をblock()またはmethod()に渡した場合はcall evalArgAtを使うことによって渡された関数を取得できます。
  • IolanguageのMapはorderedmapではないので、Listを使います。

一言

自分が糞だから糞コードを公開してた...。猛省。