Skip to content

Commit

Permalink
fix one-off bug in evhttp_request_body()
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardValenti committed Jan 6, 2011
1 parent 382b257 commit 96546a7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion demos/zf-apiserver/bin/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function processRequest($r)
try
{
printf("Used script-land memory %.2f MB\n", memory_get_usage()/(1024*1024));
$uri = evhttp_request_uri($r);
$uri = evhttp_request_get_uri($r);
$parts = parse_url($uri);

// let's process the request with the chosen webservice protocol
Expand Down
28 changes: 14 additions & 14 deletions demos/zf/bin/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AppServer
private $logger = null;
private $base = null;
private $config = null;


private function _startupSuperGlobal()
{
Expand All @@ -28,30 +28,30 @@ private function _startupSuperGlobal()
$_SERVER[ "SERVER_SOFTWARE" ] = "EvHttp ZF Application Server 0.1";
$_SERVER[ "SERVER_PROTOCOL" ] = 'HTTP 1.1';
}

public function __construct($addr="127.0.0.1", $port=8080)
{
$this->port = $port;
$this->addr = $addr;
$this->_startupSuperGlobal();

// Setup basic stuff
error_reporting(E_ALL & ~E_NOTICE);

$base = realpath(dirname(__FILE__) . '/../');
$paths = array(
'.',
'.',
realpath($base . '/library'),
get_include_path(),
);
$this->base = $base;

// Setup autoloading ...
set_include_path(implode(PATH_SEPARATOR, $paths));
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('EvHttp_');

$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
'basePath' => realpath($base . '/application'),
'namespace' => '',
Expand All @@ -66,11 +66,11 @@ public function __construct($addr="127.0.0.1", $port=8080)
),
),
));

// Load config
$this->config = new Zend_Config_Ini($this->base . '/deploy/config.ini', 'default');
Zend_Registry::set('config', $this->config);

// Connect database
$dbType = $this->config->database->type;
$params = $this->config->database->toArray();
Expand All @@ -92,30 +92,30 @@ private function _initRequest($r)
{
$_SERVER[ "REQUEST_METHOD" ] = evhttp_request_method($r);
$_SERVER[ "REQUEST_TIME" ] = time();
$_SERVER[ "argv" ] = $_SERVER[ "REQUEST_URI" ] = evhttp_request_uri($r);
$_SERVER[ "argv" ] = $_SERVER[ "REQUEST_URI" ] = evhttp_request_get_uri($r);

$parts = parse_url($_SERVER["REQUEST_URI"]);
$_SERVER['QUERY_STRING'] = $parts['query'];
parse_str($_SERVER['QUERY_STRING'], $_GET);

$headers = evhttp_request_headers($r);
// normalize to php way
foreach ($headers as $name => $value)
$_SERVER["HTTP_" . str_replace("-", "_", strtoupper($name))] = $value;

echo "script-land memory: ".memory_get_usage()."\n";
}

public function processRequest($r)
{
try
{
{
$this->_initRequest($r);
$response = $this->controller->dispatch();
}
catch(Exception $e)
{
return $e->__toString();
return $e->__toString();
}
return evhttp_response_set($response->getBody(), $response->getHttpResponseCode(), "OK");
}
Expand Down
11 changes: 6 additions & 5 deletions event.c
Original file line number Diff line number Diff line change
Expand Up @@ -802,12 +802,12 @@ PHP_FUNCTION(evhttp_request_method)
RETURN_STRING("PUT", 1);
case EVHTTP_REQ_DELETE:
RETURN_STRING("DELETE", 1);
/* case EVHTTP_REQ_OPTIONS:
case EVHTTP_REQ_OPTIONS:
RETURN_STRING("OPTIONS", 1);
case EVHTTP_REQ_TRACE:
RETURN_STRING("TRACE", 1);
case EVHTTP_REQ_CONNECT:
RETURN_STRING("CONNECT", 1); */
RETURN_STRING("CONNECT", 1);
default:
RETURN_NULL();
}
Expand Down Expand Up @@ -955,15 +955,16 @@ PHP_FUNCTION(evhttp_request_body)

ZEND_FETCH_RESOURCE(req, struct evhttp_request*, &res_req, -1, PHP_EVHTTP_REQUEST_RES_NAME, le_evhttp_request);

body_len = evbuffer_get_length(req->input_buffer);
body_len = EVBUFFER_LENGTH(req->input_buffer);

if (req->input_buffer == NULL || body_len == 0)
{
RETURN_FALSE;
}

body = emalloc(body_len + 1);
status = evbuffer_remove(req->input_buffer, (void *) body, body_len + 1);
status = evbuffer_remove(req->input_buffer, (void *) body, body_len);
body[body_len] = '\0';
if (status == -1) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not get data from resource");
RETURN_FALSE;
Expand Down Expand Up @@ -1651,7 +1652,7 @@ PHP_FUNCTION(evhttp_make_request)
zval *con_res, *req_res;
struct evhttp_connection *con;
struct evhttp_request *req;
long type;
long type;
int url_len;
char *url;
int ret;
Expand Down

0 comments on commit 96546a7

Please sign in to comment.