int body_chunk_len;
size_t n;
- lwsl_debug("%s: incoming len %d\n", __func__, (int)len);
+ lwsl_debug("%s: incoming len %d state %d\n", __func__, (int)len, wsi->state);
switch (wsi->state) {
#ifdef LWS_USE_HTTP2
/* account for what we're using in rxflow buffer */
if (wsi->rxflow_buffer)
wsi->rxflow_pos++;
- if (lws_http2_parser(wsi, buf[n++]))
+ if (lws_http2_parser(wsi, buf[n++])) {
+ lwsl_debug("%s: http2_parser bailed\n", __func__);
goto bail;
+ }
}
break;
#endif
+ case LWSS_CLIENT_HTTP_ESTABLISHED:
+ break;
+
case LWSS_HTTP:
wsi->hdr_parsing_completed = 0;
/* fallthru */
wsi->u.hdr.lextable_pos = 0;
/* fallthru */
case LWSS_HTTP_HEADERS:
- assert(wsi->u.hdr.ah);
+ if (!wsi->u.hdr.ah) {
+ lwsl_err("%s: LWSS_HTTP_HEADERS: NULL ah\n", __func__);
+ assert(0);
+ }
lwsl_parser("issuing %d bytes to parser\n", (int)len);
if (lws_handshake_client(wsi, &buf, len))
switch (wsi->state) {
case LWSS_HTTP:
case LWSS_HTTP_HEADERS:
- goto http_complete;
+ goto read_ok;
case LWSS_HTTP_ISSUING_FILE:
goto read_ok;
case LWSS_HTTP_BODY:
body_chunk_len = min(wsi->u.http.content_remain,len);
wsi->u.http.content_remain -= body_chunk_len;
len -= body_chunk_len;
-
- n = wsi->protocol->callback(wsi,
- LWS_CALLBACK_HTTP_BODY, wsi->user_space,
- buf, body_chunk_len);
- if (n)
- goto bail;
-
- buf += body_chunk_len;
+#ifdef LWS_WITH_CGI
+ if (wsi->cgi) {
+ struct lws_cgi_args args;
+
+ args.ch = LWS_STDIN;
+ args.stdwsi = &wsi->cgi->stdwsi[0];
+ args.data = buf;
+ args.len = body_chunk_len;
+
+ /* returns how much used */
+ n = user_callback_handle_rxflow(
+ wsi->protocol->callback,
+ wsi, LWS_CALLBACK_CGI_STDIN_DATA,
+ wsi->user_space,
+ (void *)&args, 0);
+ if ((int)n < 0)
+ goto bail;
+ } else {
+#endif
+ n = wsi->protocol->callback(wsi,
+ LWS_CALLBACK_HTTP_BODY, wsi->user_space,
+ buf, body_chunk_len);
+ if (n)
+ goto bail;
+ n = body_chunk_len;
+#ifdef LWS_WITH_CGI
+ }
+#endif
+ buf += n;
if (wsi->u.http.content_remain) {
lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT,
/* he sent all the content in time */
postbody_completion:
lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
- n = wsi->protocol->callback(wsi,
- LWS_CALLBACK_HTTP_BODY_COMPLETION,
- wsi->user_space, NULL, 0);
- if (n)
- goto bail;
+#ifdef LWS_WITH_CGI
+ if (!wsi->cgi)
+#endif
+ {
+ n = wsi->protocol->callback(wsi,
+ LWS_CALLBACK_HTTP_BODY_COMPLETION,
+ wsi->user_space, NULL, 0);
+ if (n)
+ goto bail;
+ }
- goto http_complete;
+ break;
}
break;
}
break;
default:
- lwsl_err("%s: Unhandled state\n", __func__);
+ lwsl_err("%s: Unhandled state %d\n", __func__, wsi->state);
break;
}
return buf - oldbuf;
-http_complete:
- lwsl_debug("%s: http_complete\n", __func__);
-
-#ifndef LWS_NO_SERVER
- /* Did the client want to keep the HTTP connection going? */
- if (lws_http_transaction_completed(wsi))
- goto bail;
-#endif
- /* we may have next header set already, but return to event loop first
- * so a heaily-pipelined http/1.1 connection cannot monopolize the
- * service thread with GET hugefile.bin GET hugefile.bin etc
- */
- goto read_ok;
-
bail:
lwsl_debug("closing connection at lws_read bail:\n");
lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS);