Browse Source

add prototypes for HTTPRequest/Response and WorkerPool placeholder

master
Brett Langdon 12 years ago
parent
commit
bd0da83d44
3 changed files with 74 additions and 0 deletions
  1. +33
    -0
      src/Drudge/HTTPRequest.php
  2. +35
    -0
      src/Drudge/HTTPResponse.php
  3. +6
    -0
      src/Drudge/WorkerPool.php

+ 33
- 0
src/Drudge/HTTPRequest.php View File

@ -0,0 +1,33 @@
<?php
namespace Drudge;
class HTTPRequest{
public $headers = array();
public $query_string = NULL;
public $path = NULL;
public $method = NULL;
public $body = NULL;
public function __construct($raw_request){
$parsed_request = array();
$parser = uv_http_parser_init();
if(uv_http_parser_execute($parser, $raw_request, $parsed_request)){
$this->headers = $parsed_request['HEADERS'];
$this->method = $parsed_request['REQUEST_METHOD'];
$this->path = $parsed_request['PATH'];
$query_string = $parsed_request['QUERY_STRING'];
$question_pos = strpos($query_string, '?');
if($question_pos !== false){
$this->query_string = substr($query_string, $question_pos + 1);
}
if(array_key_exists('BODY', $this->headers)){
$this->body = $this->headers['BODY'];
unset($this->headers['BODY']);
}
} else{
}
}
}

+ 35
- 0
src/Drudge/HTTPResponse.php View File

@ -0,0 +1,35 @@
<?php
namespace Drudge;
class HTTPResponse{
protected $http_version = '1.1';
protected $headers = array();
protected $cookies = array();
protected $status = '200 Ok';
public function setHeader($name, $value){
$this->headers[$name] = strval($value);
}
public function setCookie($name, $value){
array_push($this->cookies = "{$name}={$value}");
}
public function setStatus($status){
$this->status = $status;
}
public function __toString(){
$response = "HTTP/{$this->http_version} {$this->status}\r\n";
foreach($this->headers as $name => $value){
$response .= "{$name}: {$value}\r\n";
}
if(count($this->cookies)){
$cookies = implode(';', $this->cookies);
$response .= "Cookie: {$cookies}\r\n";
}
return $response;
}
}

+ 6
- 0
src/Drudge/WorkerPool.php View File

@ -0,0 +1,6 @@
<?php
namespace Drudge;
class WorkerPool{
}

Loading…
Cancel
Save