Renamed "Writer" types to "PrintStream" and appropriate variations.
[cslatevm.git] / src / web / cgi.slate
blob599479a589fcf87815936a0711ad4c06458e8a13
1 "CGI define: #PrintStream &parents: {Parsing BasicParser} &slots: {#rootElement}."
3 lobby define: #CGI &parents: {Cloneable} &slots:
4   {#variables -> Dictionary new.
5    #out -> Console writer.
6    #xhtml -> Xml XHTMLPrintStream.
7    #postValues -> Dictionary new.
8    #getValues -> Dictionary new.
9 }.
11 cgi@(CGI traits) parseQueryString: queryString into: dict
13   (queryString splitWithAny: {$&}) do:
14    [| :x s key value |
15     s := (x as: cgi postString) reader.
16     key := s upTo: $=.
17     value := Net URLPathEncoder convert: s upToEnd.
18     dict at: key put: value].
21 cgi@(CGI traits) on: resource
23   cgi out := resource writer.
24   cgi xhtml := xhtml newOn: cgi out.
27 cgi@(CGI traits) new
29   resend `>>
30     [variables := variables new.
31      cgi on: cgi out resource.
32      postValues := postValues new.
33      getValues := getValues new. ]
36 cgi@(CGI traits) handleCurrentRequest
38   cgi variables := Environment variables.
39   
40    (cgi variables at: 'CONTENT_LENGTH' ifAbsent: [Nil]) ifNotNilDo:
41      [| :contentlength |
42       cgi parseQueryString: (Console reader next: (contentlength as: Integer)) into: cgi postValues].
43    (cgi variables at: 'QUERY_STRING' ifAbsent: [Nil]) ifNotNilDo:
44      [| :query |
45       cgi parseQueryString: query into: cgi getValues].
48 Image startupActions at: #CGI put:
49   [CGI new handleCurrentRequest].