Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2893213
HTTPFutureHTTPResponseStatus.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
1 KB
Referenced Files
None
Subscribers
None
HTTPFutureHTTPResponseStatus.php
View Options
<?php
final
class
HTTPFutureHTTPResponseStatus
extends
HTTPFutureResponseStatus
{
private
$excerpt
;
private
$expect
;
public
function
__construct
(
$status_code
,
$body
,
array
$headers
,
$expect
=
null
)
{
// NOTE: Avoiding PhutilUTF8StringTruncator here because this isn't lazy
// and responses may be large.
if
(
strlen
(
$body
)
>
512
)
{
$excerpt
=
substr
(
$body
,
0
,
512
)
.
'...'
;
}
else
{
$excerpt
=
$body
;
}
$content_type
=
BaseHTTPFuture
::
getHeader
(
$headers
,
'Content-Type'
)
;
$match
=
null
;
if
(
phutil_nonempty_string
(
$content_type
)
&&
preg_match
(
'/;\s*charset=([^;]+)/'
,
$content_type
,
$match
)
)
{
$encoding
=
trim
(
$match
[
1
]
,
"\"'"
)
;
try
{
$excerpt
=
phutil_utf8_convert
(
$excerpt
,
'UTF-8'
,
$encoding
)
;
}
catch
(
Exception
$ex
)
{
}
}
$this
->
excerpt
=
phutil_utf8ize
(
$excerpt
)
;
$this
->
expect
=
$expect
;
parent
::
__construct
(
$status_code
)
;
}
protected
function
getErrorCodeType
(
$code
)
{
return
'HTTP'
;
}
public
function
isError
(
)
{
if
(
$this
->
expect
===
null
)
{
return
(
$this
->
getStatusCode
(
)
<
200
)
||
(
$this
->
getStatusCode
(
)
>
299
)
;
}
return
!
in_array
(
$this
->
getStatusCode
(
)
,
$this
->
expect
,
true
)
;
}
public
function
isRedirect
(
)
{
$code
=
$this
->
getStatusCode
(
)
;
return
(
$code
>=
300
&&
$code
<
400
)
;
}
public
function
isTimeout
(
)
{
return
false
;
}
protected
function
getErrorCodeDescription
(
$code
)
{
static
$map
=
array
(
404
=>
'Not Found'
,
500
=>
'Internal Server Error'
,
)
;
return
idx
(
$map
,
$code
)
.
"\n"
.
$this
->
excerpt
.
"\n"
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Jan 19, 18:04 (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1121261
Default Alt Text
HTTPFutureHTTPResponseStatus.php (1 KB)
Attached To
Mode
rARC Arcanist
Attached
Detach File
Event Timeline
Log In to Comment