[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[myserver-commit] [SCM] GNU MyServer branch, master, updated. v0.9.2-472
From: |
Giuseppe Scrivano |
Subject: |
[myserver-commit] [SCM] GNU MyServer branch, master, updated. v0.9.2-472-g1452a92 |
Date: |
Fri, 22 Apr 2011 14:08:32 +0000 |
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU MyServer".
The branch, master has been updated
via 1452a920039a2faa8f93796cc417434b96ff4361 (commit)
from ebe8e3b297859c444b3a4d57fe4bfbf5aaaffbbe (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 1452a920039a2faa8f93796cc417434b96ff4361
Author: Giuseppe Scrivano <address@hidden>
Date: Fri Apr 22 16:08:29 2011 +0200
HttpFile: simplify code for `send'.
diff --git a/myserver/include/protocol/http/http_data_handler.h
b/myserver/include/protocol/http/http_data_handler.h
index c8f863f..74c694c 100644
--- a/myserver/include/protocol/http/http_data_handler.h
+++ b/myserver/include/protocol/http/http_data_handler.h
@@ -24,7 +24,9 @@
# include <include/protocol/protocol.h>
# include "include/protocol/http/http_headers.h"
# include <include/filter/filters_chain.h>
+#include <include/filter/filters_factory.h>
# include <include/filter/memory_stream.h>
+# include <include/conf/mime/mime_manager.h>
/*!
@@ -50,7 +52,8 @@ public:
HttpDataHandler ();
virtual ~HttpDataHandler ();
- static void checkDataChunks (HttpThreadContext *, bool *, bool *);
+ static void checkDataChunks (HttpThreadContext* td, bool* keepalive,
+ bool* useChunks, bool disableEncoding = false);
static size_t appendDataToHTTPChannel (HttpThreadContext* td,
const char *buffer,
@@ -76,6 +79,11 @@ public:
FiltersChain &chain,
bool useChunks);
+ static size_t generateFiltersChain (HttpThreadContext *td,
+ FiltersFactory *factory,
+ FiltersChain &fc,
+ MimeRecord *mime,
+ MemoryStream &memStream);
};
#endif
diff --git a/myserver/src/http_handler/http_file/http_file.cpp
b/myserver/src/http_handler/http_file/http_file.cpp
index 8fd89cd..42ea59e 100644
--- a/myserver/src/http_handler/http_file/http_file.cpp
+++ b/myserver/src/http_handler/http_file/http_file.cpp
@@ -49,9 +49,6 @@ int HttpFile::putFile (HttpThreadContext* td, string&
filename)
try
{
- if (td->request.isKeepAlive ())
- td->response.setValue ("connection", "keep-alive");
-
if (!(td->permissions & MYSERVER_PERMISSION_WRITE))
return td->http->sendAuth ();
@@ -204,12 +201,11 @@ int HttpFile::send (HttpThreadContext* td, const char
*filenamePath,
size_t bytesToSend;
off_t firstByte = td->request.rangeByteBegin;
off_t lastByte = td->request.rangeByteEnd;
- bool keepalive = false;
+ bool fastCopyAllowed;
+ bool keepalive;
bool useChunks = false;
- bool useModifiers = false;
MemoryStream memStream (td->auxiliaryBuffer);
FiltersChain chain;
- size_t nbw;
size_t nbr;
time_t lastMT;
string tmpTime;
@@ -293,8 +289,6 @@ int HttpFile::send (HttpThreadContext* td, const char
*filenamePath,
bytesToSend = lastByte - firstByte;
- keepalive = td->request.isKeepAlive ();
-
td->buffer->setLength (0);
/* If a Range was requested send 206 and not 200 for success. */
@@ -317,72 +311,20 @@ int HttpFile::send (HttpThreadContext* td, const char
*filenamePath,
td->response.other.put (e->name, e);
}
}
- chain.setStream (&memStream);
- if (td->mime)
- {
- HttpRequestHeader::Entry* e = td->request.other.get
("accept-encoding");
- memStream.refresh ();
- if (td->mime)
- Server::getInstance ()->getFiltersFactory ()->chain (&chain,
-
td->mime->filters,
- &memStream,
- &nbw, 0, false,
- e ? e->value :
"");
- }
- useModifiers = chain.hasModifiersFilters ();
- if (! useModifiers)
- {
- ostringstream buffer;
- buffer << bytesToSend;
- td->response.contentLength.assign (buffer.str ());
- }
+ generateFiltersChain (td, Server::getInstance ()->getFiltersFactory (),
+ chain, td->mime, memStream);
- if (keepalive)
- td->response.setValue ("connection", "keep-alive");
- else
- td->response.setValue ("connection", "close");
+ fastCopyAllowed = chain.isEmpty ()
+ && !(td->http->getProtocolOptions () & Protocol::SSL);
- if (useModifiers)
- {
- string s;
- HttpResponseHeader::Entry *e;
- chain.getName (s);
- e = td->response.other.get ("content-encoding");
+ checkDataChunks (td, &keepalive, &useChunks, fastCopyAllowed);
- if (e)
- e->value.assign (s);
- else
- {
- e = new HttpResponseHeader::Entry ();
- e->name.assign ("content-encoding");
- e->value.assign (s);
- td->response.other.put (e->name, e);
- }
- /* Do not use chunked transfer with old HTTP/1.0 clients. */
- if (keepalive)
- useChunks = true;
- }
-
- if (useChunks)
+ if (! chain.hasModifiersFilters ())
{
- HttpResponseHeader::Entry *e;
- e = td->response.other.get ("transfer-encoding");
- if (e)
- e->value.assign ("chunked");
- else
- {
- e = new HttpResponseHeader::Entry ();
- e->name.assign ("transfer-encoding");
- e->value.assign ("chunked");
- td->response.other.put (e->name, e);
- }
- }
- else
- { HttpResponseHeader::Entry *e;
- e = td->response.other.remove ("transfer-encoding");
- if (e)
- delete e;
+ ostringstream buffer;
+ buffer << bytesToSend;
+ td->response.contentLength.assign (buffer.str ());
}
HttpHeaders::sendHeader (td->response, *td->connection->socket,
@@ -404,8 +346,7 @@ int HttpFile::send (HttpThreadContext* td, const char
*filenamePath,
Check if there are all the conditions to use a direct copy from the
file to the socket.
*/
- if (!useChunks && chain.isEmpty ()
- && !(td->http->getProtocolOptions () & Protocol::SSL))
+ if (fastCopyAllowed)
{
size_t nbw = 0;
file->fastCopyToSocket (td->connection->socket, firstByte,
@@ -433,7 +374,6 @@ int HttpFile::send (HttpThreadContext* td, const char
*filenamePath,
for (;;)
{
size_t nbr;
- size_t nbw;
/* Check if there are other bytes to send. */
if (! bytesToSend)
diff --git a/myserver/src/protocol/http/http_data_handler.cpp
b/myserver/src/protocol/http/http_data_handler.cpp
index 40c9245..9d2f1aa 100644
--- a/myserver/src/protocol/http/http_data_handler.cpp
+++ b/myserver/src/protocol/http/http_data_handler.cpp
@@ -167,14 +167,14 @@ HttpDataHandler::appendDataToHTTPChannel
(HttpThreadContext *td,
*/
void
HttpDataHandler::checkDataChunks (HttpThreadContext* td, bool* keepalive,
- bool* useChunks)
+ bool* useChunks, bool disableEncoding)
{
*keepalive = td->request.isKeepAlive ();
*useChunks = false;
*keepalive &= !td->request.ver.compare ("HTTP/1.1");
- if (*keepalive)
+ if (!disableEncoding && *keepalive)
{
HttpResponseHeader::Entry *e;
e = td->response.other.get ("transfer-encoding");
@@ -262,3 +262,30 @@ HttpDataHandler::completeHTTPResponse (HttpThreadContext
*td,
return ret;
}
+
+/*!
+ Populate a FiltersChain object ensuring desired filters are supported by the
+ client.
+ */
+size_t
+HttpDataHandler::generateFiltersChain (HttpThreadContext *td,
+ FiltersFactory *factory,
+ FiltersChain &fc,
+ MimeRecord *mime,
+ MemoryStream &memStream)
+{
+ size_t nbw;
+ HttpRequestHeader::Entry* e = td->request.other.get ("accept-encoding");
+ memStream.refresh ();
+ factory->chain (&fc, mime->filters, &memStream, &nbw, 0, false,
+ e ? e->value : "");
+
+
+ if (fc.hasModifiersFilters ())
+ {
+ string filters;
+ fc.getName (filters);
+ td->response.setValue ("content-encoding", filters.c_str ());
+ }
+ return nbw;
+}
-----------------------------------------------------------------------
Summary of changes:
myserver/include/protocol/http/http_data_handler.h | 10 ++-
myserver/src/http_handler/http_file/http_file.cpp | 84 +++-----------------
myserver/src/protocol/http/http_data_handler.cpp | 31 +++++++-
3 files changed, 50 insertions(+), 75 deletions(-)
hooks/post-receive
--
GNU MyServer
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [myserver-commit] [SCM] GNU MyServer branch, master, updated. v0.9.2-472-g1452a92,
Giuseppe Scrivano <=