This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
60 lines (54 loc) · 2.23 KB
/
Copy pathindex.php
File metadata and controls
60 lines (54 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
$host = '127.0.0.1';
$db = 'test';
$query = $_REQUEST['REQUEST_URI'];
// end of config
$url = 'http://'.$host.'/'.$db.'/'.$query;
$uri = '/'.$db.'/'.$query;
$dsn = parse_url( $url );
try{
header('Content-Type: application/json');
$fp = fsockopen($dsn['host'], isset( $dsn['port'] ) ? $dsn['port'] : 5984, $errno, $errstr, 30);
if (!$fp) {
echo json_encode( array('error'=> $errstr, 'code' => $errno));
} else {
$out = $_SERVER['REQUEST_METHOD']." $uri HTTP/1.0\r\n";
$out .= "Host: ".$dsn['host']."\r\n";
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
$out .= "Connection: Close\r\n";
$out .= "\r\n";
fwrite($fp, $out);
} else {
$request_body = file_get_contents('php://input');
$out .= "Content-Length: ".strlen($request_body)."\r\n";
$out .= "Accept: application/json\r\n";
$out .= "Content-Type: application/json\r\n";
$out .= "Connection: Close\r\n";
$out .= "\r\n";
fwrite($fp, $out);
fwrite($fp, $request_body);
}
$headers = true;
$remain = 0;
while (!feof($fp)) {
if($headers == true){
$line = fgets($fp);
if($line == "\r\n"){
$headers = false;
}else{
if(strpos($line, "HTTP/") === false){
$exp = explode(":",$line);
$n = strtolower(trim($exp[0]));
$ignore = explode(",","connection,content-encoding,transfer-encoding,access-control");
if(!in_array($n, $ignore)){
header(trim($line));
}
}
}
} else {
$buf = fread($fp, 30);
echo $buf;
}
}
fclose($fp);
}