[OpenSIPS-Devel] [opensips] addition of rest_append_hf command (#497)

Jarrod Baumann notifications at github.com
Tue May 5 07:59:39 CEST 2015


jarrodb wants to merge 1 commit into OpenSIPS:master from jarrodb:rest_append_hf:

This is an initial commit to address feature request #496.

I have tested this module with the following script excerpt:

### request route
```
  $json(test) := "{}";
  $json(test/id) = "1";
  route(TEST_POST);
  route(TEST_GET);
  route(TEST_ASYNC_POST);
```

### route definitions
```
route[TEST_GET] {
  rest_append_hf("Authorization: Bearer mF_9.B5f-4.1JqM");
  if (!rest_get("http://127.0.0.1:3000/",
                 "$var(reply)",
                 "$var(ct)",
                 "$var(rcode)"))
  {
    xlog("Error code $var(rcode) in HTTP GET!\n");
    send_reply("403", "GET Forbidden");
    exit;
  }
  xlog("Successful get - $var(ct) - $var(rcode)\n$var(reply)\n");
}

route[TEST_POST] {
  rest_append_hf("Authorization: Bearer mF_9.B5f-4.1JqM");
  if (!rest_post("http://127.0.0.1:3000/",
                 "$json(test)",
                 "application/json",
                 "$var(post_reply)",
                 "$var(post_ct)",
                 "$var(post_rcode)"))
  {
    xlog("Error code $var(post_rcode) in HTTP POST!\n");
    send_reply("403", "POST Forbidden");
    exit;
  }
  xlog("Successful post - $var(post_ct) - $var(rcode)\n$var(post_reply)\n");
}

route[TEST_ASYNC_POST] {
  rest_append_hf("Authorization: Bearer mF_9.B5f-4.1JqM");
  async(rest_post("http://127.0.0.1:3000/",
                  "$json(test)",
                  "application/json",
                  "$json(async_test_reply)",
                  "$var(async_ct)",
                  "$var(async_rcode)"),
        TEST_ASYNC_POST_REPLY);
}

route[TEST_ASYNC_POST_REPLY] {
  xlog("In TEST_ASYNC_POST_REPLY, reply received: $json(async_test_reply)\n");
}
```

### example log output
```
May  5 05:45:43 localhost opensips[919]: Successful post - application/json - <null>#012{"id": 1, "result": true}
May  5 05:45:43 localhost opensips[919]: Successful get - text/html - 200#012
May  5 05:45:43 localhost opensips[919]: In TEST_ASYNC_POST_REPLY, reply received: {"id": 1, "result": true}
```
You can view, comment on, or merge this pull request online at:

  https://github.com/OpenSIPS/opensips/pull/497

-- Commit Summary --

  * moved curl_slist to global process variable to support addition of rest_append_hf command

-- File Changes --

    M modules/rest_client/rest_cb.h (1)
    M modules/rest_client/rest_client.c (15)
    M modules/rest_client/rest_methods.c (56)
    M modules/rest_client/rest_methods.h (2)

-- Patch Links --

https://github.com/OpenSIPS/opensips/pull/497.patch
https://github.com/OpenSIPS/opensips/pull/497.diff

---
Reply to this email directly or view it on GitHub:
https://github.com/OpenSIPS/opensips/pull/497
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/devel/attachments/20150504/e4777586/attachment.htm>


More information about the Devel mailing list