[Twisted-web] Redirect problem

tarjei tarjei at nu.no
Fri Jun 20 06:45:51 EDT 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi, using Nevow, I want to send an extra header X-objectId to the client
when the client has posted an image to a page.

My problem is that when I do a post, the client returns the headers
(including mine) but then hangs partly out into the request.

Example:
curl http://localhost:8000/store/ -F image=@./globalwarming.jpg
HTTP/1.1 302 Found
Content-length: 391
Content-type: application/xml
Accept-ranges: bytes
Server: TwistedWeb/8.1.0
Last-modified: Fri, 20 Jun 2008 10:42:22 GMT
Location:
/info/2008/6/20/f/f95556fd25cc4a8a8cb87b7453bbd0de/f95556fd25cc4a8a8cb87b7453bbd0de.jpg
Date: Fri, 20 Jun 2008 10:42:22 GMT
X-objectId:
2008/6/20/f/f95556fd25cc4a8a8cb87b7453bbd0de/f95556fd25cc4a8a8cb87b7453bbd0de.jpg

<imageMetadata><property name="width" value="934" /><property
name="extension" value=".jpg" /><property name="format" value="JPEG"
/><property name="colour" value="768" /><property name="height"
value="524" /><property name="id"
value="2008/6/20/f/f95556fd25cc4a8a8cb87b7453bbd0de/f95556fd25cc4a8a8cb87b7453bbd0de.jpg"
/><property name="filename" value="globalwarming.jpg" /></imageMetad



class StoreImage(rend.Page):
    addSlash=True
    """
    Gets a file and a set of metadata fields.
    POST with the image in the field image and a metadata dictionary of
name => value pairs.
    """

    def __init__(self, config):
        self.config = config

    def locateChild(self, ctx, segments):
	# removed som internal processing here to make the example smaller.
        self.metadata = {'id': "pokpokpokpo/oijoioij" } # dummy data
        self.xmlFileName = "/somefile.xml"
        return self, ()

    def renderHTTP(self, ctx):
        metadata = self.metadata
        request = inevow.IRequest(ctx)
        request.setHeader('Content-Type', 'text/xml; charset=UTF-8')
        request.setHeader('X-objectId', metadata['id'] )
        #request.setResponseCode("303") # 303
        request.redirect( "/info/" + metadata['id'] )
        #request.finish()

        # I have also tried to return "" but with the same results.
        return static.File(self.xmlFileName, 'text/xml')



I have tried various ways to get this working. I've tried to call
request.finish(), but then the process bombs out.

Any tips to what I should do to get this working would be very welcome.

Kind regards,
Tarjei
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIW4pfYVRKCnSvzfIRArmOAJ9rR94r2taNbFav18FJGPy70iwAvwCfX0v8
FbEX7pBHtvpXJ9qtySEveCc=
=L6YP
-----END PGP SIGNATURE-----



More information about the Twisted-web mailing list