methods.es.tst 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. methods.tst - Test misc Http methods
  3. */
  4. const HTTP = tget('TM_HTTP') || "127.0.0.1:8080"
  5. let http: Http = new Http
  6. // Test methods are caseless
  7. http.connect("GeT", HTTP + "/index.html")
  8. ttrue(http.status == 200)
  9. // Put a file
  10. data = Path("test.dat").readString()
  11. http.put(HTTP + "/tmp/test.dat", data)
  12. ttrue(http.status == 201 || http.status == 204)
  13. // Delete
  14. http.connect("DELETE", HTTP + "/tmp/test.dat")
  15. if (http.status != 204) {
  16. print("STATUS IS " + http.status)
  17. }
  18. ttrue(http.status == 204)
  19. // Options
  20. http.connect("OPTIONS", HTTP + "/index.html")
  21. ttrue(http.status == 406)
  22. // ttrue(http.header("Allow") == "DELETE,GET,HEAD,OPTIONS,POST,PUT")
  23. // Trace - should be disabled
  24. http.connect("TRACE", HTTP + "/index.html")
  25. ttrue(http.status == 406)
  26. // Post
  27. http.post(HTTP + "/index.html", "Some data")
  28. ttrue(http.status == 200)
  29. http.get(HTTP + "/index.html")
  30. ttrue(http.status == 200)
  31. // Head
  32. http.connect("HEAD", HTTP + "/index.html")
  33. ttrue(http.status == 200)
  34. ttrue(http.header("Content-Length") > 0)
  35. ttrue(http.response == "")