Project

General

Profile

[Solved] 'server.stream-response-body = 2': (file size < 8 kbytes) problem

Added by laszlo.gyimothy over 6 years ago

Hi All,

I have implemented a server in C. My server consists of two EXE files, the Lighttpd.exe and the BusinessLogic.exe. They communicate using the FastCGI.

My use case is the following:

1. the client sends a GET request to the server
2. the server starts to generate the response file and sends it back to the client in chunked mode

The problem is the following:

If the generated file is smaller than 8 kbytes, then the Lighttpd doesnt append the terminating '0\r\n\r\n' data chunk to the network stream. If the generated file larger than 8 kbytes, everything works fine.

My solution is the following:

1. if the business logic gets the request, it creates the response header in string format: "... transfer encodig: chuncked ... " and sends it via FastCGI to the Lighttpd: "(void)FCGX_FPrintF(p_response->p_fcgi->out, "%s: %s\r\n", p_element, p_value);"

2. if the header is ready, the business logic generates the data and send them to the Lighttpd: "n_write = FCGX_PutStr((const char *)p_send_buf, (int)len_send_buf, p_response->p_fcgi->out);"

OS:

Linux, Windows

The Lighttpd server configuration:

  1. lighttpd main configuration ##
  1. general variables
    var.log_root = "/var/log"
    var.server_root = "/var/www"
    var.state_dir = "/var/run"
    var.home_dir = "/var/lib/lighttpd"
  1. load server modules
    server.modules = (
    "mod_access",
    "mod_accesslog",
    "mod_alias",
    "mod_cgi",
    "mod_compress",
    "mod_status",
    "mod_redirect",
    "mod_rewrite",
    "mod_fastcgi",
    )
  1. general server definitions
    server.port = 80
    server.bind = "0.0.0.0"
    server.username = "www-data"
    server.groupname = "www-data"
    server.tag = "Test"
    server.document-root = "til/apps/test"
    server.max-fds = 2048
    server.max-connections = 128
    #server.event-handler = "libev"
    server.network-backend = "writev"
    server.upload-dirs = ( "c:\tmp" )
    server.max-keep-alive-requests = 200000
    server.stat-cache-engine = "simple"
    server.follow-symlink = "disable"
    server.stream-response-body = 2
    1. supported index files
      index-file.names += (
      "index.xhtml", "index.html", "index.htm", "default.htm"
      )
  1. disable dirlisting
    dir-listing.activate = "disable"
  1. additional configuration
    include "debug.conf"
    include "rewrite.conf"
    include "fastcgi.conf"
    include "redirect.conf"
    include "alias.conf"
    include "mime.conf"

The FastCGI configuration:

  1. fastcgi configuration ##

fastcgi.debug = 0
fastcgi.server = (

  1. begin entry
    "/test/" => ((
    "host" => "127.0.0.1",
    "port" => "41280",
    "check-local" => "disable"
    )),
  2. end entry
  1. begin entry
    "/test/" => ((
    "host" => "127.0.0.1",
    "port" => "41280",
    "check-local" => "disable"
    )),
  2. end entry
  1. begin entry
    "/test_internal/" => ((
    "host" => "127.0.0.1",
    "port" => "39312",
    "check-local" => "disable"
    ),(
    "host" => "127.0.0.1",
    "port" => "39313",
    "check-local" => "disable"
    )),
  2. end entry
  1. Add new entries before this line

)

Do you have any idea?

Thank you for your help!

Laszlo


Replies (2)

RE: 'server.stream-response-body = 2': (file size < 8 kbytes) problem - Added by gstrauss over 6 years ago

It is recommended that your backend FastCGI not send Transfer-Encoding: chunked. Just send the response from your backend, and do not include HTTP/1.1 hop-by-hop headers (such as Transfer-Encoding), and do not send HTTP/1.1 "chunked"-encoded bits of data, since your backend is speaking FastCGI protocol, not HTTP/1.1 protocol.

RE: 'server.stream-response-body = 2': (file size < 8 kbytes) problem - Added by laszlo.gyimothy over 6 years ago

Thank you very much for the quick help, it works fine now!

    (1-2/2)