gSoap - parse custom http header from request

穿精又带淫゛_ 提交于 2021-02-11 13:33:01

问题


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.

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.

Any help is greatly appreciated.


回答1:


You will need a callback function to process HTTP headers, see callback functions and in particular the fparsehdr callback:

Callback that consumes an HTTP header that consists of a key-value pair.

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.

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;

The new callback function:

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.



来源:https://stackoverflow.com/questions/60191571/gsoap-parse-custom-http-header-from-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!