gSoap-解析请求中的自定义http标头
我正在尝试查找有关如何解析gSoap服务器应用程序在请求中收到的自定义http标头的信息.我已经花了几个小时试图找到与此有关的任何文档,但是到目前为止,我还没有成功.
I'm trying to find some information on how to parse out custom http headers received in a request by a gSoap server application. I've spent several hours trying to find any documentation on this but so far I haven't been successful.
我看到很多关于如何为客户端和服务器(例如通过http_extra_header属性)设置设置自定义http标头的文档,但是没有关于如何从已接收的请求中读取它们的文档..gSoap似乎支持解析现有的标准标头(例如:X-Forwarded-For),但到目前为止,我仍无法弄清如何访问尚未定义的标头.我通常擅长搜索此类内容,但我会不断查看gSoap标头文件, soap 标头或设置 http的文档标头.到目前为止,没有什么方法可以接收和解析尚未定义好的自定义标头.
I see plenty of documentation on how to set custom http headers for both the client and server (such as via the http_extra_header property), but not on how to read them from a request that was received. It seems like gSoap supports parsing out existing standardized headers (eg: X-Forwarded-For) but so far I can't figure out how to access headers that aren't already defined. I'm usually good at searching for stuff like this, but I keep hitting on documentation for gSoap header files, soap headers, or setting http headers. Nothing so far on receiving and parsing out custom headers that aren't already well-defined.
非常感谢您的帮助.
您将需要一个回调函数来处理HTTP标头,请参见 fparsehdr回调:
You will need a callback function to process HTTP headers, see callback functions and in particular the fparsehdr callback:
使用包含键值的HTTP标头的回调对.
Callback that consumes an HTTP header that consists of a key-value pair.
此回调由soap :: fparse调用,它消耗一个HTTP标头,该标头被拆分为键值对并更新soap上下文状态
This callback is called by soap::fparse, consumes an HTTP header that is split in a key-value pair and updates the soap context state accordingly.
分配此回调并使用传递给它的HTTP标头键和值对.确保在新的回调中调用原始的 soap-> fparsehdr(soap,key,val)
,以使引擎通过将所有标头传递到原始回调中来处理所有标头:
Assign this callback and use the HTTP header key and value pair passed to it. Make sure to call the original soap->fparsehdr(soap, key, val)
in the new callback, to let the engine process all headers by passing them through to the original callback:
soap->user = (void*)soap->fparsehdr; // to call fparsehdr() in our callback
soap->fparsehdr = my_parsehdr;
新的回调函数:
typedef int(*PARSEFUNC)(struct soap*, const char*, const char*);
int my_parsehdr(struct soap *soap, const char *key, const char *val)
{
... // check key (non-NULL) and use val (non-NULL)
return ((PARSEFUNC)(soap->user))(soap, key, val);
}
我建议将所有标头传递给引擎,除非它是对引擎没有意义的自定义标头.
I recommend to pass all headers through to the engine, unless it is a custom header that has no meaning to the engine.