[Gd-chatter] r10958 - trunk/libraries/koala/sources/koala
turbo24prg at gwydiondylan.org
turbo24prg at gwydiondylan.org
Wed Nov 15 17:48:17 CET 2006
Author: turbo24prg
Date: Wed Nov 15 17:48:14 2006
New Revision: 10958
Modified:
trunk/libraries/koala/sources/koala/library-unix.dylan
trunk/libraries/koala/sources/koala/library.dylan
trunk/libraries/koala/sources/koala/server.dylan
trunk/libraries/koala/sources/koala/urls.dylan
Log:
job: koala
* implemented encode-url
* made some very useful things accessible outside
Modified: trunk/libraries/koala/sources/koala/library-unix.dylan
==============================================================================
--- trunk/libraries/koala/sources/koala/library-unix.dylan (original)
+++ trunk/libraries/koala/sources/koala/library-unix.dylan Wed Nov 15 17:48:14 2006
@@ -154,6 +154,8 @@
register-url,
<request>,
*request*, // Holds the active request, per thread.
+ current-request, // Returns the active request of the thread.
+ current-response, // Returns the active response of the thread.
request-query-values, // get the keys/vals from the current GET or POST request
request-method, // Returns #"get", #"post", etc
responder-definer,
@@ -166,7 +168,8 @@
count-query-values,
count-form-values,
application-error,
- decode-url;
+ decode-url,
+ encode-url;
// Virtual hosts
create
@@ -260,6 +263,10 @@
create
print-object;
+ // files
+ create
+ static-file-responder;
+
end module koala;
// Additional interface for extending the server
@@ -356,10 +363,13 @@
respond-to-post, // Implement this for your page to handle POST requests
respond-to-head, // Implement this for your page to handle HEAD requests
+ page-source,
+ page-source-setter,
+
<dylan-server-page>, // Subclass this using the "define page" macro
page-definer, // Defines a new page class
process-template, // Call this (or next-method()) from respond-to-get/post if
- // you decide you want the DSP template to be processed.
+ // you decide you want the DSP template to ibe processed.
<taglib>,
taglib-definer,
tag-definer, // Defines a new DSP tag function and registers it with a page
Modified: trunk/libraries/koala/sources/koala/library.dylan
==============================================================================
--- trunk/libraries/koala/sources/koala/library.dylan (original)
+++ trunk/libraries/koala/sources/koala/library.dylan Wed Nov 15 17:48:14 2006
@@ -154,6 +154,8 @@
register-url,
<request>,
*request*, // Holds the active request, per thread.
+ current-request, // Returns the active request of the thread.
+ current-response, // Returns the active response of the thread.
request-query-values, // get the keys/vals from the current GET or POST request
request-method, // Returns #"get", #"post", etc
responder-definer,
@@ -166,7 +168,8 @@
count-query-values,
count-form-values,
application-error,
- decode-url;
+ decode-url,
+ encode-url;
// Virtual hosts
create
@@ -260,6 +263,10 @@
create
print-object;
+ // files
+ create
+ static-file-responder;
+
end module koala;
// Additional interface for extending the server
@@ -356,6 +363,9 @@
respond-to-post, // Implement this for your page to handle POST requests
respond-to-head, // Implement this for your page to handle HEAD requests
+ page-source,
+ page-source-setter,
+
<dylan-server-page>, // Subclass this using the "define page" macro
page-definer, // Defines a new page class
process-template, // Call this (or next-method()) from respond-to-get/post if
Modified: trunk/libraries/koala/sources/koala/server.dylan
==============================================================================
--- trunk/libraries/koala/sources/koala/server.dylan (original)
+++ trunk/libraries/koala/sources/koala/server.dylan Wed Nov 15 17:48:14 2006
@@ -532,10 +532,8 @@
define thread variable *request-query-values* :: <string-table>
= make(<string-table>);
-// Is there ever any need for clients to use these?
-//define inline function current-request () => (request :: <request>) *request* end;
-//define inline function current-response () => (response :: <response>) *response* end;
-
+define inline function current-request () => (request :: <request>) *request* end;
+define inline function current-response () => (response :: <response>) *response* end;
// Called (in a new thread) each time an HTTP request is received.
define function handler-top-level
@@ -881,6 +879,7 @@
end
end
end;
+ let url = decode-url(url, 0, size(url));
let path = split(url, separator: "/");
let trie = url-map(*server*);
let (responder, rest) = find-object(trie, path);
Modified: trunk/libraries/koala/sources/koala/urls.dylan
==============================================================================
--- trunk/libraries/koala/sources/koala/urls.dylan (original)
+++ trunk/libraries/koala/sources/koala/urls.dylan Wed Nov 15 17:48:14 2006
@@ -26,8 +26,30 @@
end;
end make-locator;
+define function encode-url (url :: <byte-string>, #key reserved?)
+ => (encoded-url :: <byte-string>)
+ let result = make(<byte-string>);
+ let allowed-special = #('$', '-', '_', '.', '+', '!', '*', '\'', '(', ')');
+ let reserved = #('$', '&', '+', ',', '/', ':', ';', '=', '?', '@');
+
+ for (char in url)
+ case
+ (char >= 'a' & char <= 'z') |
+ (char >= 'A' & char <= 'Z') |
+ (char >= '0' & char <= '9') |
+ member?(char, allowed-special) |
+ (member?(char, reserved) & ~ reserved?) =>
+ result := add!(result, char);
+ otherwise =>
+ result := concatenate(result,
+ "%", integer-to-string(as(<byte>, char), base: 16));
+ end case;
+ end for;
+ result;
+end;
+
define function decode-url
- (str :: <byte-string>, bpos :: <integer>, epos :: <integer>)
+ (str :: <byte-string>, bpos :: <integer>, epos :: <integer>)
=> (str :: <byte-string>)
// Note: n accumulates how many chars are NOT needed in the copy.
iterate count (pos :: <integer> = bpos, n :: <integer> = 0)
More information about the chatter
mailing list