[MarkLogic Dev General] xdmp:http-get with auto-follow redirect

Micah Dubinko Micah.Dubinko at marklogic.com
Thu Mar 4 12:43:26 PST 2010


It may be a good idea to count how many redirect cycles you've followed and give up at some point. :-)

-m

On Mar 4, 2010, at 12:40 PM, Geert Josten wrote:

> Hi Steve,
> 
> You will have to follow the redirect yourself, but wrapping the function in a function of your own shouldn't be difficult. Something like the following should most likely do:
> 
> declare namespace http = "xdmp:http";
> 
> declare function local:http-get($url as xs:string) as item()* {
>  let $response := xdmp:http-get($url)
>  let $header := $response[1]
>  let $body := $response[2]
>  return
>    if (number($header/http:response/http:code) = 301) then
>      local:http-get($header/http:response/http:headers/http:location)
>    else
>      $body
> }
> 
> Note: haven't tested, I'm not sure the redirect url is returned as a location header, but that is what I remember..
> 
> Kind regards,
> Geert
> 
>> 
> 
> 
> drs. G.P.H. (Geert) Josten
> Consultant
> 
> 
> Daidalos BV
> Hoekeindsehof 1-4
> 2665 JZ Bleiswijk
> 
> T +31 (0)10 850 1200
> F +31 (0)10 850 1199
> 
> mailto:geert.josten at daidalos.nl
> http://www.daidalos.nl/
> 
> KvK 27164984
> 
> P Please consider the environment before printing this mail.
> De informatie - verzonden in of met dit e-mailbericht - is afkomstig van Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit bericht kunnen geen rechten worden ontleend.
> 
>> From: general-bounces at developer.marklogic.com
>> [mailto:general-bounces at developer.marklogic.com] On Behalf Of spig
>> Sent: donderdag 4 maart 2010 21:00
>> To: general at developer.marklogic.com
>> Subject: [MarkLogic Dev General] xdmp:http-get with
>> auto-follow redirect
>> 
>> When I use xdmp:http-get I sometimes get a Redirect (301). Is
>> there a way to have xdmp:http-get automatically follow these
>> redirects? or do I need to create my own structure around
>> this to follow the redirects?
>> 
>> Thanks,
>> Steve Spigarelli
>> 
>> 
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://xqzone.com/mailman/listinfo/general



More information about the General mailing list