1 var sys = require("util")
2 , assert = require("assert")
3 , XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest
4 , http = require("http")
8 var server = http.createServer(function (req, res) {
9 // Check request method and URL
10 assert.equal(methods[curMethod], req.method);
11 assert.equal("/" + methods[curMethod], req.url);
13 var body = (req.method != "HEAD" ? "Hello World" : "");
16 "Content-Type": "text/plain",
17 "Content-Length": Buffer.byteLength(body)
20 if (req.method != "HEAD") {
25 if (curMethod == methods.length - 1) {
31 // Test standard methods
32 var methods = ["GET", "POST", "HEAD", "PUT", "DELETE"];
35 function start(method) {
37 xhr = new XMLHttpRequest();
39 xhr.onreadystatechange = function() {
40 if (this.readyState == 4) {
41 if (method == "HEAD") {
42 assert.equal("", this.responseText);
44 assert.equal("Hello World", this.responseText);
49 if (curMethod < methods.length) {
50 sys.puts("Testing " + methods[curMethod]);
51 start(methods[curMethod]);
56 var url = "http://localhost:8000/" + method;
57 xhr.open(method, url);
61 sys.puts("Testing " + methods[curMethod]);
62 start(methods[curMethod]);