mirror of
https://github.com/gnustep/libs-gsweb.git
synced 2025-02-22 19:21:23 +00:00
* GSWeb/GSWResponse.m
* GSWeb/GSWHTTPIO.m do not add ETag * GSWeb/GSWResourceRequestHandler.h add request: argument to _responseForDataAtPath: * GSWeb/GSWResourceRequestHandler.m add request: argument to _responseForDataAtPath: _responseForDataAtPath:request: generate Last-Modified header generate ETag header use hash of modification date and size (faster than over a large NSData object) check for if-none-match header git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@30832 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b8b1e1318e
commit
3fb75c4004
5 changed files with 65 additions and 24 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
||||||
|
2010-06-22 David Wetzel <dave@turbocat.de>
|
||||||
|
* GSWeb/GSWResponse.m
|
||||||
|
* GSWeb/GSWHTTPIO.m
|
||||||
|
do not add ETag
|
||||||
|
* GSWeb/GSWResourceRequestHandler.h
|
||||||
|
add request: argument to _responseForDataAtPath:
|
||||||
|
* GSWeb/GSWResourceRequestHandler.m
|
||||||
|
add request: argument to _responseForDataAtPath:
|
||||||
|
_responseForDataAtPath:request:
|
||||||
|
generate Last-Modified header
|
||||||
|
generate ETag header
|
||||||
|
use hash of modification date and size
|
||||||
|
(faster than over a large NSData object)
|
||||||
|
check for if-none-match header
|
||||||
|
|
||||||
2010-06-22 David Wetzel <dave@turbocat.de>
|
2010-06-22 David Wetzel <dave@turbocat.de>
|
||||||
* GSWeb/GSWResourceManager.m
|
* GSWeb/GSWResourceManager.m
|
||||||
make url prefix dynamic based on [request _applicationURLPrefix]
|
make url prefix dynamic based on [request _applicationURLPrefix]
|
||||||
|
|
|
@ -214,12 +214,9 @@ void _sendMessage(GSWResponse * message, NSFileHandle* fh, NSString * httpVersio
|
||||||
int contentLength = 0;
|
int contentLength = 0;
|
||||||
BOOL keepAlive = NO;
|
BOOL keepAlive = NO;
|
||||||
BOOL requestIsHead = NO;
|
BOOL requestIsHead = NO;
|
||||||
NSString * eTagString = nil;
|
|
||||||
NSString * ifNoneMatchValue;
|
|
||||||
|
|
||||||
if (message) {
|
if (message) {
|
||||||
contentLength = [message _contentLength];
|
contentLength = [message _contentLength];
|
||||||
eTagString = [message headerForKey:@"ETag"];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request) {
|
if (request) {
|
||||||
|
@ -228,12 +225,6 @@ void _sendMessage(GSWResponse * message, NSFileHandle* fh, NSString * httpVersio
|
||||||
keepAlive = [connectionValue isEqualToString:KEEP_ALIVE];
|
keepAlive = [connectionValue isEqualToString:KEEP_ALIVE];
|
||||||
}
|
}
|
||||||
requestIsHead = [[request method] isEqualToString:HEAD];
|
requestIsHead = [[request method] isEqualToString:HEAD];
|
||||||
ifNoneMatchValue = [request headerForKey:@"if-none-match"];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ([ifNoneMatchValue isEqualToString:eTagString]) {
|
|
||||||
// return 304 Not Modified
|
|
||||||
[message setStatus:304];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[headers appendString:GSWIntToNSString([message status])];
|
[headers appendString:GSWIntToNSString([message status])];
|
||||||
|
|
|
@ -39,8 +39,12 @@
|
||||||
|
|
||||||
-(GSWResponse*)handleRequest:(GSWRequest*)aRequest;
|
-(GSWResponse*)handleRequest:(GSWRequest*)aRequest;
|
||||||
-(GSWResponse*)_responseForJavaClassAtPath:(NSString*)aPath;
|
-(GSWResponse*)_responseForJavaClassAtPath:(NSString*)aPath;
|
||||||
-(GSWResponse*)_responseForDataAtPath:(NSString*)aPath;
|
|
||||||
|
-(GSWResponse*)_responseForDataAtPath:(NSString*)aPath
|
||||||
|
request:(GSWRequest*)aRequest;
|
||||||
|
|
||||||
-(GSWResponse*)_responseForDataCachedWithKey:(NSString*)aKey;
|
-(GSWResponse*)_responseForDataCachedWithKey:(NSString*)aKey;
|
||||||
|
|
||||||
-(GSWResponse*)_generateResponseForData:(NSData*)aData
|
-(GSWResponse*)_generateResponseForData:(NSData*)aData
|
||||||
mimeType:(NSString*)mimeType;
|
mimeType:(NSString*)mimeType;
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,7 @@ RCS_ID("$Id$")
|
||||||
} else {
|
} else {
|
||||||
filePath = [self _filepathForUripath:urlRequestHandlerPath];
|
filePath = [self _filepathForUripath:urlRequestHandlerPath];
|
||||||
|
|
||||||
response = [self _responseForDataAtPath:filePath];
|
response = [self _responseForDataAtPath:filePath request:aRequest];
|
||||||
}
|
}
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:DidHandleRequestNotification
|
[[NSNotificationCenter defaultCenter] postNotificationName:DidHandleRequestNotification
|
||||||
|
@ -150,26 +150,56 @@ RCS_ID("$Id$")
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
-(GSWResponse*)_responseForDataAtPath:(NSString*)aPath
|
-(GSWResponse*)_responseForDataAtPath:(NSString*)aPath
|
||||||
|
request:(GSWRequest*)aRequest
|
||||||
{
|
{
|
||||||
NSUInteger fileLength = 0;
|
|
||||||
NSString * contentType;
|
NSString * contentType;
|
||||||
NSData * fileData;
|
NSData * fileData;
|
||||||
GSWResponse * aResponse;
|
GSWResponse * aResponse;
|
||||||
|
NSDictionary * attributes;
|
||||||
|
NSDate * modDate;
|
||||||
|
NSString * eTagString;
|
||||||
|
NSString * dateString;
|
||||||
|
NSString * hashString;
|
||||||
|
NSString * ifNoneMatchValue;
|
||||||
|
|
||||||
|
attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:aPath
|
||||||
|
error:NULL];
|
||||||
|
modDate = [attributes fileModificationDate];
|
||||||
|
|
||||||
fileData = [NSData dataWithContentsOfFile:aPath];
|
if (!modDate) {
|
||||||
|
|
||||||
if (!fileData) {
|
|
||||||
return [self _404ResponseForPath:aPath];
|
return [self _404ResponseForPath:aPath];
|
||||||
}
|
}
|
||||||
|
|
||||||
contentType = [[GSWApp resourceManager] contentTypeForResourcePath:aPath];
|
dateString = [modDate descriptionWithCalendarFormat:@"%a, %d %b %Y %H:%M:%S GMT"
|
||||||
|
timeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]
|
||||||
|
locale:nil];
|
||||||
|
|
||||||
aResponse = [GSWApp createResponseInContext:nil];
|
aResponse = [GSWApp createResponseInContext:nil];
|
||||||
|
|
||||||
|
[aResponse setHeader:dateString
|
||||||
|
forKey:@"Last-Modified"];
|
||||||
|
|
||||||
|
hashString = [NSString stringWithFormat:@"%@-%@", dateString, [attributes objectForKey:NSFileSize]];
|
||||||
|
|
||||||
|
eTagString = [NSString stringWithFormat:@"%lx", (unsigned long) [hashString hash]];
|
||||||
|
|
||||||
|
[aResponse setHeader:eTagString
|
||||||
|
forKey:@"ETag"];
|
||||||
|
|
||||||
|
ifNoneMatchValue = [aRequest headerForKey:@"if-none-match"];
|
||||||
|
|
||||||
|
if ([ifNoneMatchValue isEqualToString:eTagString]) {
|
||||||
|
// return 304 Not Modified
|
||||||
|
[aResponse setStatus:304];
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
fileData = [NSData dataWithContentsOfFile:aPath];
|
||||||
|
[aResponse setContent:fileData];
|
||||||
[aResponse setStatus:200];
|
[aResponse setStatus:200];
|
||||||
[aResponse setHeader:[NSString stringWithFormat:@"%d",[fileData length]]
|
}
|
||||||
forKey:@"content-length"];
|
|
||||||
|
contentType = [[GSWApp resourceManager] contentTypeForResourcePath:aPath];
|
||||||
|
|
||||||
if (contentType)
|
if (contentType)
|
||||||
{
|
{
|
||||||
|
@ -177,7 +207,6 @@ RCS_ID("$Id$")
|
||||||
forKey:@"content-type"];
|
forKey:@"content-type"];
|
||||||
}
|
}
|
||||||
|
|
||||||
[aResponse setContent:fileData];
|
|
||||||
|
|
||||||
return aResponse;
|
return aResponse;
|
||||||
}
|
}
|
||||||
|
|
|
@ -280,11 +280,13 @@ void GSWResponse_appendTagAttributeValueEscapingHTMLAttributeValue(GSWResponse*
|
||||||
dataLength=[self _contentLength];
|
dataLength=[self _contentLength];
|
||||||
|
|
||||||
if (dataLength>0) {
|
if (dataLength>0) {
|
||||||
|
/*
|
||||||
NSString * eTagString = [NSString stringWithFormat:@"%lx",
|
NSString * eTagString = [NSString stringWithFormat:@"%lx",
|
||||||
(unsigned long) [_contentData hash]];
|
(unsigned long) [_contentData hash]];
|
||||||
|
|
||||||
[self setHeader:eTagString
|
[self setHeader:eTagString
|
||||||
forKey:@"ETag"];
|
forKey:@"ETag"];
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we see if we can gzip the content
|
// Now we see if we can gzip the content
|
||||||
|
|
Loading…
Reference in a new issue