Browser Cross Domain Problems
This time: two ways of executing asynchronous Javascript Browser calls to deal with Browser's security policy.
AJAX Cross Domain calls are usually forbidden, but in somtimes it is needed. Think of including third party libraries.
Apache's mod_rewrite module
If you use OpenSUSE you need the modules: mod_proxy,mod_headers, mod_proxy_http, php5. See /etc/sysconfig/apache2 at APACHE_MODULES= .
In the vhost.d configuration file it would look like:
ServerName 127.0.0.1
RewriteEngine On
RewriteLoglevel 99
RewriteLog /tmp/apache_rewrite.log
RewriteRule ^/RewriteThisStringToTarget$ https://TargetDomain.com/ [P,QSA,L]
/Virtualhost>
Whereby P stands for Proxy mode, all queries will be redirected to the target (ProxyPass).
QSA query string append, that means all parameter will be redirected
L last, no more rewrite rules will be executed
rewrite the AJAX calls in PHP
Well, not every web host runs Apache, so an alternative solution is:
Write an HTTP relay. What to do? Read the response HTTP header and re-set/forward the actions.
Hereby essential is:
Cookies
if (preg_match("/Set-Cookie: ([A-Za-z]+)=([a-zA-Z0-9]+); expires=(.+);/", $line, $match))
setcookie($match[1],$match[2]); //,$match[3],'/');
Content length (for not waiting for timeout)
if (preg_match("/^Content-Length:\\s+([0-9]+)/", $line, $match))
$content_length = $match[1];
Transfer ecoding
if (strpos($response, "\r\n\r\n") > 0 && 0 == preg_match("/Transfer-Encoding: chunked/i",$response))
$content_length -= strlen($line);
Chunked transfer
/* saerch for the hint of chunked transfer length, e.g. "^f512$"; strip them out */
if (preg_match("/\r\n[a-z0-9]+/m",$response))
$response = preg_replace("/\r\n[a-z0-9]+/m","",$response,1);
/* search for chunked transfer termination, chunked transfer sends an explicit 0 */
if ($line=="0\r\n")
$response = preg_replace("/\r\n0/m","",$response,1);
I hope this few hints give a good overwiew about what to do, when dealing with HTTP relay.
Keine Kommentare:
Kommentar veröffentlichen