[Toss-devel-svn] SF.net SVN: toss:[1695] trunk/Toss
Status: Beta
Brought to you by:
lukaszkaiser
|
From: <luk...@us...> - 2012-03-16 01:52:31
|
Revision: 1695
http://toss.svn.sourceforge.net/toss/?rev=1695&view=rev
Author: lukaszkaiser
Date: 2012-03-16 01:52:25 +0000 (Fri, 16 Mar 2012)
Log Message:
-----------
Use gzip-compressed js files in TossServer.
Modified Paths:
--------------
trunk/Toss/Client/.cvsignore
trunk/Toss/Client/Makefile
trunk/Toss/Client/index.html
trunk/Toss/Makefile
trunk/Toss/Server/Server.ml
Property Changed:
----------------
trunk/Toss/Client/
Property changes on: trunk/Toss/Client
___________________________________________________________________
Modified: svn:ignore
- # We are still using .cvsignore files as we find them easier to manage
# than svn properties. Therefore if you change .cvsignore do the following.
# svn propset svn:ignore -F .cvsignore .
JsHandler.js
clientTestRender*.png
*~
+ # We are still using .cvsignore files as we find them easier to manage
# than svn properties. Therefore if you change .cvsignore do the following.
# svn propset svn:ignore -F .cvsignore .
JsHandler.js
clientTestRender*.png
*.js.gz
*~
Modified: trunk/Toss/Client/.cvsignore
===================================================================
--- trunk/Toss/Client/.cvsignore 2012-03-15 00:18:58 UTC (rev 1694)
+++ trunk/Toss/Client/.cvsignore 2012-03-16 01:52:25 UTC (rev 1695)
@@ -4,4 +4,5 @@
JsHandler.js
clientTestRender*.png
+*.js.gz
*~
Modified: trunk/Toss/Client/Makefile
===================================================================
--- trunk/Toss/Client/Makefile 2012-03-15 00:18:58 UTC (rev 1694)
+++ trunk/Toss/Client/Makefile 2012-03-16 01:52:25 UTC (rev 1695)
@@ -4,6 +4,14 @@
make -C .. Client/JsHandler.js
phantomjs clientTest.js
+JSFILES = $(notdir $(shell find . -maxdepth 1 -name '*.js'))
+JSGZFILES = $(addsuffix .gz, $(JSFILES))
+
+%.js.gz: %.js
+ gzip --best -c $< > $@
+
+alljsgz: $(JSGZFILES)
+
tests: ClientTest
Modified: trunk/Toss/Client/index.html
===================================================================
--- trunk/Toss/Client/index.html 2012-03-15 00:18:58 UTC (rev 1694)
+++ trunk/Toss/Client/index.html 2012-03-16 01:52:25 UTC (rev 1695)
@@ -31,7 +31,7 @@
</span>
<span id="appstorelink">
<a href="http://itunes.apple.com/us/app/tplay/id438620686"
- ><img style="height: 24px;" src="img/appstore-small.png" /></a>
+ ><img style="height: 24px; width: 69px;" src="img/appstore-small.png" /></a>
</span>
<span id="toprighttab"><a id="backlink-games" href="index.html">Games</a></span>
</div>
Modified: trunk/Toss/Makefile
===================================================================
--- trunk/Toss/Makefile 2012-03-15 00:18:58 UTC (rev 1694)
+++ trunk/Toss/Makefile 2012-03-16 01:52:25 UTC (rev 1695)
@@ -12,8 +12,10 @@
make $(basename $@).byte
$(JSOCAML) _build/$(basename $@).byte
cat _build/$@ > $@
+ gzip --best -c $@ > $@.gz
TossClient: Client/JsHandler.js
+ make -C Client alljsgz
RELEASE=0.7
Modified: trunk/Toss/Server/Server.ml
===================================================================
--- trunk/Toss/Server/Server.ml 2012-03-15 00:18:58 UTC (rev 1694)
+++ trunk/Toss/Server/Server.ml 2012-03-16 01:52:25 UTC (rev 1695)
@@ -1,10 +1,9 @@
(* Server for Toss Functions. *)
open OUnit
-let debug_level = ref 0
let set_debug_level i =
- debug_level := i;
+ AuxIO.set_debug_level "Server" i;
AuxIO.set_debug_level "GameTree" i;
AuxIO.set_debug_level "Play" i
@@ -86,7 +85,7 @@
(* ------------ Http Handlers ------------ *)
-let http_msg get code mimetp cookies s =
+let http_msg ?(gz=false) get code mimetp cookies s =
let get_tm s =
let t = Unix.gmtime (Unix.gettimeofday() +. s) in
let day = match t.Unix.tm_wday with
@@ -106,16 +105,23 @@
let cookies_s = String.concat "\n" (List.map ck_str cookies) in
let expires_str = if not get then "" else
"Expires: " ^ (get_tm (float (40 * 24 * 3600))) ^ "\r\n" in
- "HTTP/1.1 " ^ code ^ "\r\n" ^
- "Date: " ^ (get_tm 0.) ^ "\r\n" ^
- "Server: Toss\r\n" ^
- expires_str ^
- "Content-Type: " ^ mimetp ^ "\r\n" ^
- (if cookies = [] then "" else cookies_s ^ "\r\n") ^
- "Content-length: " ^ (string_of_int (String.length s)) ^ "\r\n\r\n" ^ s
+ let head =
+ "HTTP/1.1 " ^ code ^ "\r\n" ^
+ "Date: " ^ (get_tm 0.) ^ "\r\n" ^
+ "Server: Toss\r\n" ^
+ expires_str ^
+ "Content-Type: " ^ mimetp ^ "\r\n" ^
+ (if mimetp = "image/png" then "Cache-Control: public\r\n" else "") ^
+ (if gz then "Content-Encoding: gzip\r\n" else "") ^
+ (if cookies = [] then "" else cookies_s ^ "\r\n") ^
+ "Content-length: " ^ (string_of_int (String.length s)) ^ "\r\n\r\n" in
+ LOG 2 "%s" head;
+ head ^ s
+let ext_two s = String.sub s ((String.index s '.') + 1) 2
+
let mime_type fname =
- match String.sub fname ((String.index fname '.') + 1) 2 with
+ match ext_two fname with
| "ht" -> "text/html; charset=utf-8"
| "ic" -> "image/x-icon"
| "pn" -> "image/png"
@@ -125,7 +131,7 @@
| _ -> "text/html charset=utf-8"
let handle_http_get cmd head msg ck =
- if !debug_level > 1 then (
+ if AuxIO.debug_level_for "Server" > 1 then (
Printf.printf "Http Get Handler\n%s%s\n%!" cmd msg;
if ck <> [] then
let ck_strs = List.map (fun (n, v) -> n ^ "=" ^ v) ck in
@@ -136,16 +142,18 @@
let fname_in = try String.sub fname_in1 0 (String.index fname_in1 '?')
with Not_found -> fname_in1 in
let fname = !html_dir_path ^ fname_in in
- if !debug_level > 1 then Printf.printf "SERVING FILE: %s;\n%!" fname;
+ let gz= ext_two fname= "js"&& Aux.str_contains head "Accept-Encoding: gzip" in
+ let fname = if gz then fname ^ ".gz" else fname in
+ LOG 1 "SERVING FILE: %s" fname;
try if not !cache_html then raise Not_found else
let content = Hashtbl.find html_cache fname in
LOG 1 "Found %s in html cache" fname;
- http_msg true "200 OK" (mime_type fname) [] content
+ http_msg ~gz true "200 OK" (mime_type fname) [] content
with Not_found ->
if Sys.file_exists fname && not (Sys.is_directory fname) then (
let content = AuxIO.input_file fname in
if !cache_html then Hashtbl.add html_cache fname content;
- http_msg true "200 OK" (mime_type fname) [] content
+ http_msg ~gz true "200 OK" (mime_type fname) [] content
) else http_msg true "404 NOT FOUND" "text/html; charset=utf-8" []
("<html>\n<head><title>Toss: Page Not Found</title></head>\n" ^
"<body><p>Not found: " ^ fname_in ^ "</p></body>\n</html>")
@@ -209,17 +217,17 @@
(String.sub line 0 (line_len-1)) in
match AuxIO.input_if_http_message line in_ch with
| Some (head, msg, cookies) ->
- if !debug_level > 0 then Printf.printf "Rcvd: %s\n%!" msg;
+ LOG 1 "Rcvd: %s" msg;
let strip_ws = Aux.strip_spaces in
let ck = List.map (fun (k, v) -> (strip_ws k, strip_ws v)) cookies in
("HTTP", Some (Aux.Left (line, head, msg, ck)))
| None ->
if line = "COMP" then
let res = Marshal.from_channel in_ch in
- if !debug_level > 0 then Printf.printf "COMP, %!";
+ LOG 1 "COMP";
("COMP", Some (Aux.Right res))
else (
- if !debug_level > 0 then Printf.printf "Rcvd: %s\n%!" line;
+ LOG 1 "Rcvd: %s" line;
(line, None)
)
@@ -228,11 +236,8 @@
try
let time_started = Unix.gettimeofday () in
let report (new_rstate, resp) continue =
- if !debug_level > 0 then (
- Printf.printf "Resp-time: %F\n%!" (Unix.gettimeofday() -. time_started);
- if !debug_level > 1 || String.length resp < 500 then
- print_endline ("\nRepl: " ^ resp ^ "\n");
- );
+ LOG 1 "Resp-time: %F" (Unix.gettimeofday() -. time_started);
+ LOG 2 "%s\n" (if String.length resp < 500 then "\nRepl: " ^ resp else "");
output_string out_ch (resp ^ "\n");
flush out_ch;
(new_rstate, continue) in
@@ -312,8 +317,7 @@
if !continue then (* collect zombies *)
try ignore (Unix.waitpid [Unix.WNOHANG] (-1)); with
Unix.Unix_error (e,_,_) ->
- if !debug_level > 1 then
- Printf.printf "UNIX WAITPID: %s\n%!" (Unix.error_message e);
+ LOG 2 "UNIX WAITPID: %s\n%!" (Unix.error_message e);
else (try Unix.close cl_sock with _ -> (); Unix.close sock)
done
@@ -362,7 +366,6 @@
let server_tests = "Server" >::: [
"ServerGDLTest.in GDL Tic-Tac-Toe automatic" >::
(fun () ->
- (* Solver.set_debug_level 2; *)
let old_force_competitive = !Heuristic.force_competitive in
let old_use_monotonic = !Heuristic.use_monotonic in
Heuristic.use_monotonic := true;
@@ -432,7 +435,7 @@
String.sub f 0 (String.index f '.')
else f in
([String.sub name 0 slash], [file]) in
- let verbose = !debug_level > 0 in
+ let verbose = AuxIO.debug_level_for "Server" > 0 in
set_debug_level 0;
quit_on_eof := true;
ignore (OUnit.run_test_tt ~verbose
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|