我是新的stackoverflow,所以,如果我犯了一个错误,对不起.
我必须编写一个python脚本,它使用Elasticsearch收集一些数据,然后将数据写入数据库.我正在努力用elasticsearch收集数据,因为我工作的公司背后是代理.
该脚本无需代理即可运行..但我不知道如何将代理设置传递给Elasticsearch.
以下代码无需代理即可运行:
es = Elasticsearch(['https://user:password@logs.net/elasticsearch'])
res = es.search(index=index, body=request, search_type="count")
Run Code Online (Sandbox Code Playgroud)
当我在代理后面时,我尝试了以下内容:
es = Elasticsearch(['https://user:password@logs.net/elasticsearch'], _proxy = 'http://proxy.org', _proxy_headers = {'basic_auth': 'user:pw'})
res = es.search(index=index, body=request, search_type="count")
return res
Run Code Online (Sandbox Code Playgroud)
有没有人知道我必须传递Elasticsearch的关键字,所以它使用代理?
你能帮忙的话,我会很高兴.
谢谢.
如何创建深度/递归代理?
具体来说,我想知道在对象树中的任何位置设置或修改属性.
这是我到目前为止所得到的:
function deepProxy(obj) {
return new Proxy(obj, {
set(target, property, value, receiver) {
console.log('set', property,'=', value);
if(typeof value === 'object') {
for(let k of Object.keys(value)) {
if(typeof value[k] === 'object') {
value[k] = deepProxy(value[k]);
}
}
value = deepProxy(value);
}
target[property] = value;
return true;
},
deleteProperty(target, property) {
if(Reflect.has(target, property)) {
let deleted = Reflect.deleteProperty(target, property);
if(deleted) {
console.log('delete', property);
}
return deleted;
}
return false;
}
});
}
Run Code Online (Sandbox Code Playgroud)
这是我的测试:
const proxy = deepProxy({});
const …Run Code Online (Sandbox Code Playgroud) 我正在尝试从API网关端点代理配置为网站的S3存储桶.我使用控制台成功配置了端点,但我无法使用Cloudformation重新创建配置.
经过大量的试验和错误猜测后,我想出了以下CF堆栈模板,让我非常接近:
Resources:
Api:
Type: 'AWS::ApiGateway::RestApi'
Properties:
Name: ApiDocs
Resource:
Type: 'AWS::ApiGateway::Resource'
Properties:
ParentId: !GetAtt Api.RootResourceId
RestApiId: !Ref Api
PathPart: '{proxy+}'
RootMethod:
Type: 'AWS::ApiGateway::Method'
Properties:
HttpMethod: ANY
ResourceId: !GetAtt Api.RootResourceId
RestApiId: !Ref Api
AuthorizationType: NONE
Integration:
IntegrationHttpMethod: ANY
Type: HTTP_PROXY
Uri: 'http://my-bucket.s3-website-${AWS::Region}.amazonaws.com/'
PassthroughBehavior: WHEN_NO_MATCH
IntegrationResponses:
- StatusCode: 200
ProxyMethod:
Type: 'AWS::ApiGateway::Method'
Properties:
HttpMethod: ANY
ResourceId: !Ref Resource
RestApiId: !Ref Api
AuthorizationType: NONE
RequestParameters:
method.request.path.proxy: true
Integration:
CacheKeyParameters:
- 'method.request.path.proxy'
RequestParameters:
integration.request.path.proxy: 'method.request.path.proxy'
IntegrationHttpMethod: ANY
Type: HTTP_PROXY
Uri: 'http://my-bucket.s3-website-${AWS::Region}.amazonaws.com/{proxy}'
PassthroughBehavior: WHEN_NO_MATCH …Run Code Online (Sandbox Code Playgroud) 我有一个mod_rewrite规则,将任何子域请求发送到PHP脚本,该脚本应该将这些请求代理到另一个主机(内部代理,而不是302).
我很接近,因为我的脚本适用于Web浏览器,但curl似乎不喜欢它:
curl: (56) Received problem 2 in the chunky parser
Run Code Online (Sandbox Code Playgroud)
这是我的mod_rewrite:
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$
RewriteRule ^.*$ %{DOCUMENT_ROOT}/proxy.php?__path=%1 [QSA,L]
Run Code Online (Sandbox Code Playgroud)
和我的 proxy.php
<?php
$name = $_GET['__path'];
unset($_GET['__path']);
$path = $_SERVER['REQUEST_URI'];
$url = "http://$name.internal.example.com$path";
$ch = curl_init($url);
$headers = array();
foreach (apache_request_headers() as $key => $value) {
$headers[] = "$key: $value";
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $_SERVER['REQUEST_METHOD']);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($_POST));
curl_setopt($ch, CURLOPT_HEADER, TRUE);
$data = curl_exec($ch);
list($headers, $body) = explode("\r\n\r\n", $data, 2);
$headers = explode("\r\n", $headers); …Run Code Online (Sandbox Code Playgroud) 我试图以编程方式更新IE中的代理异常(工具 - > Internet选项,连接 - > Lan设置,高级和例外),但我无法找到API和/或注册表项.有人有想法吗?
谢谢!
当我设计一个通用类时,我经常处于以下设计选择之间的两难境地:
template<class T>
class ClassWithSetter {
public:
T x() const; // getter/accessor for x
void set_x(const T& x);
...
};
// vs
template<class T>
class ClassWithProxy {
struct Proxy {
Proxy(ClassWithProxy& c /*, (more args) */);
Proxy& operator=(const T& x); // allow conversion from T
operator T() const; // allow conversion to T
// we disallow taking the address of the reference/proxy (see reasons below)
T* operator&() = delete;
T* operator&() const = delete;
// more operators to delegate to …Run Code Online (Sandbox Code Playgroud) 我的部分应用程序需要充当第三方RESTful Web服务的代理服务器.有没有办法设置Web API路由,以便所有相同类型的请求将使用相同的方法?
例如,如果客户端发送这些GET请求中的任何一个,我希望它们进入单个GET操作方法,然后将该请求发送到下游服务器.
api/Proxy/Customers/10045
api/Proxy/Customers/10045/orders
api/Proxy/Customers?lastname=smith
Run Code Online (Sandbox Code Playgroud)
GET的单一操作方法将获取这三个请求中的任何一个并将它们发送到相应的服务(我知道如何使用HttpClient来有效地实现这一点):
http://otherwebservice.com/Customers/10045
http://otherwebservice.com/Customers/10045/orders
http://otherwebservice.com/Customers?lastname=smith
Run Code Online (Sandbox Code Playgroud)
我不想将我的Web服务紧密地耦合到第三方Web服务,并将其整个API作为我内部的方法调用进行复制.
我想到的一个解决方法是简单地在客户端上用JavaScript编码目标URL,并将其传递给Web API,然后只能看到一个参数.它会工作,但我更愿意在可能的情况下使用Web API中的路由功能.
我正在尝试设置一个终止SSL连接的Apache Forward Proxy.我试图这样做的原因是在返回的代码上运行Apache过滤器(特别是mod_pagespeed).在我处理mod_pagespeed之前,我正在通过尝试在响应中插入一个标头来测试这个POC(这将证明我可以编辑响应),但我遇到了SSL代理问题(非SSL代理工作正常) .
请注意,我并不担心任何证书错误等 - 这纯粹是为了内部测试.
我已经设置了服务器并在非SSL页面上看到了X-MSCProxy Header:
jshannon-macbookpro:pagespeed_proxy jshannon$ curl -vv --proxy pagespeed_proxy:3ja82ad9@localhost:8080 -D - -o /dev/null http://www.slate.com
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
* Proxy auth using Basic with user 'pagespeed_proxy'
> GET http://www.slate.com/ HTTP/1.1
> Host: www.slate.com
...
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Date: Mon, 30 Oct 2017 18:10:40 GMT
Date: Mon, 30 Oct 2017 18:10:40 GMT
< Server: Apache/2.2.29 (Amazon)
Server: Apache/2.2.29 (Amazon)
... …Run Code Online (Sandbox Code Playgroud) 注意:我的主要目的是解决服务的CORS问题
最近我发现spring 文档页面说:
Spring AOP 使用 JDK 动态代理或 CGLIB 来为给定的目标对象创建代理。(只要有选择,JDK 动态代理都是首选)。
如果要代理的目标对象至少实现一个接口,则将使用 JDK 动态代理。
但我的申请中似乎并非如此。我想编写一个小型基准测试来比较两种代理类型的性能。
有两个类似的类。两者都有一种带有注释的方法@Transactional。一个类实现了该接口,而另一个类则没有:
@Service
public class Cglib {
@Transactional
public void method() {}
}
Run Code Online (Sandbox Code Playgroud)
public interface Dynamic {
void method();
}
Run Code Online (Sandbox Code Playgroud)
@Service
public class DynamicImpl implements Dynamic {
@Override
@Transactional
public void method() {}
}
Run Code Online (Sandbox Code Playgroud)
根据第一个类的文档,应该创建一个 CGLIB 代理,对于第二个类,应该创建一个 JDK 动态代理。
但就我而言,CGLIB 用于这两个类:
@Component
@RequiredArgsConstructor
public class Runner implements ApplicationRunner {
private final Cglib cglib;
private final Dynamic dynamic;
@Override
public void run(ApplicationArguments args) { …Run Code Online (Sandbox Code Playgroud) proxy ×10
amazon-s3 ×1
apache ×1
c++ ×1
curl ×1
ecmascript-6 ×1
java ×1
javascript ×1
node.js ×1
php ×1
powershell ×1
python ×1
spring ×1
spring-boot ×1
ssl ×1