+
+struct http_header * http_header_append(struct http_channel *ch,
+ struct http_header * hp,
+ const char *name,
+ const char *value)
+{
+ struct http_header *hpnew = 0;
+
+ if (!hp | !ch)
+ return 0;
+
+ while (hp && hp->next)
+ hp = hp->next;
+
+ if(name && strlen(name)&& value && strlen(value)){
+ hpnew = nmem_malloc(ch->nmem, sizeof *hpnew);
+ 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;
+ }
+
+ return hp;
+}
+
+
+static int is_inprogress(void)
+{
+#ifdef WIN32
+ if (WSAGetLastError() == WSAEWOULDBLOCK)
+ return 1;
+#else
+ if (errno == EINPROGRESS)
+ return 1;
+#endif
+ return 0;
+}
+
+static void enable_nonblock(int sock)
+{
+ int flags;
+#ifdef WIN32
+ flags = (flags & CS_FLAGS_BLOCKING) ? 0 : 1;
+ if (ioctlsocket(sock, FIONBIO, &flags) < 0)
+ yaz_log(YLOG_FATAL|YLOG_ERRNO, "ioctlsocket");
+#else
+ if ((flags = fcntl(sock, F_GETFL, 0)) < 0)
+ yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl");
+ if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0)
+ yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl2");
+#endif
+}
+