badUrl.es.tst 581 B

123456789101112131415161718192021222324252627
  1. /*
  2. badUrl.tst - Stress test malformed URLs
  3. */
  4. const HTTP = tget('TM_HTTP') || "127.0.0.1:8080"
  5. let http: Http = new Http
  6. let caught
  7. try {
  8. /* Http.get will throw exception for a bad url */
  9. http.get(HTTP + "/index\x01.html")
  10. } catch {
  11. caught = true
  12. }
  13. ttrue(caught)
  14. http.close()
  15. // Bypass http to send the request to the server
  16. let s = new Socket
  17. s.connect(HTTP)
  18. s.write("GET /index\x01.html HTTP/1.0\r\n\r\n")
  19. let response = new ByteArray
  20. while ((n = s.read(response, -1)) != null) {}
  21. let r = response.toString()
  22. ttrue(r.contains('400 Bad Request'))
  23. s.close()