-
Notifications
You must be signed in to change notification settings - Fork 52
Added lua-resty-http as sender #34
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
base: master
Are you sure you want to change the base?
Changes from 5 commits
bd88eed
f19b540
72aafcc
36ef53b
2c7df89
d068e38
7a5146b
2c7f8a6
94c0225
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| -- vim: st=4 sts=4 sw=4 et: | ||
| --- Network backend using [lua-resty-http](https://github.com/ledgetech/lua-resty-http). | ||
| --- Supports https, http, and keepalive for better performance. | ||
| -- | ||
| -- @module raven.senders.lua-resty-http | ||
| -- @copyright 2014-2017 CloudFlare, Inc. | ||
| -- @license BSD 3-clause (see LICENSE file) | ||
|
|
||
| local util = require 'raven.util' | ||
| local http = require 'resty.http' | ||
| local cjson = require 'cjson' | ||
|
|
||
| local tostring = tostring | ||
| local setmetatable = setmetatable | ||
| local table_concat = table.concat | ||
| local parse_dsn = util.parse_dsn | ||
| local generate_auth_header = util.generate_auth_header | ||
| local _VERSION = util._VERSION | ||
| local _M = {} | ||
|
|
||
| local mt = {} | ||
| mt.__index = mt | ||
|
|
||
| function mt:send(json_str) | ||
| local httpc = http.new() | ||
| local res, err = httpc:request_uri(self.server, { | ||
|
||
| method = "POST", | ||
| headers = { | ||
| ['Content-Type'] = 'applicaion/json', | ||
| ['User-Agent'] = "raven-lua-http/" .. _VERSION, | ||
| ['X-Sentry-Auth'] = generate_auth_header(self), | ||
| ["Content-Length"] = tostring(#json_str), | ||
| }, | ||
| body = cjson.encode(json_str), | ||
| keepalive = self.opts.keepalive, | ||
| keepalive_timeout = self.opts.keepalive_timeout, | ||
| keepalive_pool = self.opts.keepalive_pool | ||
| }) | ||
|
|
||
| if not res then | ||
| return nil, table_concat(err) | ||
|
||
| end | ||
|
|
||
| return true | ||
|
||
| end | ||
|
|
||
| --- Configuration table for the lua-resty-http. | ||
| -- @field dsn DSN string | ||
| -- @field verify_ssl Whether or not the SSL certificate is checked (boolean, | ||
| -- defaults to false) | ||
| -- @field keepalive Whether or not to keep connection alive (boolean, | ||
| -- defaults to false) | ||
| -- @field keepalive_timeout The maximum number of connections in the keepalive pool(int, | ||
| -- defaults to 0) | ||
| -- @field keepalive_pool Whether or not to keep connection alive (int, | ||
| -- defaults to 0) | ||
| -- @table sender_conf | ||
|
|
||
| --- Create a new sender object for the given DSN | ||
| -- @param conf Configuration table, see @{sender_conf} | ||
| -- @return A sender object | ||
| function _M.new(conf) | ||
| local obj, err = parse_dsn(conf.dsn) | ||
| if not obj then | ||
| return nil, err | ||
| end | ||
|
|
||
| obj.opts = { | ||
| verify = conf.verify_ssl or false, | ||
| keepalive = conf.keepalive or false, | ||
| keepalive_timeout = conf.keepalive_timeout or 0, | ||
| keepalive_pool = conf.keepalive_pool or 0 | ||
| } | ||
|
|
||
| return setmetatable(obj, mt) | ||
| end | ||
|
|
||
| return _M | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually not add senders dependencies on the rockspec because it doesn't make sense to every user of the module to install them. This is why
luasocketandluasecare not listed here as they are specific to theluasocketbackend.