/*
- * $Id: http.c,v 1.12 2007-03-15 16:50:56 quinn Exp $
+ * $Id: http.c,v 1.13 2007-03-27 13:41:23 marc Exp $
*/
#include <stdio.h>
#include <yaz/comstack.h>
#include <netdb.h>
+#include "cconfig.h"
#include "util.h"
#include "eventl.h"
#include "pazpar2.h"
return 0;
}
+
+struct http_header * http_header_append(struct http_channel *ch,
+ struct http_header * hp,
+ const char *name,
+ const char *value)
+{
+ struct http_header *hpnew = nmem_malloc(ch->nmem, sizeof *hpnew);
+
+ while (hp && hp->next)
+ hp = hp->next;
+
+ hpnew->name = nmem_strdup(ch->nmem, name);
+ hpnew->value = nmem_strdup(ch->nmem, value);
+ hpnew->next = 0;
+ hp->next = hpnew;
+ hp = hp->next;
+ return hpnew;
+}
+
+
+
static int http_proxy(struct http_request *rq)
{
struct http_channel *c = rq->channel;
struct http_proxy *p = c->proxy;
struct http_header *hp;
struct http_buf *requestbuf;
+ //struct conf_server *ser = global_parameters.server;
+
if (!p) // This is a new connection. Create a proxy channel
{
yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl");
if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0)
yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl2");
- if (connect(sock, (struct sockaddr *) proxy_addr, sizeof(*proxy_addr)) < 0)
+ if (connect(sock, (struct sockaddr *) proxy_addr,
+ sizeof(*proxy_addr)) < 0)
if (errno != EINPROGRESS)
{
yaz_log(YLOG_WARN|YLOG_ERRNO, "Proxy connect");
return -1;
}
hp->value = nmem_strdup(c->nmem, proxy_url);
+
+ // Add new header about paraz2 version, host, remote client address, etc.
+
+ hp = rq->headers;
+ hp = http_header_append(c, hp, PACKAGE_NAME "-version", PACKAGE_VERSION);
+ //hp = http_header_append(c, hp, PACKAGE_NAME "-server-host", ser->host);
+ //hp = http_header_append(c, hp, PACKAGE_NAME "-server-port", ser->port);
+ //hp = http_header_append(c, hp, PACKAGE_NAME "-remote-host", "blabla");
+ //hp = http_header_append(c, hp, PACKAGE_NAME "-remote-port", "blabla");
+
requestbuf = http_serialize_request(rq);
http_buf_enqueue(&p->oqueue, requestbuf);
iochan_setflag(p->iochan, EVENT_OUTPUT);
void http_set_proxyaddr(char *url, char *baseurl);
void http_init(const char *addr);
-void http_addheader(struct http_response *r, const char *name, const char *value);
+void http_addheader(struct http_response *r,
+ const char *name, const char *value);
+struct http_header * http_header_append(struct http_channel *ch,
+ struct http_header * hp,
+ const char *name,
+ const char *value);
char *http_argbyname(struct http_request *r, char *name);
char *http_headerbyname(struct http_header *r, char *name);
struct http_response *http_create_response(struct http_channel *c);