HTTPRelay
[ class tree: HTTPRelay ] [ index: HTTPRelay ] [ all elements ]

Class: HTTPRelay

Source Location: /HTTPRelay/HTTPRelay.php

Class Overview


HTTPRelay 패키지는 HTTP 요청을 간단하게 하거나 또는 HTTP 요청을 다른 서버로 Relay를 하기 위한 기능을 제공한다.


Variables

Constants

Methods



Class Details

[line 37]
HTTPRelay 패키지는 HTTP 요청을 간단하게 하거나 또는 HTTP 요청을 다른 서버로 Relay를 하기 위한 기능을 제공한다.

예제:

  1. <?php
  2. /*
  3.  * Test code for HTTPRelay
  4.  * $Id$
  5.  */
  6.  
  7. $iniget function_exists ('___ini_get''___ini_get' 'ini_get';
  8. $iniset function_exists ('___ini_set''___ini_set' 'ini_set';
  9.  
  10. $cwd getcwd ();
  11. $ccwd basename ($cwd);
  12. if $ccwd == 'tests' {
  13.     $oldpath $iniget ('include_path');
  14.     $newpath preg_replace ("!/{$ccwd}!"''$cwd);
  15.     $iniset ('include_path'$newpath ':' $oldpath);
  16. }
  17.  
  18. require_once 'HTTPRelay.php';
  19.  
  20. try {
  21.     $http new HTTPRelay;
  22.  
  23.     $buf $http->fetch ('https://raw.github.com/twbs/bootstrap/master/bower.json'3);
  24.  
  25.     if $buf === false {
  26.         echo 'ERROR:  ' $http->error "\n";
  27.         exit;
  28.     }
  29.  
  30.     $buf json_decode ($buf);
  31.  
  32.     print_r ($buf);
  33.     print_r ($http->info);
  34. catch myException $e {
  35.     echo $e->Message ("\n";
  36.     print_r ($e->TraceAsArray ()) "\n";
  37.     $e->finalize ();
  38. }
  39.  
  40. /*
  41.  * Local variables:
  42.  * tab-width: 4
  43.  * c-basic-offset: 4
  44.  * End:
  45.  * vim: set filetype=php noet sw=4 ts=4 fdm=marker:
  46.  * vim600: noet sw=4 ts=4 fdm=marker
  47.  * vim<600: noet sw=4 ts=4
  48.  */
  49. ?>




[ Top ]


Class Variables

static $error =  ''

[line 50]

에러 발생시에 에러 메시지 저장



Tags:

access:  public

Type:   string


[ Top ]

$debug =  false

[line 78]

print debug messages to stderr

디버그 메시지를 stderr로 출력한다.




Tags:

access:  public

Type:   array


[ Top ]

$info =  null

[line 59]

HTTP 요청 정보 결과 저장

1.0.5 부터는 30x 반환시에 redirect를 내부 처리를 하며, 이 경우, $info는 2차 배열로 referer의 info 정보를 보관한다.




Tags:

access:  public

Type:   array


[ Top ]

$posttype =  'url-encode'

[line 70]

Post data encoding type

Post data를 어떤 방식으로 인코딩 할지를 결정한다. 'url-encode'와 'form-data' 둘 중의 하나로 지정을 해야 한다. Post data에 파일 전송을 하기 위해서는 무조건 'form-data'로 지정을 해야 한다.




Tags:

access:  public

Type:   string


[ Top ]



Class Methods


constructor __construct [line 122]

HTTPRelay __construct( [array $header = null])

HTTPRelay 초기화

예제:

  1.     $header array (
  2.         'X_REQ_HEADER' => 'addtional request header',
  3.         'X_REQ_HEADER2' => 'addtional request header 2'
  4.     );
  5.  
  6.     $http new HTTPRelay ($header);




Tags:

access:  public


Parameters:

array   $header   (optional) 사용자 정의 HTTP Header
  • Key는 Header 이름이어야 하며 '-'는 '_'로 표기한다.
  • Heder값이 없어야 할 경우에는 값을 '-'로 넣어준다.
  • Key값에 POSTTYPE을 지정할 경우, Post encoding 방식을 직접 지정이 가능하다. 이 경우 POSTTYPE은 HTTP Header 에 영향을 주지 않으며, 값으로는 'form-data'와 'url-encode' 중에 지정할 수 있다. POSTTYPE은 제거될 예정이니 $posttype property를 직접 설정하여야 한다.

[ Top ]

method fetch [line 253]

string fetch( string $to, [int $tmout = 60], [string $httphost = ''], [array $post = null], [boolean $recursion = false])

HTML 요청의 결과를 반환한다.

예제:

  1. <?php
  2. /*
  3.  * Test code for HTTPRelay
  4.  * $Id$
  5.  */
  6.  
  7. $iniget function_exists ('___ini_get''___ini_get' 'ini_get';
  8. $iniset function_exists ('___ini_set''___ini_set' 'ini_set';
  9.  
  10. $cwd getcwd ();
  11. $ccwd basename ($cwd);
  12. if $ccwd == 'tests' {
  13.     $oldpath $iniget ('include_path');
  14.     $newpath preg_replace ("!/{$ccwd}!"''$cwd);
  15.     $iniset ('include_path'$newpath ':' $oldpath);
  16. }
  17.  
  18. require_once 'HTTPRelay.php';
  19.  
  20. try {
  21.     $http new HTTPRelay;
  22.  
  23.     $buf $http->fetch ('https://raw.github.com/twbs/bootstrap/master/bower.json'3);
  24.  
  25.     if $buf === false {
  26.         echo 'ERROR:  ' $http->error "\n";
  27.         exit;
  28.     }
  29.  
  30.     $buf json_decode ($buf);
  31.  
  32.     print_r ($buf);
  33.     print_r ($http->info);
  34. catch myException $e {
  35.     echo $e->Message ("\n";
  36.     print_r ($e->TraceAsArray ()) "\n";
  37.     $e->finalize ();
  38. }
  39.  
  40. /*
  41.  * Local variables:
  42.  * tab-width: 4
  43.  * c-basic-offset: 4
  44.  * End:
  45.  * vim: set filetype=php noet sw=4 ts=4 fdm=marker:
  46.  * vim600: noet sw=4 ts=4 fdm=marker
  47.  * vim<600: noet sw=4 ts=4
  48.  */
  49. ?>




Tags:

access:  public


Parameters:

string   $to   요청할 URL
int   $tmout   (optional) timeout 값
string   $httphost   (optional) HTTP/1.1 Host Header. 지정을 하지 않을 경우 $to의 도메인으로 지정됨
array   $post   (optional) Post방식으로 요청시 전송할 Post data
boolean   $recursion   redirec 처리를 위한 재귀 호출 구분 변수 (1.0.5)

[ Top ]

method head [line 157]

stdClass head( string $to, [int $tmout = 60], [string $httphost = ''], [boolean $recursion = false])

HTTP/1.1 HEAD 요청

예제:

  1. <?php
  2. /*
  3.  * Test code for HTTPRelay
  4.  * $Id$
  5.  */
  6.  
  7. $iniget function_exists ('___ini_get''___ini_get' 'ini_get';
  8. $iniset function_exists ('___ini_set''___ini_set' 'ini_set';
  9.  
  10. $cwd getcwd ();
  11. $ccwd basename ($cwd);
  12. if $ccwd == 'tests' {
  13.     $oldpath $iniget ('include_path');
  14.     $newpath preg_replace ("!/{$ccwd}!"''$cwd);
  15.     $iniset ('include_path'$newpath ':' $oldpath);
  16. }
  17.  
  18. require_once 'HTTPRelay.php';
  19.  
  20. try {
  21.     $http new HTTPRelay;
  22.  
  23.     $buf $http->head ('https://raw.github.com/twbs/bootstrap/master/bower.json'3);
  24.  
  25.     if $buf === false {
  26.         echo 'ERROR:  ' $http->error "\n";
  27.         exit;
  28.     }
  29.  
  30.     print_r ($http->info);
  31.     print_r ($buf);
  32. catch myException $e {
  33.     echo $e->Message ("\n";
  34.     print_r ($e->TraceAsArray ()) "\n";
  35.     $e->finalize ();
  36. }
  37.  
  38. /*
  39.  * Local variables:
  40.  * tab-width: 4
  41.  * c-basic-offset: 4
  42.  * End:
  43.  * vim: set filetype=php noet sw=4 ts=4 fdm=marker:
  44.  * vim600: noet sw=4 ts=4 fdm=marker
  45.  * vim<600: noet sw=4 ts=4
  46.  */
  47. ?>




Tags:

since:  1.0.2
access:  public


Parameters:

string   $to   요청할 URL
int   $tmout   (optional) timeout 값
string   $httphost   (optional) HTTP/1.1 Host Header. 지정을 하지 않을 경우 $to의 도메인으로 지정됨
boolean   $recursion   redirec 처리를 위한 재귀 호출 구분 변수 (1.0.5)

[ Top ]

method relay [line 341]

string relay( string $to, [int $tmout = 60], [string $httphost = ''], [boolean $recursion = false])

HTML 요청을 다른 호스트로 중계를 한다.

예제:

  1. <?php
  2. /*
  3.  * Test code for HTTPRelay
  4.  * $Id$
  5.  */
  6.  
  7. $iniget function_exists ('___ini_get''___ini_get' 'ini_get';
  8. $iniset function_exists ('___ini_set''___ini_set' 'ini_set';
  9.  
  10. $cwd getcwd ();
  11. $ccwd basename ($cwd);
  12. if $ccwd == 'tests' {
  13.     $oldpath $iniget ('include_path');
  14.     $newpath preg_replace ("!/{$ccwd}!"''$cwd);
  15.     $iniset ('include_path'$newpath ':' $oldpath);
  16. }
  17.  
  18. require_once 'HTTPRelay.php';
  19.  
  20. try {
  21.     $http new HTTPRelay;
  22.  
  23.     $buf $http->fetch ('https://raw.github.com/twbs/bootstrap/master/bower.json'3);
  24.  
  25.     if $buf === false {
  26.         echo 'ERROR:  ' $http->error "\n";
  27.         exit;
  28.     }
  29.  
  30.     $buf json_decode ($buf);
  31.  
  32.     print_r ($buf);
  33.     print_r ($http->info);
  34. catch myException $e {
  35.     echo $e->Message ("\n";
  36.     print_r ($e->TraceAsArray ()) "\n";
  37.     $e->finalize ();
  38. }
  39.  
  40. /*
  41.  * Local variables:
  42.  * tab-width: 4
  43.  * c-basic-offset: 4
  44.  * End:
  45.  * vim: set filetype=php noet sw=4 ts=4 fdm=marker:
  46.  * vim600: noet sw=4 ts=4 fdm=marker
  47.  * vim<600: noet sw=4 ts=4
  48.  */
  49. ?>




Tags:

access:  public


Parameters:

string   $to   중계할 URL
int   $tmout   (optional) timeout 값
string   $httphost   (optional) HTTP/1.1 Host Header. 지정을 하지 않을 경우 $to의 도메인으로 지정됨
boolean   $recursion   redirec 처리를 위한 재귀 호출 구분 변수 (1.0.5)

[ Top ]


Class Constants

UAGENT =  'OOPS HTTP Relay Wrapper 1.0'

[line 42]

Default User Agent


[ Top ]



Documentation generated on Tue, 14 May 2019 02:00:07 +0900 by phpDocumentor 1.4.4