Skip to content

Commit

Permalink
Don't include optional header in request if blank
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlyocean committed Sep 20, 2022
1 parent 7c87491 commit 9c0c227
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions motioneye/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,9 @@ function initUI() {

return true;
}, '');
makeCustomValidator($('#webHookNotificationsUrlEntry, #webHookEndNotificationsUrlEntry, #webHookNotificationsAcceptHeader, #webHookEndNotificationsAcceptHeader, #webHookNotificationsUserAgent, #webHookEndNotificationsUserAgent'), function (value) {
makeCustomValidator($('#webHookNotificationsUrlEntry, #webHookEndNotificationsUrlEntry'), function (value) {
if (!value.match(webHookUrlValidRegExp)) {
return "use of semicolon (;) or single quote (') is not allowed in web hook URL, Accept, or User-Agent headers";
return "use of semicolon (;) or single quote (') is not allowed in web hook URL";
}

return true;
Expand Down
8 changes: 4 additions & 4 deletions motioneye/templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -1149,12 +1149,12 @@
</td>
<td><span class="help-mark" title="{{ _("La HTTP-metodo por uzi kiam vi petas URL (la donitaj URL-parametroj estos transdonitaj kiel indikite ĉi tie).") }}">?</span></td>
</tr>
<tr class="settings-item" required="false" depends="webHookNotificationsEnabled motionDetectionEnabled" strip="true">
<tr class="settings-item" validate="^[^;\']*$" depends="webHookNotificationsEnabled motionDetectionEnabled" strip="true">
<td class="settings-item-label"><span class="settings-item-label">Accept Header</span></td>
<td class="settings-item-value"><input type="text" class="styled notifications camera-config" id="webHookNotificationsAcceptHeader" placeholder="e.g. */*"></td>
<td><span class="help-mark" title="If the webhook server would reject requests whose headers are missing Accept key, you can provide one here">?</span></td>
</tr>
<tr class="settings-item" required="false" depends="webHookNotificationsEnabled motionDetectionEnabled" strip="true">
<tr class="settings-item" validate="^[^;\']*$" depends="webHookNotificationsEnabled motionDetectionEnabled" strip="true">
<td class="settings-item-label"><span class="settings-item-label">User-Agent Header</span></td>
<td class="settings-item-value"><input type="text" class="styled notifications camera-config" id="webHookNotificationsUserAgentHeader" placeholder="e.g. curl/7.64.0"></td>
<td><span class="help-mark" title="If the webhook server would reject requests whose headers are missing User-Agent key, you can provide one here">?</span></td>
Expand Down Expand Up @@ -1204,12 +1204,12 @@
</td>
<td><span class="help-mark" title="{{ _("La HTTP-metodo por uzi kiam vi petas URL (la donitaj URL-parametroj estos transdonitaj kiel indikite ĉi tie).") }}">?</span></td>
</tr>
<tr class="settings-item" required="false" depends="webHookEndNotificationsEnabled motionDetectionEnabled" strip="true">
<tr class="settings-item" validate="^[^;\']*$" depends="webHookEndNotificationsEnabled motionDetectionEnabled" strip="true">
<td class="settings-item-label"><span class="settings-item-label">Accept Header</span></td>
<td class="settings-item-value"><input type="text" class="styled notifications camera-config" id="webHookEndNotificationsAcceptHeader" placeholder="e.g. */*"></td>
<td><span class="help-mark" title="If the webhook server would reject requests whose headers are missing Accept key, you can provide one here">?</span></td>
</tr>
<tr class="settings-item" required="false" depends="webHookEndNotificationsEnabled motionDetectionEnabled" strip="true">
<tr class="settings-item" validate="^[^;\']*$" depends="webHookEndNotificationsEnabled motionDetectionEnabled" strip="true">
<td class="settings-item-label"><span class="settings-item-label">User-Agent Header</span></td>
<td class="settings-item-value"><input type="text" class="styled notifications camera-config" id="webHookEndNotificationsUserAgentHeader" placeholder="e.g. curl/7.64.0"></td>
<td><span class="help-mark" title="If the webhook server would reject requests whose headers are missing User-Agent key, you can provide one here">?</span></td>
Expand Down
14 changes: 8 additions & 6 deletions motioneye/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@


def parse_options(parser, args):
parser.add_argument('method', help='the HTTP method to use')
parser.add_argument('accept', help='the Accept header for the request')
parser.add_argument('useragent', help='the User Agent header for the request')
parser.add_argument('accept', help='the Accept header for the request')
parser.add_argument('method', help='the HTTP method to use')
parser.add_argument('url', help='the URL for the request')

return parser.parse_args(args)
Expand All @@ -42,17 +42,19 @@ def main(parser, args):

logging.debug('hello!')
logging.debug('method = %s' % options.method)
logging.debug('accept = %s' % options.accept)
logging.debug('useragent = %s' % options.useragent)
if 'accept' in options:
logging.debug('accept = %s' % options.accept)
if 'useragent' in options:
logging.debug('useragent = %s' % options.useragent)
logging.debug('url = %s' % options.url)

headers = {}
parts = urllib.parse.urlparse(options.url)
url = options.url
data = None
if 'accept' in options:
if 'accept' in options and options.accept:
headers['Accept'] = options.accept
if 'useragent' in options:
if 'useragent' in options and options.useragent:
headers['User-Agent'] = options.useragent

if options.method == 'POST':
Expand Down

0 comments on commit 9c0c227

Please sign in to comment.