Skip to content

Commit

Permalink
small header updates, added missing date and maybe fix FF playback issue
Browse files Browse the repository at this point in the history
after a report came in about FF playback, it seems that the accept-ranges header may be
causing some issue.  We don't need it and I'm not aware of anyone actually requiring it
so remove that for now.

Added Date header just to keep to standard, and only return 1.1 if the request was 1.1
  • Loading branch information
karlheyes committed Nov 14, 2015
1 parent 61bb6b1 commit d2d1ece
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ int format_general_headers (format_plugin_t *plugin, client_t *client)
if (client->respcode == 0)
{
const char *useragent = httpp_getvar (client->parser, "user-agent");
const char *protocol = (client->flags & CLIENT_KEEPALIVE) ? "HTTP/1.1" : "HTTP/1.0";
const char *ver = httpp_getvar (client->parser, HTTPP_VAR_VERSION);
const char *protocol;
const char *contenttypehdr = "Content-Type";
const char *contenttype = plugin->contenttype;
const char *fs = httpp_getvar (client->parser, "__FILESIZE");
Expand All @@ -294,6 +295,10 @@ int format_general_headers (format_plugin_t *plugin, client_t *client)

do
{
if (ver && strcmp (ver, "1.1") == 0)
protocol = "HTTP/1.1";
else
protocol = "HTTP/1.0";
if (opt)
{
fmtcode = atoi (opt);
Expand Down Expand Up @@ -389,35 +394,40 @@ int format_general_headers (format_plugin_t *plugin, client_t *client)
}
if (client->respcode == 0)
{
char datebuf [100] = "\0";
struct tm result;

if (gmtime_r (&client->worker->current_time.tv_sec, &result))
strftime (datebuf, sizeof(datebuf), "Date: %a, %d %b %Y %X GMT\r\n", &result);

if (contenttype == NULL)
contenttype = "application/octet-stream";
if (length)
{
client->respcode = 200;
bytes = snprintf (ptr, remaining, "%s 200 OK\r\n"
"Content-Length: %" PRIu64 "\r\n"
"%s: %s\r\n", protocol, length, contenttypehdr, contenttype);
"%s: %s\r\n%s", protocol, length, contenttypehdr, contenttype, datebuf);
}
else
{
int chunked = 0; // (ver == NULL || strcmp (ver, "1.0") == 0) ? 0 : 1;
int chunked = 0;
const char *TE = "";

if (plugin && plugin->flags & FORMAT_FL_ALLOW_HTTPCHUNKED)
{
const char *ver = httpp_getvar (client->parser, HTTPP_VAR_VERSION);
chunked = (ver == NULL || strcmp (ver, "1.0") == 0) ? 0 : 1;
}
if (chunked && (fmtcode & FMT_DISABLE_CHUNKED) == 0)
{
client->flags |= CLIENT_CHUNKED;
TE = "Transfer-Encoding: chunked\r\n";
protocol = "HTTP/1.1";
}
client->flags &= ~CLIENT_KEEPALIVE;
client->respcode = 200;
bytes = snprintf (ptr, remaining, "%s 200 OK\r\nAccept-Ranges: bytes\r\n%s"
"%s: %s\r\n", protocol, TE, contenttypehdr, contenttype);

bytes = snprintf (ptr, remaining, "%s 200 OK\r\n%s"
"%s: %s\r\n%s", protocol, TE, contenttypehdr, contenttype, datebuf);
}
}
remaining -= bytes;
Expand Down

0 comments on commit d2d1ece

Please sign in to comment.