}
else if (isset($header['HTTP-Response'])) {
$s = sprintf("HTTP/1.1 %s\r\n", $header['HTTP-Response']);
+ foreach($header as $key => $value) {
+ if (strtolower($key) == "http-response")
+ continue;
+ $s .= sprintf("%s: %s\r\n", $key, $value);
+ }
+ if ($len >= 0) {
+ $s .= sprintf("Content-Length: %ld\r\n", $len);
+ }
}
else {
$s = "HTTP/1.1 200 OK\r\n";
* MAIN
*/
-function chunked_content($zls, $content)
-{
- if ($zls) {
- $cont_comp = $zls->compress_chunk($content);
- }
- else {
- $cont_comp = $content;
- }
- $cont_comp_l = mb_strlen($cont_comp, "ASCII");
- // printf("CHUNK: [%s]\n", $content);
-
- return (sprintf("%X\r\n", $cont_comp_l).$cont_comp."\r\n");
-}
-
-function chunked_fini()
-{
- return sprintf("0\r\n");
-}
-
function get_encoding($header)
{
$enc = "plain";
if (isset($this->s2u[$id])) {
// $user_a[$s2u[$id]]->disable();
if ($this->s2u[$id]->rd_socket_get() != NULL) {
+ // try to send close frame (for websocket)
+ $clo = $this->s2u[$id]->stream_close();
+ $clo_l = mb_strlen($clo, "ASCII");
+ @fwrite($sock, $clo, $clo_l);
$this->s2u[$id]->rd_socket_set(NULL);
}
unset($this->s2u[$id]);
$content = $user->stream_keepalive(FALSE);
}
if ($content != "") {
- $response = chunked_content($user->rd_zls_get(), $content);
+ $response = $user->chunked_content($content);
}
}
// echo "SPIA: [".substr($response, 0, 60)."...]\n";
// echo "SPIA: [".$response."]\n";
$response_l = mb_strlen($response, "ASCII");
- $wret = @fwrite($sock, $response);
+ $wret = @fwrite($sock, $response, $response_l);
if ($wret < $response_l) {
printf("TROUBLE WITH FWRITE: %d\n", $wret);
$user->rd_cache_set(mb_substr($response, $wret, $response_l - $wret, "ASCII"));
}
unset($this->socks[$id]);
unset($this->s2u[$id]);
+ $clo = $user->stream_close();
+ $clo_l = mb_strlen($clo, "ASCII");
+ @fwrite($sock, $clo, $clo_l);
fclose($sock);
printf("CLOSE ON LOOP\n");
}