- yaz_log(YLOG_WARN, "Failed to parse request");
- http_destroy(i);
- return;
- }
- hc->response = 0;
- yaz_log(YLOG_LOG, "Request: %s %s%s%s", hc->request->method,
- hc->request->path,
- *hc->request->search ? "?" : "",
- hc->request->search);
- if (http_weshouldproxy(hc->request))
- http_proxy(hc->request);
- else
- {
- // Execute our business logic!
- hc->state = Http_Busy;
- http_command(hc);
- }
- if (hc->iqueue)
- {
- yaz_log(YLOG_DEBUG, "We think we have more input to read. Forcing event");
- iochan_setevent(i, EVENT_INPUT);
+ if (hc->state == Http_Busy)
+ return;
+ reqlen = request_check(hc->iqueue);
+ if (reqlen <= 2)
+ return;
+ // we have a complete HTTP request
+ nmem_reset(hc->nmem);
+#if HAVE_SYS_TIME_H
+ if (hc->http_server->record_file)
+ {
+ struct timeval tv;
+ int sz = 0;
+ struct http_buf *hb;
+ for (hb = hc->iqueue; hb; hb = hb->next)
+ sz += hb->len;
+ gettimeofday(&tv, 0);
+ fprintf(hc->http_server->record_file, "r %lld %lld %lld %d\n",
+ (long long) tv.tv_sec, (long long) tv.tv_usec,
+ (long long) iochan_getfd(i), sz);
+ for (hb = hc->iqueue; hb; hb = hb->next)
+ fwrite(hb->buf, 1, hb->len, hc->http_server->record_file);
+ fflush(hc->http_server->record_file);
+ }
+ #endif
+ if (!(hc->request = http_parse_request(hc, &hc->iqueue, reqlen)))
+ {
+ yaz_log(YLOG_WARN, "Failed to parse request");
+ http_error(hc, 400, "Bad Request");
+ return;
+ }
+ hc->response = 0;
+ yaz_log(YLOG_LOG, "Request: %s %s%s%s", hc->request->method,
+ hc->request->path,
+ *hc->request->search ? "?" : "",
+ hc->request->search);
+ if (hc->request->content_buf)
+ yaz_log(YLOG_LOG, "%s", hc->request->content_buf);
+ if (http_weshouldproxy(hc->request))
+ http_proxy(hc->request);
+ else
+ {
+ // Execute our business logic!
+ hc->state = Http_Busy;
+ http_command(hc);
+ }