mirror of
https://github.com/gnustep/libs-gsweb.git
synced 2025-02-21 02:41:04 +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>
|
||||
* GSWeb/GSWResourceManager.m
|
||||
make url prefix dynamic based on [request _applicationURLPrefix]
|
||||
|
|
|
@ -214,12 +214,9 @@ void _sendMessage(GSWResponse * message, NSFileHandle* fh, NSString * httpVersio
|
|||
int contentLength = 0;
|
||||
BOOL keepAlive = NO;
|
||||
BOOL requestIsHead = NO;
|
||||
NSString * eTagString = nil;
|
||||
NSString * ifNoneMatchValue;
|
||||
|
||||
if (message) {
|
||||
contentLength = [message _contentLength];
|
||||
eTagString = [message headerForKey:@"ETag"];
|
||||
}
|
||||
|
||||
if (request) {
|
||||
|
@ -228,12 +225,6 @@ void _sendMessage(GSWResponse * message, NSFileHandle* fh, NSString * httpVersio
|
|||
keepAlive = [connectionValue isEqualToString:KEEP_ALIVE];
|
||||
}
|
||||
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])];
|
||||
|
|
|
@ -39,8 +39,12 @@
|
|||
|
||||
-(GSWResponse*)handleRequest:(GSWRequest*)aRequest;
|
||||
-(GSWResponse*)_responseForJavaClassAtPath:(NSString*)aPath;
|
||||
-(GSWResponse*)_responseForDataAtPath:(NSString*)aPath;
|
||||
|
||||
-(GSWResponse*)_responseForDataAtPath:(NSString*)aPath
|
||||
request:(GSWRequest*)aRequest;
|
||||
|
||||
-(GSWResponse*)_responseForDataCachedWithKey:(NSString*)aKey;
|
||||
|
||||
-(GSWResponse*)_generateResponseForData:(NSData*)aData
|
||||
mimeType:(NSString*)mimeType;
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ RCS_ID("$Id$")
|
|||
} else {
|
||||
filePath = [self _filepathForUripath:urlRequestHandlerPath];
|
||||
|
||||
response = [self _responseForDataAtPath:filePath];
|
||||
response = [self _responseForDataAtPath:filePath request:aRequest];
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:DidHandleRequestNotification
|
||||
|
@ -149,27 +149,57 @@ RCS_ID("$Id$")
|
|||
};
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
-(GSWResponse*)_responseForDataAtPath:(NSString*)aPath
|
||||
-(GSWResponse*)_responseForDataAtPath:(NSString*)aPath
|
||||
request:(GSWRequest*)aRequest
|
||||
{
|
||||
NSUInteger fileLength = 0;
|
||||
NSString * contentType;
|
||||
NSData * fileData;
|
||||
GSWResponse * aResponse;
|
||||
NSDictionary * attributes;
|
||||
NSDate * modDate;
|
||||
NSString * eTagString;
|
||||
NSString * dateString;
|
||||
NSString * hashString;
|
||||
NSString * ifNoneMatchValue;
|
||||
|
||||
|
||||
fileData = [NSData dataWithContentsOfFile:aPath];
|
||||
|
||||
if (!fileData) {
|
||||
attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:aPath
|
||||
error:NULL];
|
||||
modDate = [attributes fileModificationDate];
|
||||
|
||||
if (!modDate) {
|
||||
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 setStatus:200];
|
||||
[aResponse setHeader:[NSString stringWithFormat:@"%d",[fileData length]]
|
||||
forKey:@"content-length"];
|
||||
[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];
|
||||
}
|
||||
|
||||
contentType = [[GSWApp resourceManager] contentTypeForResourcePath:aPath];
|
||||
|
||||
if (contentType)
|
||||
{
|
||||
|
@ -177,7 +207,6 @@ RCS_ID("$Id$")
|
|||
forKey:@"content-type"];
|
||||
}
|
||||
|
||||
[aResponse setContent:fileData];
|
||||
|
||||
return aResponse;
|
||||
}
|
||||
|
|
|
@ -280,11 +280,13 @@ void GSWResponse_appendTagAttributeValueEscapingHTMLAttributeValue(GSWResponse*
|
|||
dataLength=[self _contentLength];
|
||||
|
||||
if (dataLength>0) {
|
||||
NSString * eTagString = [NSString stringWithFormat:@"%lx",
|
||||
/*
|
||||
NSString * eTagString = [NSString stringWithFormat:@"%lx",
|
||||
(unsigned long) [_contentData hash]];
|
||||
|
||||
[self setHeader:eTagString
|
||||
forKey:@"ETag"];
|
||||
*/
|
||||
}
|
||||
|
||||
// Now we see if we can gzip the content
|
||||
|
|
Loading…
Reference in a new issue