<arg>-m <replaceable>method</replaceable></arg>
<arg>-O <replaceable>fname</replaceable></arg>
<arg>-p <replaceable>fname</replaceable></arg>
+ <arg>-R <replaceable>num</replaceable></arg>
<arg>-u <replaceable>user/password</replaceable></arg>
<arg>-x <replaceable>proxy</replaceable></arg>
<arg rep="repeat">url</arg>
</varlistentry>
<varlistentry>
+ <term>-R <replaceable>num</replaceable></term>
+ <listitem><para>
+ Sets maximum number of HTTP redirects to be followed.
+ A value of zero disables follow of HTTP redirects.
+ </para></listitem>
+ </varlistentry>
+
+ <varlistentry>
<term>-u <replaceable>user/password</replaceable></term>
<listitem><para>
Specifies a user and a password to be uesd in HTTP
*/
YAZ_EXPORT void yaz_url_set_proxy(yaz_url_t p, const char *proxy);
+/** \brief sets maximum number of redirects
+ \param p handle
+ \param num maximum number of redirects
+*/
+YAZ_EXPORT void yaz_url_set_max_redirects(yaz_url_t p, int num);
+
/** \brief executes the actual HTTP request (including redirects, etc)
\param p handle
\param uri URL
ODR odr_in;
ODR odr_out;
char *proxy;
+ int max_redirects;
};
yaz_url_t yaz_url_create(void)
p->odr_in = odr_createmem(ODR_DECODE);
p->odr_out = odr_createmem(ODR_ENCODE);
p->proxy = 0;
+ p->max_redirects = 10;
return p;
}
p->proxy = xstrdup(proxy);
}
+void yaz_url_set_max_redirects(yaz_url_t p, int num)
+{
+ p->max_redirects = num;
+}
+
static void extract_user_pass(NMEM nmem,
const char *uri,
char **uri_lean, char **http_user,
break;
code = res->code;
location = z_HTTP_header_lookup(res->headers, "Location");
- if (++number_of_redirects < 10 &&
+ if (++number_of_redirects <= p->max_redirects &&
location && (code == 301 || code == 302 || code == 307))
{
odr_reset(p->odr_out);
printf(" -m method Sets HTTP method\n");
printf(" -O fname Writes HTTP content to file\n");
printf(" -p fname POSTs file at following url\n");
+ printf(" -R num Set maximum number of HTTP redirects\n");
printf(" -u user/password Sets Basic HTTP auth\n");
printf(" -x proxy Sets HTTP proxy\n");
exit(1);
int no_urls = 0;
const char *outfname = 0;
- while ((ret = options("hH:m:O:p:u:x:", argv, argc, &arg))
+ while ((ret = options("h{help}H:m:O:p:R{max-redirs}:u:x:", argv, argc, &arg))
!= YAZ_OPTIONS_EOF)
{
switch (ret)
post_buf = get_file(arg, &post_len);
method = "POST";
break;
+ case 'R':
+ yaz_url_set_max_redirects(p, atoi(arg));
+ break;
case 'u':
if (strchr(arg, '/'))
{