The Sol Programming Language!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

server.sol 914B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. http = {
  2. ERRORS = {
  3. [400] = "Bad Request",
  4. [500] = "Server Error",
  5. }
  6. }
  7. NL = '
  8. '
  9. CR = chr(13)
  10. func get_request()
  11. result = {}
  12. httpline = io.stdin:read(io.LINE)
  13. httpline = httpline:split(NL)[0]
  14. httpline = httpline:split(CR)[0]
  15. parts = httpline:split(" ")
  16. if (3 != (#parts)) || (parts[2] != "HTTP/1.1") then
  17. error(400)
  18. end
  19. result.method = parts[0]
  20. result.path = parts[1]
  21. result.protocol = parts[2]
  22. return result
  23. end
  24. out = try(get_request)
  25. success = out[0]
  26. value = out[1]
  27. if success then
  28. print('HTTP/1.1 200 OK
  29. Content-type: text/plain
  30. Hello from Sol! You sent in these values:', value)
  31. else
  32. if type(value) == "int" then
  33. print('HTTP/1.1 ' + tostring(value) + ' ' + (http.ERRORS[value]) + '
  34. Content-type: text/plain
  35. Error ' + tostring(value) + ': ' + (http.ERRORS[value]))
  36. else
  37. print('HTTP/1.1 500 Server Error
  38. Content-type: text/plain
  39. Internal error: ' + tostring(value))
  40. end
  41. end