我在问这个古老的问题,当使用ruby gem时,如何通过你的代理。
我尝试设置环境变量HTTP_PROXY
HTTP_PROXY=myusername:password@proxy.com:8080但这是行不通的。
> gem install rails
ERROR: While executing gem ... (URI::InvalidURIError)
bad URI(is not URI?): http://myusername:password@proxy.com:8080我尝试在开始时添加tcp://,但它在错误消息中显示http://tcp://,所以我认为这也是错误的。
因此,我尝试使用以下代码通过php进行自动连接:
<?php
$path = 'http://rubygems.org/';
$auth = base64_encode('myusername:password');
file_put_contents('proxy.log', 'POST::', FILE_APPEND);
file_put_contents('proxy.log', print_r($_POST, true), FILE_APPEND);
file_put_contents('proxy.log', 'GET::', FILE_APPEND);
file_put_contents('proxy.log', print_r($_GET, true), FILE_APPEND);
$aContext = array(
'http' => array(
'method' => 'GET',
'content' => http_build_query($_GET),
'proxy' => 'tcp://proxy.com:8080',
'request_fulluri' => true,
'header' => "Proxy-Authorization: Basic $auth"
)
);
$cxContext = stream_context_create($aContext);
$sFile = file_get_contents($path, false, $cxContext);
header('Content-type: application/gzip');
echo $sFile;如果它试图获取一个特定的文件,我使用apache处理它。
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*[^/])$ http://%{HTTP_HOST}%{REQUEST_URI}/ [R=301,L]
RewriteCond $1 !^$
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php?$1 [QSA,L]
</IfModule>
# Options -Indexes但是我还是得到了这个错误。
> gem sources -ahttp://mylocalhost/ror-proxy/
ERROR: While executing gem ... (Zlib::GzipFile::Error)
not in gzip format有什么想法吗?
发布于 2011-01-04 10:24:01
修复了PHP代理。
添加新的源码时,gem会发出
specs_4_8_gz
请注意,_表示.(点)。你所要做的就是替换它。请注意,此操作仅执行一次。其他gem将作为其正确的文件名发送出去。
应该是这样的。
if (empty($_GET['_p'])) {
header('Content-type: text/html');
} else {
header('Content-type: application/gzip');
$item = $_GET['_p'];
$item = '.gz' == substr($item, -3) ? $item: str_replace('_', '.', $item);
header('Content-Disposition: filename="' . $item . '"');
$path .= $item;
}我的完整脚本将发布在github上。
发布于 2011-01-04 02:27:39
代理服务器,特别是身份验证代理服务器,可能会在各种自动更新服务中造成麻烦。不幸的是,gem不能正确处理HTTP_PROXY环境变量。简而言之,它不知道如何处理来自服务器的BasicAuthentication响应--尽管它试图这样做。
长话短说,您必须设置一个本地代理服务器,它负责在代理中导航。它不能执行任何转换(如解压缩压缩流)。
myusername:password@company.com:8080构造不是有效的URL。我知道这是windows验证代理服务器的快捷方式,但只有@符号后面的部分才是有效的URL。
请查看以下常见问题:http://docs.rubygems.org/read/chapter/15
这个问题很常见。
https://stackoverflow.com/questions/4583635
复制相似问题