2007-06-22 David Wetzel <dave@turbocat.de>

* GSWAdaptors/Apache2/mod_gsw.c
    * GSWSWeb.framework/GSWComponentRequestHandler.m
    * GSWeb.framework/GSWDefaultAdaptorThread.m

    Added support for POST requests from browsers without content-length header.
    (firefox does this without proxy)



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@25287 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Dave Wetzel 2007-06-22 16:12:16 +00:00
parent 65765a9412
commit 1e6833238c
4 changed files with 85 additions and 55 deletions

View file

@ -1,3 +1,11 @@
2007-06-22 David Wetzel <dave@turbocat.de>
* GSWAdaptors/Apache2/mod_gsw.c
* GSWSWeb.framework/GSWComponentRequestHandler.m
* GSWeb.framework/GSWDefaultAdaptorThread.m
Added support for POST requests from browsers without content-length header.
(firefox does this without proxy)
2007-05-15 David Wetzel <dave@turbocat.de> 2007-05-15 David Wetzel <dave@turbocat.de>
* GSWAdaptors/Apache2 * GSWAdaptors/Apache2
made Application name clickable on status page made Application name clickable on status page

View file

@ -1,39 +1,25 @@
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* /*
* Apache gsw module. Provide demonstrations of how modules do things. Copyright (C) 1999, 2000 Free Software Foundation, Inc.
* It is not meant to be used in a production server. Since it participates
* in all of the processing phases, it could conceivable interfere with Written by: David Wetzel <dave@turbocat.de>
* the proper operation of other modules -- particularly the ones related Based on Apache2 Sample Module
* to security.
* This file is part of the GNUstep Web Library.
* In the interest of brevity, all functions and structures internal to
* this module, but which may have counterparts in *real* modules, are This library is free software; you can redistribute it and/or
* prefixed with 'gsw_' instead of 'gsw_'. modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* IMPORTANT NOTE version 2 of the License, or (at your option) any later version.
* ==============
* This library is distributed in the hope that it will be useful,
* Some of the code in this module has problems. but WITHOUT ANY WARRANTY; without even the implied warranty of
* Before using it to base your work on, see MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* http://issues.apache.org/bugzilla/show_bug.cgi?id=29709
* http://issues.apache.org/bugzilla/show_bug.cgi?id=32051 You should have received a copy of the GNU Library General Public
*/ License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "httpd.h" #include "httpd.h"
#include "http_config.h" #include "http_config.h"
@ -672,28 +658,26 @@ void * read_sock_line(int socket, request_rec *r, apr_pool_t * pool)
while (((done == 0) && (i < sizeof(buffer) -1)) && (rval >0)) { while (((done == 0) && (i < sizeof(buffer) -1)) && (rval >0)) {
rval= read(socket, &b, 1); rval= read(socket, &b, 1);
buffer[i] = b; buffer[i] = b;
if (b == '\n') { if (b == '\n') {
done = 1; done = 1;
buffer[i] = '\0'; buffer[i] = '\0';
}
i++;
} }
i++;
// buffer[i] = '\0';
// ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "got:'%s'", buffer);
} buffer[i] = '\0';
buffer[i] = '\0';
// in case we got a \0 in the string? // in case we got a \0 in the string?
i = strlen(buffer); i = strlen(buffer);
if (i > 0) {
if (i > 0) { void * newBuf = apr_palloc(pool,i+1);
void * newBuf = apr_palloc(pool,i+1); strncpy(newBuf, buffer, i+1);
strncpy(newBuf, buffer, i+1); // ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "read_sock_line:'%s'", newBuf);
return newBuf; return newBuf;
} }
return NULL; return NULL;
} }
@ -763,7 +747,8 @@ static int handle_request(request_rec *r, gsw_app_conf * app)
} }
if (ap_setup_client_block(r, REQUEST_CHUNKED_ERROR) != OK) { if (ap_setup_client_block(r, REQUEST_CHUNKED_ERROR) != OK) {
return DECLINED; ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "handle_request: DECLINED");
return DECLINED;
} }
// check if we are on a POST trip... // check if we are on a POST trip...
@ -787,6 +772,7 @@ static int handle_request(request_rec *r, gsw_app_conf * app)
postbuf = apr_palloc(sub_pool,1024*8+1); postbuf = apr_palloc(sub_pool,1024*8+1);
// TODO: check if we need to transfer the last CR / NL from the POST data.
while (bytesread > 0) { while (bytesread > 0) {
bytesread = ap_get_client_block(r, postbuf, 1024*8); bytesread = ap_get_client_block(r, postbuf, 1024*8);
@ -797,8 +783,8 @@ static int handle_request(request_rec *r, gsw_app_conf * app)
postbuf[bytesread]='\0'; postbuf[bytesread]='\0';
write_sock(soc, postbuf, bytesread, r); write_sock(soc, postbuf, bytesread, r);
} }
postbuf[0]='\0'; // postbuf[0]='\0';
write_sock(soc, postbuf, 1, r); // write_sock(soc, postbuf, 1, r);
} }
write_sock(soc, CRLF, 2, r); write_sock(soc, CRLF, 2, r);

View file

@ -76,6 +76,8 @@ RCS_ID("$Id$")
NSDictionary* requestHandlerValues=nil; NSDictionary* requestHandlerValues=nil;
BOOL exceptionRaised=NO; BOOL exceptionRaised=NO;
// NSLog(@"%s %@",__PRETTY_FUNCTION__, aRequest);
NS_DURING NS_DURING
{ {
requestHandlerValues=[GSWComponentRequestHandler _requestHandlerValuesForRequest:aRequest]; requestHandlerValues=[GSWComponentRequestHandler _requestHandlerValuesForRequest:aRequest];

View file

@ -368,6 +368,36 @@ NSMutableArray* unpackData(NSMutableData* data)
return headers; return headers;
} }
- (NSData*) _readPostData
{
#define UPLOAD_LIMIT 1024*1024*10 // 10 MB
#define TIME_LIMIT 30 // 30 seconds
time_t starttime, now;
int totalLen = 0;
BOOL isElapsed = NO;
NSMutableData* allMimeData = nil;
time(&starttime);
while ((! isElapsed) && ([allMimeData length] <= UPLOAD_LIMIT)) {
NSData* dataBlock = [_stream readDataOfLengthNonBlocking:1024];
if (dataBlock) {
if (!allMimeData) {
allMimeData = (NSMutableData*)[NSMutableData data];
}
[allMimeData appendData:dataBlock];
} else {
break;
}
time(&now);
isElapsed = ((now - starttime) > TIME_LIMIT);
}
return allMimeData;
}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
/** read request from crrent stream and put request line, headers and data in /** read request from crrent stream and put request line, headers and data in
@ -440,6 +470,7 @@ NSMutableArray* unpackData(NSMutableData* data)
if ((myArray) && ([myArray count])) { if ((myArray) && ([myArray count])) {
contentLength = [[myArray objectAtIndex:0] intValue]; contentLength = [[myArray objectAtIndex:0] intValue];
//
if (contentLength > 0) { if (contentLength > 0) {
if (!allMimeData) { if (!allMimeData) {
allMimeData = (NSMutableData*)[NSMutableData data]; allMimeData = (NSMutableData*)[NSMutableData data];
@ -452,6 +483,9 @@ NSMutableArray* unpackData(NSMutableData* data)
isElapsed = ((now - starttime) > 30); isElapsed = ((now - starttime) > 30);
} }
} }
//
} else { // no content length info
allMimeData = [self _readPostData];
} }
allDataRead = YES; allDataRead = YES;
} else { } else {