+static Z_GDU *get_HTTP_Request_url(ODR odr, const char *url)
+{
+ Z_GDU *p = z_get_HTTP_Request(odr);
+ const char *host = url;
+ const char *cp0 = strstr(host, "://");
+ const char *cp1 = 0;
+ if (cp0)
+ cp0 = cp0+3;
+ else
+ cp0 = host;
+
+ cp1 = strchr(cp0, '/');
+ if (!cp1)
+ cp1 = cp0 + strlen(cp0);
+
+ if (cp0 && cp1)
+ {
+ char *h = (char*) odr_malloc(odr, cp1 - cp0 + 1);
+ memcpy (h, cp0, cp1 - cp0);
+ h[cp1-cp0] = '\0';
+ z_HTTP_header_add(odr, &p->u.HTTP_Request->headers, "Host", h);
+ }
+ p->u.HTTP_Request->path = odr_strdup(odr, *cp1 ? cp1 : "/");
+ return p;
+}
+
+static zoom_ret send_SRW_redirect(ZOOM_connection c, const char *uri,
+ Z_HTTP_Response *cookie_hres)
+{
+ struct Z_HTTP_Header *h;
+ Z_GDU *gdu = get_HTTP_Request_url(c->odr_out, uri);
+
+ gdu->u.HTTP_Request->method = odr_strdup(c->odr_out, "GET");
+ z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers, "Accept",
+ "text/xml");
+
+ for (h = cookie_hres->headers; h; h = h->next)
+ {
+ if (!strcmp(h->name, "Set-Cookie"))
+ z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers,
+ "Cookie", h->value);
+ }
+ if (c->user && c->password)
+ {
+ z_HTTP_header_add_basic_auth(c->odr_out, &gdu->u.HTTP_Request->headers,
+ c->user, c->password);
+ }
+ if (!z_GDU(c->odr_out, &gdu, 0, 0))
+ return zoom_complete;
+ if (c->odr_print)
+ z_GDU(c->odr_print, &gdu, 0, 0);
+ c->buf_out = odr_getbuf(c->odr_out, &c->len_out, 0);
+
+ odr_reset(c->odr_out);
+ return do_write(c);
+}
+