[Bese-devel] Providing raw data (Service link)

Marco Baringer mb at bese.it
Mon Apr 24 11:19:08 UTC 2006


Christian Haselbach <chriss at muon.de> writes:

> Hello,
>
> what is the best way to create an url where raw data (i.e., not
> wrapped / modified by ucw) is served, but where the current session is
> available to create the data. I am looking for something that is called
> Service Link in Tapestry.
>
> For example a download link for some data as plain text.
>
> My idea was to call a component wich captures the whole window (as
> described in the cliki ucw cookbook). The componenent is defined using
> defcomponent, but not inhereting from another component. The render
> :before gets to set the content type. However, ucw modifies the output.

how does ucw modify the output?

> Another example for a service link would be an image used in a website,
> that is dependend on the state of the session. Think for example of a
> web mapping service, where the user can see a map an navigate through
> it.

i've got a couple of actions whcih generate images, or rtf or pdf
documents. the basic idea is to define a regular old component:

(defcomponent my-document ()
  (...))

and have someone call it as the toplevel component:

(call-as-window 'my-document ...)

and make sure my-document's render method setups the proper headers:

(defmethod render ((doc my-document))
  (let ((response (context.response *context*)))
    (setf (get-header response  "Content-Type") "application/rtf; charset=utf-8;"
          (get-header response "Content-Disposition") "filename=document.rtf"
          (external-format response) :iso-8859-1)
    (write-document-data (html-stream response))))

notice the call to (setf external-format) in the render method. 

one thing which ucw could do to help you in this is te split the
shutdown method into two parts:

(defgeneric send-headers (response)
  (:documentation "Send the HTTP headers in RESPONSE."))

(defgeneric send-body (response)
  (:documentation "Send the BODY of response."))

what this, combined with a custom dispatcher, wolud allow you to do is
to send the headers using the standard ucw mechanisms and then write
the data directly (skipping the call to send-body) to the response's
content-stream (which is a (unsigned-byte 8) stream attached directly
to the client).

-- 
-marco
Ring the bells that still can ring.
Forget the perfect offering.
There is a crack in everything.
That's how the light gets in.
	-Leonard Cohen



More information about the bese-devel mailing list