Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions lib/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abstract class Request
{
private static $validOutputFormats = array("json", "xml");
private static $requestAcceptType = "";

private static $requestAcceptEncoding = "";
/**
* Sends GET request and returns output in specified format.
*
Expand Down Expand Up @@ -52,7 +52,10 @@ public static function request($request, $output_format = "xml", $decode_json =
"Accept: ".$accept,
"Authorization: Bearer ".$token
);

/// enable GZIP compression for post MLSGRID Api
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps remove GRID from the comment? I think it's sufficient to say that it's for GZIP compression.

if(self::$requestAcceptEncoding) {
$headers[] = "Accept-Encoding:".self::$requestAcceptEncoding;
}
// Send request
$response = $curl->request("get", $url, $headers, null, false);
if(!$response || !is_array($response) || $response[1] != 200) {
Expand Down Expand Up @@ -112,6 +115,9 @@ public static function requestPost($request, $params = array())
"Accept: ".$accept,
"Authorization: Bearer ".$token
);
if(self::$requestAcceptEncoding) {
$headers[] = "Accept-Encoding:".$requestAcceptEncoding;
}

// Send request
$response = $curl->request("post", $url, $headers, $params, false);
Expand Down Expand Up @@ -192,7 +198,7 @@ public static function setAcceptType($type = "") {
self::$requestAcceptType = $type;
}
}

/**
* Formats request parameters to compatible string
*
Expand All @@ -215,4 +221,14 @@ public static function formatRequestParameters($parameters_string) {

return implode("&", $params);
}

/**
* Sets accep encoding
*
* @param string
*/
public static function setAcceptEncoding($encoding = "") {
self::$requestAcceptEncoding = $encoding;
}

}