-/* $Id: http.c,v 1.41 2007-10-02 12:11:14 adam Exp $
- Copyright (c) 2006-2007, Index Data.
-
-This file is part of Pazpar2.
+/* This file is part of Pazpar2.
+ Copyright (C) 2006-2008 Index Data
Pazpar2 is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
for more details.
You should have received a copy of the GNU General Public License
-along with Pazpar2; see the file LICENSE. If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
- */
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+*/
#include <stdio.h>
#include <sys/socket.h>
}
}
-#ifdef GAGA
-// Calculate length of chain
-static int http_buf_len(struct http_buf *b)
-{
- int sum = 0;
- for (; b; b = b->next)
- sum += b->len;
- return sum;
-}
-#endif
-
static struct http_buf *http_buf_bybuf(char *b, int len)
{
struct http_buf *res = 0;
r->channel = c;
r->headers = 0;
r->payload = 0;
+ r->content_type = "text/xml";
return r;
}
{
wrbuf_printf(c->wrbuf, "Content-Length: %d\r\n", r->payload ?
(int) strlen(r->payload) : 0);
- wrbuf_printf(c->wrbuf, "Content-Type: text/xml\r\n");
- if (1)
+ wrbuf_printf(c->wrbuf, "Content-Type: %s\r\n", r->content_type);
+ if (!strcmp(r->content_type, "text/xml"))
{
xmlDoc *doc = xmlParseMemory(r->payload, strlen(r->payload));
if (doc)
}
}
-#ifdef GAGA
-// If this hostname contains our proxy host as a prefix, replace with myurl
-static char *sub_hostname(struct http_channel *c, char *buf)
-{
- char tmp[1024];
- if (strlen(buf) > 1023)
- return buf;
- if (strncmp(buf, "http://", 7))
- return buf;
- if (!strncmp(buf + 7, proxy_url, strlen(proxy_url)))
- {
- strcpy(tmp, myurl);
- strcat(tmp, buf + strlen(proxy_url) + 7);
- return nmem_strdup(c->nmem, tmp);
- }
- return buf;
-}
-#endif
-
// Handles I/O on a client connection to a backend web server (proxy mode)
static void proxy_io(IOCHAN pi, int event)
{
htbuf->buf[res] = '\0';
htbuf->offset = 0;
htbuf->len = res;
-#ifdef GAGA
- if (pc->first_response) // Check if this is a redirect
- {
- int len;
- if ((len = package_check(htbuf->buf)))
- {
- struct http_response *res = http_parse_response_buf(hc, htbuf->buf, len);
- if (res)
- {
- const char *location = http_lookup_header(
- res->header, "Location");
- if (location)
- {
- // We found a location header. Rewrite it.
- struct http_buf *buf;
- h->value = sub_hostname(hc, location);
- buf = http_serialize_response(hc, res);
- yaz_log(YLOG_LOG, "Proxy rewrite");
- http_buf_enqueue(&hc->oqueue, buf);
- htbuf->offset = len;
- break;
- }
- }
- }
- pc->first_response = 0;
- }
-#endif
// Write any remaining payload
if (htbuf->len - htbuf->offset > 0)
http_buf_enqueue(&hc->oqueue, htbuf);