Project

General

Profile

repr.diff

How to reproduce - stepancheg, 2008-12-24 17:44

View differences:

src/mod_uploadprogress.c Fri Dec 19 01:26:54 2008 +0300 → src/mod_uploadprogress.c Wed Dec 24 15:47:14 2008 +0300
477 477
			return HANDLER_FINISHED;
478 478
		}
479 479

  
480
		if (post_con_entry->con == con) {
481
			TRACE("post_con_entry->con: %d, con: %d", post_con_entry->con, con);
482
			exit(1);
483
		}
484

  
480 485
		buffer_copy_string_len(b, CONST_STR_LEN("new Object({ 'state' : "));
481 486

  
482 487
		if (post_con_entry->status == 413) {
/dev/null Thu Jan 01 00:00:00 1970 +0000 → testing/get.py Wed Dec 24 15:47:14 2008 +0300
1
#!/usr/bin/python
2

  
3
import sys
4
import httplib
5
import time
6

  
7
print sys.argv
8

  
9
host = '127.0.0.1:10103'
10
#uuid = sys.argv[1]
11
uuid_list = ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb')
12
k = 0
13

  
14
while (1 == 1):
15
	uuid = uuid_list[k]
16
	print uuid
17
	h = httplib.HTTP(host)
18
	h.putrequest('GET', '/progress');
19
	h.putheader('X-ProgRess-ID', uuid)
20
	h.endheaders()
21

  
22
	returncode, returnmsg, headers = h.getreply()
23
	
24
#	print "returncode = "+ str(returncode)
25
#	print returnmsg
26
#	print headers	
27

  
28
	print time.localtime()
29
	
30
	if returncode == 200:
31
		f = h.getfile()
32
		print f.read()
33
		print "_____"
34

  
35
	time.sleep(1)
36
	k = 1-k
/dev/null Thu Jan 01 00:00:00 1970 +0000 → testing/l.conf Wed Dec 24 15:47:14 2008 +0300
1
server.document-root  =  "/home/ayvlasov/up_assert/ayvlasov/temp/www"
2
server.upload-dirs    = ("/home/ayvlasov/up_assert/ayvlasov/temp/www/tmp")
3
#server.network-backend = "write"
4
#server.errorlog      = "/home/ayvlasov/upfail/throughput/temp/test_reset_and_close.log"
5

  
6
server.port = 10103
7

  
8
server.modules = (
9
	"mod_access",
10
	"mod_accesslog",
11
	"mod_cgi",
12
	"mod_uploadprogress",
13
)
14

  
15

  
16
upload-progress.progress-url = "/progress"
17
upload-progress.debug = "enable"
18
upload-progress.remove-timeout = 4
19

  
20
#post_to_disk.tmp-dir = "/home/ayvlasov/upfail/throughput/temp/www/tmp"
21
#post_to_disk.done-dir = "/home/ayvlasov/upfail/throughput/temp/www/done"
22
#post_to_disk.failed-dir = "/home/ayvlasov/upfail/throughput/temp/www/failed"
23
#post_to_disk.response-content = "application-xml"
24

  
25
index-file.names = ("index.html", "index.py", "index.htm", "default.htm")
26

  
27
static-file.exclude-extensions = (".php", ".py", ".fcgi")
28

  
29
cgi.assign = (".py" => "/usr/bin/python", ".cgi" => "/usr/bin/python") #, ".php" => "/usr/bin/php-cgi")
30

  
31
debug.log-request-header   = "enable"
32
debug.log-response-header  = "enable"
33
debug.log-request-handling = "enable"
34
#debug.log-state-handling = "enable"
35
debug.log-file-not-found   = "enable"
36

  
37
mimetype.assign = (
38
	".html" => "text/html",
39
	".txt"  => "text/plain",
40
	".jpg"  => "image/jpeg",
41
	".png"  => "image/png"
42
)
/dev/null Thu Jan 01 00:00:00 1970 +0000 → testing/up.html Wed Dec 24 15:47:14 2008 +0300
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
<html xmlns="http://www.w3.org/1999/xhtml">
3
<head>
4
 <title>/dev/null</title>
5
 <script type="text/javascript">
6
  interval = null;
7
  interval_msec = 10;
8
  last_received = 0;
9
  is_zero = 0;
10
  is_started = 0;
11
  time_since_start = 0;
12
  last_ts = 0;
13
  file_size = 0;
14

  
15
  function fetch(uuid) {
16
    time_since_start += interval_msec;
17
    if (is_started) return;
18
    req = false;
19
    // basic object checking - forked from apple's xhr docs
20
    // branch for native XMLHttpRequest object
21
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
22
      try {
23
        req = new XMLHttpRequest();
24
      } catch(e) {
25
        req = false;
26
      }
27
    // branch for IE/Windows ActiveX version
28
    } else if(window.ActiveXObject) {
29
      try {
30
        req = new ActiveXObject("Msxml2.XMLHTTP");
31
      } catch(e) {
32
        try {
33
          req = new ActiveXObject("Microsoft.XMLHTTP");
34
        } catch(e) {
35
          req = false;
36
        } 
37
      }
38
    }
39
    if(!req) return;
40

  
41
    req.open("GET", "/progress", 1);
42
    req.setRequestHeader("X-Progress-Id", uuid);
43
    req.onreadystatechange = function () {
44
      if (!req) {
45
        window.clearTimeout(interval);
46
        return;
47
      }
48

  
49
      if (req.readyState == 1) {
50
        /** 
51
	* we might have 2 requests running at the same time if the connection
52
	* is very slow
53
	*/
54
        is_started = 1;
55
      } else if (req.readyState == 4) {
56
        is_started = 0;
57
        if (req.status == 200) {
58
          /* poor-man JSON parser */
59
          var upload = eval(req.responseText);
60

  
61
	  if (upload.state == 'error') {
62
	    document.getElementById('tp').innerHTML = "upload failed with status 413, file is too large";
63
	  } else if (upload.size == 0) {
64
            window.clearTimeout(interval);
65

  
66
	    upload.size = file_size;
67
	    upload.received = file_size;
68
	  }
69

  
70
	  if (!file_size) file_size = upload.size;
71

  
72
          suffix = "";
73
	  delta_bytes = upload.received - last_received;
74
	  last_received = upload.received;
75
	  if (delta_bytes) {
76
	    is_zero = 0;
77
	    throughput = delta_bytes / (time_since_start - last_ts) * 1000;
78
	    last_ts = time_since_start;
79
	  
80
	    left_bytes = upload.size - upload.received;
81
            left_time = left_bytes / throughput;
82
            
83
            if (throughput > 10240) { throughput /= 1024; suffix = "k"; }
84
            if (throughput > 10240) { throughput /= 1024; suffix = "M"; }
85
            
86
            document.getElementById('tp').innerHTML = sprintf("%s: %.2f %sBytes/sec, est. time: %.2fsec",
87
	      upload.state, throughput, suffix, left_time);
88
	  } else {
89
	    is_zero++;
90

  
91
	    if (is_zero > 10) {
92
              document.getElementById('tp').innerHTML = "no progress since 10 polls, looks like you canceled the upload";
93
              window.clearTimeout(interval);
94
	    }
95
	  }
96
 
97
          /* change the width if the inner progress-bar */
98
          if (upload.state == 'done') {
99
            bar = document.getElementById('progressbar');
100
            w = 400;
101
            bar.style.width = w + 'px';
102
	  } else if (upload.state == 'uploading') {
103
            bar = document.getElementById('progressbar');
104
            w = 400 * upload.received / upload.size;
105
            bar.style.width = w + 'px';
106
          }
107
          /* we are done, stop the interval */
108
          if (upload.state == 'done' || upload.state == 'error') {
109
            window.clearTimeout(interval);
110
          }
111
        } else {
112
          window.clearTimeout(interval);
113
	}
114
      } else {
115
        /** 
116
	* debugging, track the progress  */
117
        document.getElementById('tp').innerHTML = "req.readyState is " + req.readyState;
118
      }
119
    }
120
    req.send(null);
121
  }
122

  
123
  function openProgressBar() {
124
    /* generate random progress-id */
125
    uuid = "";
126
    for (i = 0; i < 32; i++) {
127
    /*  uuid += Math.floor(Math.random() * 16).toString(16);*/
128
	uuid += "a";
129
    }
130
    /* patch the form-action tag to include the progress-id */
131
    document.getElementById("upload").action="/up.html?X-Progress-ID=" + uuid;
132
    document.getElementById('tp').innerHTML = "uuid is " + uuid;
133

  
134
/*    interval = window.setInterval(
135
      function () {
136
        fetch(uuid);
137
      },
138
      interval_msec
139
    );*/
140
  }
141

  
142
 </script>
143
</head>
144
<body>
145
 <form id="upload" enctype="multipart/form-data" action="/up.html" method="post" target="uploadframe"
146
          onsubmit="openProgressBar(); return true;">
147
  <input name="userfile" type="file" label="fileupload" />
148
  <input type="submit" value="Send File" />
149
 </form>
150
<iframe id="uploadframe" name="uploadframe" width="0" height="0" frameborder="0" border="0" src="about:blank"></iframe>
151
 <div>
152
  <div id="progress" style="width: 400px; border: 1px solid black">
153
   <div id="progressbar" 
154
       style="width: 1px; background-color: black; border: 1px solid white">
155
     &nbsp;
156
   </div>
157
  </div>
158
  <div id="tp">(throughput)</div>
159
 </div>
160
</body>
161
</html>
/dev/null Thu Jan 01 00:00:00 1970 +0000 → testing/upb.html Wed Dec 24 15:47:14 2008 +0300
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
<html xmlns="http://www.w3.org/1999/xhtml">
3
<head>
4
 <title>/dev/null</title>
5
 <script type="text/javascript">
6
  interval = null;
7
  interval_msec = 10;
8
  last_received = 0;
9
  is_zero = 0;
10
  is_started = 0;
11
  time_since_start = 0;
12
  last_ts = 0;
13
  file_size = 0;
14

  
15
  function fetch(uuid) {
16
    time_since_start += interval_msec;
17
    if (is_started) return;
18
    req = false;
19
    // basic object checking - forked from apple's xhr docs
20
    // branch for native XMLHttpRequest object
21
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
22
      try {
23
        req = new XMLHttpRequest();
24
      } catch(e) {
25
        req = false;
26
      }
27
    // branch for IE/Windows ActiveX version
28
    } else if(window.ActiveXObject) {
29
      try {
30
        req = new ActiveXObject("Msxml2.XMLHTTP");
31
      } catch(e) {
32
        try {
33
          req = new ActiveXObject("Microsoft.XMLHTTP");
34
        } catch(e) {
35
          req = false;
36
        } 
37
      }
38
    }
39
    if(!req) return;
40

  
41
    req.open("GET", "/progress", 1);
42
    req.setRequestHeader("X-Progress-Id", uuid);
43
    req.onreadystatechange = function () {
44
      if (!req) {
45
        window.clearTimeout(interval);
46
        return;
47
      }
48

  
49
      if (req.readyState == 1) {
50
        /** 
51
	* we might have 2 requests running at the same time if the connection
52
	* is very slow
53
	*/
54
        is_started = 1;
55
      } else if (req.readyState == 4) {
56
        is_started = 0;
57
        if (req.status == 200) {
58
          /* poor-man JSON parser */
59
          var upload = eval(req.responseText);
60

  
61
	  if (upload.state == 'error') {
62
	    document.getElementById('tp').innerHTML = "upload failed with status 413, file is too large";
63
	  } else if (upload.size == 0) {
64
            window.clearTimeout(interval);
65

  
66
	    upload.size = file_size;
67
	    upload.received = file_size;
68
	  }
69

  
70
	  if (!file_size) file_size = upload.size;
71

  
72
          suffix = "";
73
	  delta_bytes = upload.received - last_received;
74
	  last_received = upload.received;
75
	  if (delta_bytes) {
76
	    is_zero = 0;
77
	    throughput = delta_bytes / (time_since_start - last_ts) * 1000;
78
	    last_ts = time_since_start;
79
	  
80
	    left_bytes = upload.size - upload.received;
81
            left_time = left_bytes / throughput;
82
            
83
            if (throughput > 10240) { throughput /= 1024; suffix = "k"; }
84
            if (throughput > 10240) { throughput /= 1024; suffix = "M"; }
85
            
86
            document.getElementById('tp').innerHTML = sprintf("%s: %.2f %sBytes/sec, est. time: %.2fsec",
87
	      upload.state, throughput, suffix, left_time);
88
	  } else {
89
	    is_zero++;
90

  
91
	    if (is_zero > 10) {
92
              document.getElementById('tp').innerHTML = "no progress since 10 polls, looks like you canceled the upload";
93
              window.clearTimeout(interval);
94
	    }
95
	  }
96
 
97
          /* change the width if the inner progress-bar */
98
          if (upload.state == 'done') {
99
            bar = document.getElementById('progressbar');
100
            w = 400;
101
            bar.style.width = w + 'px';
102
	  } else if (upload.state == 'uploading') {
103
            bar = document.getElementById('progressbar');
104
            w = 400 * upload.received / upload.size;
105
            bar.style.width = w + 'px';
106
          }
107
          /* we are done, stop the interval */
108
          if (upload.state == 'done' || upload.state == 'error') {
109
            window.clearTimeout(interval);
110
          }
111
        } else {
112
          window.clearTimeout(interval);
113
	}
114
      } else {
115
        /** 
116
	* debugging, track the progress  */
117
        document.getElementById('tp').innerHTML = "req.readyState is " + req.readyState;
118
      }
119
    }
120
    req.send(null);
121
  }
122

  
123
  function openProgressBar() {
124
    /* generate random progress-id */
125
    uuid = "";
126
    for (i = 0; i < 32; i++) {
127
    /*  uuid += Math.floor(Math.random() * 16).toString(16);*/
128
	uuid += "b";
129
    }
130
    /* patch the form-action tag to include the progress-id */
131
    document.getElementById("upload").action="/up.html?X-Progress-ID=" + uuid;
132
    document.getElementById('tp').innerHTML = "uuid is " + uuid;
133

  
134
/*    interval = window.setInterval(
135
      function () {
136
        fetch(uuid);
137
      },
138
      interval_msec
139
    );*/
140
  }
141

  
142
 </script>
143
</head>
144
<body>
145
 <form id="upload" enctype="multipart/form-data" action="/up.html" method="post" target="uploadframe"
146
          onsubmit="openProgressBar(); return true;">
147
  <input name="userfile" type="file" label="fileupload" />
148
  <input type="submit" value="Send File" />
149
 </form>
150
<iframe id="uploadframe" name="uploadframe" width="0" height="0" frameborder="0" border="0" src="about:blank"></iframe>
151
 <div>
152
  <div id="progress" style="width: 400px; border: 1px solid black">
153
   <div id="progressbar" 
154
       style="width: 1px; background-color: black; border: 1px solid white">
155
     &nbsp;
156
   </div>
157
  </div>
158
  <div id="tp">(throughput)</div>
159
 </div>
160
</body>
161
</html>