[mapserver-dev] Can msIO_stripStdoutBufferContentHeaders()
return headers and be available through MapScript?
Lime, Steve D (DNR)
steve.lime at state.mn.us
Tue Jun 14 15:38:27 EDT 2011
JF: Could you create a ticket for the two patches you've supplied so they don't get lost?
Steve
-----Original Message-----
From: mapserver-dev-bounces at lists.osgeo.org [mailto:mapserver-dev-bounces at lists.osgeo.org] On Behalf Of Jean-François Gigand
Sent: Tuesday, June 14, 2011 11:10 AM
To: Daniel Morissette; Stephan Meißl
Cc: mapserver-dev at lists.osgeo.org
Subject: Re: [mapserver-dev] Can msIO_stripStdoutBufferContentHeaders() return headers and be available through MapScript?
Hi again,
Since I'm on the php/msIO topic, I remember a bug (in 5.6, still in
6.0) in the ms_ioGetStdoutBufferString() PHP/MapScript function.
The function does not work with binary data, since RETURN_STRING() assumes, as you know, a \0 byte for the end.
I have replaced it with RETURN_STRINGL() which takes a length argument instead of relying on strlen(). It works with my PNG test.
Attached is the (tiny) patch.
Best regards,
JF Gigand
2011/6/14 Jean-François Gigand <jean-francois at gigand.fr>:
> Hi,
>
> I did not notice that msIO_stripStdoutBufferContentHeaders() was
> available in MapScript. The page you pointed, Stephan, is SWIG's. The
> PHP bindings in mapscript/php/php_mapscript.c are statically written
> (not based on SWIG) and do not contain the function. The following
> check confirms it at runtime:
>
> $ echo '<?php print ms_GetVersion()."\n";
> print_r(get_extension_funcs("mapscript"));' | php MapServer version
> 6.0.0 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG OUTPUT=KML SUPPORTS=PROJ
> SUPPORTS=AGG SUPPORTS=CAIRO SUPPORTS=FREETYPE SUPPORTS=ICONV
> SUPPORTS=FRIBIDI SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT
> SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER
> SUPPORTS=SOS_SERVER SUPPORTS=FASTCGI SUPPORTS=THREADS SUPPORTS=GEOS
> INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE Array (
> [0] => ms_GetVersion
> [1] => ms_GetVersionInt
> [2] => ms_newLineObj
> [3] => ms_newRectObj
> [4] => ms_newShapeObj
> [5] => ms_shapeObjFromWkt
> [6] => ms_GetErrorObj
> [7] => ms_ResetErrorList
> [8] => ms_newOWSRequestObj
> [9] => ms_newShapeFileObj
> [10] => ms_newMapObj
> [11] => ms_newMapObjFromString
> [12] => ms_newLayerObj
> [13] => ms_newPointObj
> [14] => ms_newProjectionObj
> [15] => ms_newStyleObj
> [16] => ms_newSymbolObj
> [17] => ms_newClassObj
> [18] => ms_newGridObj
> [19] => ms_getCwd
> [20] => ms_getPid
> [21] => ms_getScale
> [22] => ms_tokenizeMap
> [23] => ms_ioInstallStdoutToBuffer
> [24] => ms_ioInstallStdinFromBuffer
> [25] => ms_ioGetStdoutBufferString
> [26] => ms_ioResetHandlers
> [27] => ms_ioStripStdoutBufferContentType
> [28] => ms_ioGetStdoutBufferBytes
> )
>
> However, my need was to *fetch* the Content-* headers.
>
> In the mean time, since msIO_stripStdoutBufferContentHeaders() is in
> SWIG but not in PHP, I guess it is just missing.
> So I added it, attached is a patch, made against trunk rev 11817.
> I named the function "ms_ioStripStdoutBufferContentHeaders", following
> the naming convention of the other PHP MS bindings.
>
> Best regards,
>
> JF Gigand
>
>
>
> 2011/6/13 Daniel Morissette <dmorissette at mapgears.com>:
>> Maybe we couold add a new ms_ioExtractStdoutBufferHeaders() that
>> would extract and return all headers in an array?
>>
>>
>> On 11-06-13 11:59 AM, Stephan Meißl wrote:
>>>
>>> Jean-François,
>>>
>>> in 6.0 the exact function you propose was added (see [1]). It
>>> doesn't return the headers though. I haven't tested the function in
>>> PHP MapScript but it works with Python.
>>>
>>> cu
>>> Stephan
>>>
>>> [1]
>>> http://mapserver.org/mapscript/mapscript.html#mapscript-functions
>>>
>>>
>>> On Mon, 2011-06-13 at 15:27 +0200, Jean-François Gigand wrote:
>>>>
>>>> Hi,
>>>>
>>>> I use PHP MapScript and handle WxS requests through the "MapScript
>>>> Wrappers for WxS Services", which work fine.
>>>>
>>>> Since 6.0 I also use OGR output (ZIP of CSV/Shapefiles), which also
>>>> works fine (much thanks, 6.0 kicks ass!).
>>>>
>>>> Through {,Fast}Cgi, everything is fine.
>>>> But, through (PHP) MapScript, when the WxS request outputs a
>>>> "Content-Disposition" header, the
>>>> ms_ioStripStdoutBufferContentType()
>>>> function is of no use, as the Content-Type header is not the first
>>>> one, and no MapScript method would extract the "Content-Disposition"
>>>> header anyway.
>>>>
>>>> To my guess, the perfect solution would be a
>>>> msIO_stripStdoutBufferContentHeaders() function which:
>>>> - would return the headers, not just strip them off, for example
>>>> returning a<char **>
>>>> - would be available through MapScript
>>>>
>>>> If you confirm the need for this solution, I can develop it and
>>>> send you a patch (just advise me about the function name and
>>>> prototype (<char***> param or<char**> return?).
>>>>
>>>> So far, I have done this through PHP, see the function below:
>>>>
>>>> /**
>>>> * Strip off Content-* headers from buffer and set them on
>>>> response object
>>>> *
>>>> * @param $buffer string Ref to buffer string, which may
>>>> include Content-* headers
>>>> * @param $reponse Response Framework-dependant response object
>>>> to add the headers to
>>>> */
>>>> function extractContentHeaders(&$buffer, Response $response)
>>>> {
>>>> $length = -1;
>>>> $regex = "/^(Content-[a-zA-Z-]+): ([a-zA-Z0-9.\/=?!_; -]+)\n/";
>>>> while (strlen($buffer) != $length) {
>>>> $length = strlen($buffer);
>>>> $cb = function($m) use ($response) {
>>>> $response->headers->set($m[1], $m[2]);
>>>> return '';
>>>> };
>>>> $buffer = preg_replace_callback($regex,$cb, $buffer);
>>>> }
>>>> }
>>>>
>>>>
>>>> Best regards,
>>>>
>>>> JF Gigand
>>>> _______________________________________________
>>>> mapserver-dev mailing list
>>>> mapserver-dev at lists.osgeo.org
>>>> http://lists.osgeo.org/mailman/listinfo/mapserver-dev
>>>
>>>
>>> _______________________________________________
>>> mapserver-dev mailing list
>>> mapserver-dev at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/mapserver-dev
>>
>>
>> --
>> Daniel Morissette
>> http://www.mapgears.com/
>> Provider of Professional MapServer Support since 2000
>>
>> _______________________________________________
>> mapserver-dev mailing list
>> mapserver-dev at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/mapserver-dev
>>
>
More information about the mapserver-dev
mailing list