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

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

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

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

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

if(System args size != 2) then(
  HTTPStatusMap foreach(key, line,
    value := key .. " " .. line
    value println
  )
) else(
  arg1 := System args at(1)
  if(arg1 size == 3,
    HTTPStatusMap foreach(key, line,
      if(key == arg1,
        value := key .. " " .. line
        value println
      ) elseif(true,
        res := line containsSeq(arg1)
        if(res,
          value := key .. " " .. line
          value println
        )
      )
    )
  ) else(
    HTTPStatusMap foreach(key, line,
      if(key exSlice(0, arg1 size) containsSeq(arg1),
        value := key .. " " .. line
        value println
      )
    )
  )
)

総括

iolanguageは標準でRegExpがなかったり、やり方知らないだけかもしれないけど、無名関数を渡せない。