Skip to content

Commit

Permalink
rename tagging name
Browse files Browse the repository at this point in the history
  • Loading branch information
Joungkyun committed Sep 26, 2013
1 parent f3b9cb0 commit ed94593
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 409 deletions.
147 changes: 20 additions & 127 deletions HTTPRelay.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
* HTTPRelay 패키지는 HTTP 요청을 간단하게 하거나 또는 HTTP
* 요청을 다른 서버로 Relay를 하기 위한 기능을 제공한다.
*
* 예제:
* {@example pear_HTTPRelay/tests/test.php}
*
* @category HTTP
* @package HTTPRelay
* @author JoungKyun.Kim <http:https://oops.org>
Expand All @@ -20,19 +17,13 @@
* @filesource
*/

/**
* import myException API
*/
@require_once 'myException.php';
HTTPRelay_REQUIRES ();

/**
* HTTPRelay 패키지는 HTTP 요청을 간단하게 하거나 또는 HTTP
* 요청을 다른 서버로 Relay를 하기 위한 기능을 제공한다.
*
* 예제:
* {@example pear_HTTPRelay/tests/test.php}
*
* @package HTTPRelay
*/
Class HTTPRelay {
Expand All @@ -45,36 +36,24 @@
* @access public
*/
/**
* 에러 발생시에 에러 메시지 저장
* 에러 메시지 저장
* @var string
*/
static public $error = '';
/**
* HTTP 요청 정보 결과 저장
* HTTP 요청 결과 저장
* @var array
*/
public $info = null;
/**
* Post data encoding type
*
* Post data를 어떤 방식으로 인코딩 할지를 결정한다.
* 'url-encode'와 'form-data' 둘 중의 하나로 지정을 해야 한다.
* Post data에 파일 전송을 하기 위해서는 무조건 'form-data'로
* 지정을 해야 한다.
*
* @var string
*/
public $posttype = 'url-encode';
/**#@-*/
/**
* User Define Header
*
* 사용자 Request header를 배열로 지정한다.
* 배열 키는 Header Name으로 지정하며, 배열값에는 Header의 값을 지정한다.
* 배열값을 '-'으로 지정을 하면, 빈 값으로 처리를 한다.
*
* {@example pear_HTTPRelay/tests/test-relay.php 30 1}
*
* @access private
* @var array
*/
Expand All @@ -85,24 +64,18 @@
/**
* HTTPRelay 초기화
*
* 예제:
* {@example pear_HTTPRelay/tests/test-relay.php 23 6}
*
* @access public
* @param array $header (optional) 사용자 정의 HTTP Header
* @param array $header 사용자 정의 HTTP Header
* - Key는 Header 이름이엉야 하며 '-'는 '_'로 표기한다.
* - Heder값이 없어야 할 경우에는 값을 '-'로 넣어준다.
* - Key값에 POSTTYPE을 지정할 경우, Post encoding 방식을
* 직접 지정이 가능하다. 이 경우 POSTTYPE은 HTTP Header
* 에 영향을 주지 않으며, 값으로는 'form-data'와 'url-encode'
* 중에 지정할 수 있다. POSTTYPE은 제거될 예정이니 $posttype
* property를 직접 설정하여야 한다.
*
* 중에 지정할 수 있다.
*/
function __construct ($header = null) {
$this->error = &self::$error;

// deprecated soon
if ( $header['POSTTYPE'] ) {
switch ($header['POSTTYPE']) {
case 'form-data' :
Expand All @@ -111,99 +84,30 @@ function __construct ($header = null) {
}
unset ($header['POSTTYPE']);
}
// deprecated soon

if ( is_array ($header) )
$this->header = &$header;
}
// }}}

/**
* HTTP/1.1 HEAD 요청
*
* 예제:
* {@example pear_HTTPRelay/tests/test-head.php}
*
* @access public
* @return stdClass
* @param string $to 요청할 URL
* @param int $tmout (optional) timeout 값
* @param string $httphost (optional) HTTP/1.1 Host Header. 지정을 하지 않을 경우
* $to의 도메인으로 지정됨
* @sinse 1.0.2
*/
public function head ($to, $tmout = 60, $httphost = '') {
if ( ! trim ($to) )
return null;

if ( ! is_resource ($c = curl_init ()) )
return null;

# header information
$header = self::http_header ();

curl_setopt ($c, CURLOPT_URL, $to);
curl_setopt ($c, CURLOPT_TIMEOUT, $tmout);
curl_setopt ($c, CURLOPT_NOPROGRESS, 1);
curl_setopt ($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt (
$c, CURLOPT_USERAGENT,
$this->header['User_Agent'] ? $this->header['User_Agent'] : self::UAGENT
);
curl_setopt ($c, CURLOPT_HEADER, 1);
curl_setopt ($c, CURLOPT_NOBODY, 1);
curl_setopt ($c, CURLOPT_HTTPHEADER, $header);
curl_setopt ($c, CURLOPT_FAILONERROR, 1);
curl_setopt ($c, CURLINFO_HEADER_OUT, 1);

$data = curl_exec ($c);

if ( curl_errno ($c) ) {
self::$error = curl_error ($c);
return false;
}

$this->info = curl_getinfo ($c);
curl_close ($c);

$r = new stdClass;
$content = preg_split ('/\r\n/', trim ($data));
foreach ( $content as $v ) {
$v = trim ($v);
if ( preg_match ('!^HTTP/([0-9.]+) ([0-9]+) (.*)!', $v, $matches) ) {
$r->{'VERSION'} = $matches[1];
$r->{'RETURN-CODE'} = $matches[2];
$r->{'RETURN-MSG'} = $matches[3];
continue;
}
$tmp = preg_split ('/:[\s]+/', $v);
$r->{$tmp[0]} = $tmp[1];
}

return $r;
}

// {{{ +-- public (string) fetch ($to, $tmout = 60, $httphost = '', $post = null)
/**
* HTML 요청의 결과를 반환한다.
*
* 예제:
* {@example pear_HTTPRelay/tests/test.php}
*
* @access public
* @return string
* @param string $to 요청할 URL
* @param int $tmout (optional) timeout 값
* @param string $httphost (optional) HTTP/1.1 Host Header. 지정을 하지 않을 경우
* @param int $tmout timeout 값
* @param string $httphost HTTP/1.1 Host Header. 지정을 하지 않을 경우
* $to의 도메인으로 지정됨
* @param array $post (optional) Post방식으로 요청시 전송할 Post data
* @param array $post Post방식으로 요청시 전송할 Post data
*/
public function fetch ($to, $tmout = 60, $httphost = '', $post = null) {
if ( ! trim ($to) )
return null;
return '';

if ( ! is_resource ($c = curl_init ()) )
return null;
return '';

# header information
$header = self::http_header ();
Expand All @@ -220,7 +124,6 @@ public function fetch ($to, $tmout = 60, $httphost = '', $post = null) {
curl_setopt ($c, CURLOPT_NOBODY, 0);
curl_setopt ($c, CURLOPT_HTTPHEADER, $header);
curl_setopt ($c, CURLOPT_FAILONERROR, 1);
curl_setopt ($c, CURLINFO_HEADER_OUT, 1);

if ( $post && is_array ($post) ) {
curl_setopt ($c, CURLOPT_POST, 1);
Expand All @@ -247,22 +150,19 @@ public function fetch ($to, $tmout = 60, $httphost = '', $post = null) {
/**
* HTML 요청을 다른 호스트로 중계를 한다.
*
* 예제:
* {@example pear_HTTPRelay/tests/test.php}
*
* @access public
* @return string
* @param string $to 중계할 URL
* @param int $tmout (optional) timeout 값
* @param string $httphost (optional) HTTP/1.1 Host Header. 지정을 하지 않을 경우
* @param int $tmout timeout 값
* @param string $httphost HTTP/1.1 Host Header. 지정을 하지 않을 경우
* $to의 도메인으로 지정됨
*/
public function relay ($to, $tmout = 60, $httphost = '') {
if ( ! trim ($to) )
return null;
return '';

if ( ! is_resource ($c = curl_init ()) )
return null;
return '';

# basic information
$uri = trim ($_SERVER['QUERY_STRING']);
Expand All @@ -285,7 +185,6 @@ public function relay ($to, $tmout = 60, $httphost = '') {
curl_setopt ($c, CURLOPT_NOBODY, 0);
curl_setopt ($c, CURLOPT_HTTPHEADER, $header);
curl_setopt ($c, CURLOPT_FAILONERROR, 1);
curl_setopt ($c, CURLINFO_HEADER_OUT, 1);

self::relay_post ($c);

Expand Down Expand Up @@ -338,7 +237,7 @@ private function http_header () {
}
// }}}

// {{{ +-- private (void) set_header (&$h, $d, $v)
// {{{ +-- private (void) set_header (&$h, $d, $v, $noval = false)
/**
* 헤더를 셋팅한다. 헤더 값이 '-'로 지정이 될 경우, 해당 헤더는
* 빈 값을 가지는 헤더로 처리를 한다.
Expand All @@ -349,7 +248,7 @@ private function http_header () {
* @param string 헤더 이름
* @param string 헤더 값. '-' 값을 가지면, 빈 값을 가지는 헤더라는 의미로 처리된다.
*/
private function set_header (&$h, $d, $v) {
private function set_header (&$h, $d, $v, $noval = false) {
if ( ! trim ($d) || ! trim ($v) )
return;

Expand All @@ -371,7 +270,7 @@ private function set_header (&$h, $d, $v) {
* Hostname (2번째 인자)가 따로 지정되지 않으면 주어진 Full URL(1번째 인자)
* 에서 hostname을 구한다.
*
* @access private
* @acces private
* @return string
* @param string 전체 URL
* @param string HTTP/1.1 Host header 값
Expand All @@ -387,15 +286,15 @@ private function http_host ($t, $h) {
}
// }}}

// {{{ +-- private (void) relay_post (&$c)
// {{{ +-- public (void) relay_post (&$c)
/**
* Post로 넘어온 Data를 relay하기 위한 post data template
*
* @access private
* @return void
* @param resource CURL resource
*/
private function relay_post (&$c) {
function relay_post (&$c) {
if ( $_SERVER['REQUEST_METHOD'] != 'POST' )
return;

Expand All @@ -419,10 +318,10 @@ private function relay_post (&$c) {
/**
* Relay를 위한 Client IP 주소 설정
*
* @access private
* @acces private
* @return void
* @param array 헤더 저장 변수
* @param string (optional) IP 주소
* @param string IP 주소
*/
private function client_ip_set (&$h, $ip = null) {
if ( php_sapi_name () == 'cli' )
Expand All @@ -444,12 +343,6 @@ private function client_ip_set (&$h, $ip = null) {
}

// {{{ +-- public HTTPRelay_REQUIRES (void)
/**
* HTTRelay 패키지에서 필요한 의존성을 검사한다.
*
* @access public
* @return void
*/
function HTTPRelay_REQUIRES () {
$br = PHP_EOL;
if ( PHP_SAPI != 'cli' )
Expand Down
21 changes: 0 additions & 21 deletions pack.sh

This file was deleted.

31 changes: 9 additions & 22 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,25 @@
<email>[email protected]</email>
<active>yes</active>
</lead>
<date>2013-09-26</date>
<time>17:18:16</time>
<date>2013-09-24</date>
<time>18:47:10</time>
<version>
<release>1.0.2</release>
<release>1.0.1</release>
<api>1.0.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license>BSD</license>
<notes>* 1.0.2 release
* add head method for requesting HTTP/1.1 HEAD method
<notes>* 1.0.1 release
* fixed typo CURL_FAILONERROR to CURLOPT_FAILONERROR
* add myException dependency
* add posttype public property ('form-data', 'url-encode')
</notes>
<contents>
<dir name="/">
<file role="php" md5sum="afd5faee24c9a3ad1ca2da21a8ae79c0" name="HTTPRelay.php" />
<file role="php" md5sum="068e26d1a7b0e3363a8db88304d4e5c5" name="HTTPRelay.php" />
</dir>
</contents>
<dependencies>
Expand All @@ -47,21 +49,6 @@
</dependencies>
<phprelease />
<changelog>
<release>
<version>
<release>1.0.2</release>
<api>1.0.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<date>2013-09-26</date>
<license>BSD</license>
<notes>* release 1.0.2
* add head method for requesting HTTP/1.1 HEAD method
</notes>
</release>
<release>
<version>
<release>1.0.1</release>
Expand All @@ -71,7 +58,7 @@
<release>stable</release>
<api>stable</api>
</stability>
<date>2013-09-24 18:47:10</date>
<date>2013-09-24</date>
<license>BSD</license>
<notes>* release 1.0.1
* fixed typo CURL_FAILONERROR to CURLOPT_FAILONERROR
Expand Down
Loading

0 comments on commit ed94593

Please sign in to comment.