Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http请求去除connection header #1495

Closed
18328594608 opened this issue Feb 27, 2024 · 8 comments
Closed

http请求去除connection header #1495

18328594608 opened this issue Feb 27, 2024 · 8 comments

Comments

@18328594608
Copy link

想要在发送http的时候禁用connection这个header pair 目前没有看到相应的接口 都是默认在发送请求时加上了这个header pair ,能新增一个接口去掉这个header pair么

@Barenboim
Copy link
Contributor

你好。我们目前已经支持对header的删除了,具体代码修改可以看这个PR:#1492
不过,你的需求是删除connection这个header。这个header是框架在发送消息之前再加的。所以,你要删除的话需要给task设置一个prepare函数,设置prepare的接口在WFClientTask上。具体的方法如下:

void f()
{
    WFHttpTask *task = WFTaskFactory::create_http_task(...);
    auto *client_task = static_cast<WFClientTask<protocol::HttpRequest, protocol::HttpResponse> *>task;
    client_task->set_prepare([](WFHttpTask *t) {
        protocol::HttpHeaderCursor cursor(t->get_req());
        cursor.find_and_erase("Connection");
    });
    task->start();
}

HttpHeaderCursor的find_and_erase()操作,删除这个名字下的第一个header,如果可能存在多个同名的header,则需要写成循环。例如:

void f()
{
    while (cursor.find_and_erase("Cookie"))
        ;
}

@Barenboim Barenboim changed the title http请求需求 http请求去除connection header Feb 28, 2024
@Barenboim
Copy link
Contributor

@18328594608 你好,请问是否解决了问题?

@18328594608
Copy link
Author

感谢支持!
最近在改业务上面的东西 这个还没更新过代码去试,我周一去试过之后给您回复.

@18328594608
Copy link
Author

后续我在业务上验证过了。使用task新增prepare的方式能够解决我的问题. 感谢支持.

@Barenboim
Copy link
Contributor

请问一下,你那边为什么有这个删除connection header对需求呢?删除之后,对连接是否保持的协商可能不准确。

@18328594608
Copy link
Author

这边是因为对向服务器对于这个字段的支持有bug, 在这个字段存在的时候,多次发送请求,他那边服务会拒绝请求.暂时那边改不了就只能先把这个字段删除掉. 连接是否保持这个不考虑,只要能满足正常的回包response功能就行.

@Barenboim
Copy link
Contributor

Barenboim commented Mar 11, 2024

是因为对向服务器对于这个字段的支持有bug, 在这个字段存在的时候,多次发送请求,他那边服务会拒绝请求.暂时那边改不了就只能先把这个字段删除掉. 连接是否保持这个不考虑,只要能满足正常的回包response功能就行.

好的。之后可以把服务器也改用workflow实现😂

@18328594608
Copy link
Author

是因为对向服务器对于这个字段的支持有bug, 在这个字段存在的时候,多次发送请求,他那边服务会拒绝请求.暂时那边改不了就只能先把这个字段删除掉. 连接是否保持这个不考虑,只要能满足正常的回包response功能就行.

好的。之后可以把服务器也改用workflow实现😂

那是一个windows 下的中间件服务 比较古老了 等后面淘汰哈哈😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants