From 4bf0d833cd791f83541ef4b787a6f0e3d4be8add Mon Sep 17 00:00:00 2001 From: martii Date: Thu, 24 Jul 2014 20:27:40 +0200 Subject: [PATCH] nhttpd: fix range handling --- src/nhttpd/yhttpd_core/yresponse.cpp | 3 ++- src/nhttpd/yhttpd_core/ysocket.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/nhttpd/yhttpd_core/yresponse.cpp b/src/nhttpd/yhttpd_core/yresponse.cpp index 1bcecb0c1..0e7852b16 100644 --- a/src/nhttpd/yhttpd_core/yresponse.cpp +++ b/src/nhttpd/yhttpd_core/yresponse.cpp @@ -140,7 +140,8 @@ bool CWebserverResponse::SendResponse() { // cache = false; Write(Connection->HookHandler.BuildHeader(cache)); if (Connection->Method != M_HEAD) - Sendfile(Connection->Request.UrlData["url"], Connection->HookHandler.RangeStart, Connection->HookHandler.RangeEnd - Connection->HookHandler.RangeStart + 1); + Sendfile(Connection->Request.UrlData["url"], Connection->HookHandler.RangeStart, + (Connection->HookHandler.RangeStart == 0 && Connection->HookHandler.RangeEnd == -1) ? -1 : Connection->HookHandler.RangeEnd - Connection->HookHandler.RangeStart + 1); return true; } if (Connection->HookHandler.status == HANDLED_SENDFILE && Connection->HookHandler.httpStatus == HTTP_REQUEST_RANGE_NOT_SATISFIABLE) { diff --git a/src/nhttpd/yhttpd_core/ysocket.cpp b/src/nhttpd/yhttpd_core/ysocket.cpp index 3a7a8cc0c..d39a1b914 100644 --- a/src/nhttpd/yhttpd_core/ysocket.cpp +++ b/src/nhttpd/yhttpd_core/ysocket.cpp @@ -329,7 +329,7 @@ bool CySocket::SendFile(int filed, off_t start, off_t size) { if (errno != EPIPE) perror("sendfile failed"); if (errno != EINVAL) - return false; + return false; break; } else { BytesSend += written;