Skip to content

Commit

Permalink
http_async_client: workaround for dealing with HTTP Via format in rep…
Browse files Browse the repository at this point in the history
…lies
  • Loading branch information
grumvalski committed May 17, 2016
1 parent 149976a commit 2449f85
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions modules/http_async_client/async_http.c
Expand Up @@ -94,13 +94,34 @@ int async_http_init_sockets(async_http_worker_t *worker)
return 0;
}

static inline char *strfindcasestrz(str *haystack, char *needlez)
{
int i,j;
str needle;

needle.s = needlez;
needle.len = strlen(needlez);
for(i=0;i<haystack->len-needle.len;i++) {
for(j=0;j<needle.len;j++) {
if ( !((haystack->s[i+j]==needle.s[j]) ||
( isalpha((int)haystack->s[i+j])
&& ((haystack->s[i+j])^(needle.s[j]))==0x20 )) )
break;
}
if (j==needle.len)
return haystack->s+i;
}
return 0;
}

void async_http_cb(struct http_m_reply *reply, void *param)
{
async_query_t *aq;
cfg_action_t *act;
unsigned int tindex;
unsigned int tlabel;
struct cell *t = NULL;
char *p;
sip_msg_t *fmsg;

if (reply->result != NULL) {
Expand All @@ -119,6 +140,18 @@ void async_http_cb(struct http_m_reply *reply, void *param)
ah_error.len = strlen(ah_error.s);
} else {
/* success */

/* check for HTTP Via header
* - HTTP Via format is different that SIP Via
* - workaround: replace with Hia to be ignored by SIP parser
*/
if((p=strfindcasestrz(reply->result, "\nVia:"))!=NULL)
{
p++;
*p = 'H';
LM_DBG("replaced HTTP Via with Hia [[\n%.*s]]\n", reply->result->len, reply->result->s);
}

ah_reply->buf = reply->result->s;
ah_reply->len = reply->result->len;

Expand Down

0 comments on commit 2449f85

Please sign in to comment.