Skip to content
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

Added custom headers support for Aria2 RPC HTTP(s) requests #638

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/langs/zh_Hans.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ Aria2 RPC Address=Aria2 RPC 地址
Aria2 RPC Protocol=Aria2 RPC 协议
Aria2 RPC Http Request Method=Aria2 RPC Http 请求方法
POST method only supports aria2 v1.15.2 and above.=POST 方法仅支持 aria2 v1.15.2 及以上.
Aria2 RPC Http Request Header=Aria2 RPC Http 请求头
Append HEADER to Aria2 RPC Http request header. Put one item per line, each item containing "header name: header value".=增加 Aria2 RPC Http 请求头內容. 每行放置一项, 每项包含 "请求头名: 请求头值".
Aria2 RPC Secret Token=Aria2 RPC 密钥
Activate=激活
Reset Settings=重置设置
Expand Down
2 changes: 2 additions & 0 deletions src/langs/zh_Hant.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ Aria2 RPC Address=Aria2 RPC 位址
Aria2 RPC Protocol=Aria2 RPC 協定
Aria2 RPC Http Request Method=Aria2 RPC Http 要求方法
POST method only supports aria2 v1.15.2 and above.=POST 方法僅支援 aria2 v1.15.2 及以上.
Aria2 RPC Http Request Header=Aria2 RPC Http 要求標頭
Append HEADER to Aria2 RPC Http request header. Put one item per line, each item containing "header name: header value".=增加 Aria2 RPC Http 要求標頭內容. 每行放置一項, 每項包含 "標頭名: 標頭值".
Aria2 RPC Secret Token=Aria2 RPC 金鑰
Activate=啟用
Reset Settings=重設設定
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/config/defaultLanguage.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@
'Aria2 RPC Protocol': 'Aria2 RPC Protocol',
'Aria2 RPC Http Request Method': 'Aria2 RPC Http Request Method',
'POST method only supports aria2 v1.15.2 and above.': 'POST method only supports aria2 v1.15.2 and above.',
'Aria2 RPC Http Request Header': 'Aria2 RPC Http Request Header',
'Append HEADER to Aria2 RPC Http request header. Put one item per line, each item containing "header name: header value".': 'Append HEADER to Aria2 RPC Http request header. Put one item per line, each item containing "header name: header value".',
'Aria2 RPC Secret Token': 'Aria2 RPC Secret Token',
'Activate': 'Activate',
'Reset Settings': 'Reset Settings',
Expand Down
14 changes: 13 additions & 1 deletion src/scripts/services/aria2HttpRpcService.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function () {
'use strict';

angular.module('ariaNg').factory('aria2HttpRpcService', ['$http', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgLogService', function ($http, ariaNgCommonService, ariaNgSettingService, ariaNgLogService) {
angular.module('ariaNg').factory('aria2HttpRpcService', ['$http', 'ariaNgConstants', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgLogService', 'ariaNgStorageService', function ($http, ariaNgConstants, ariaNgCommonService, ariaNgSettingService, ariaNgLogService, ariaNgStorageService) {
var rpcUrl = ariaNgSettingService.getCurrentRpcUrl();
var method = ariaNgSettingService.getCurrentRpcHttpMethod();

Expand Down Expand Up @@ -66,6 +66,18 @@
requestContext.url = getUrlWithQueryString(requestContext.url, context.requestBody);
}

var options = ariaNgStorageService.get(ariaNgConstants.optionStorageKey);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not import ariaNgStorageService into this service, because ariaNgSettingService is the unique interface for other service/controller getting/setting option value. You should put a method like getCurrentRpcHttpRequestHeaders into ariaNgSettingService, this method should return a array containing all request headers. I think you can refer to getCurrentRpcUrl or getCurrentRpcDisplayName method.

By the way, I think you should also put a default option value (maybe a empty string "") into scripts/config/constants.js

if (options.httpHeader) {
var lines = options.httpHeader.split("\n");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use single quotes

requestContext.headers = {};
angular.forEach(lines, function (item) {
var entry = item.split(":");
if (entry.length == 2) {
requestContext.headers[entry[0].trim()] = entry[1].trim();
}
})
}

ariaNgLogService.debug('[aria2HttpRpcService.request] ' + (context && context.requestBody && context.requestBody.method ? context.requestBody.method + ' ' : '') + 'request start', requestContext);

return $http(requestContext).then(function onSuccess(response) {
Expand Down
3 changes: 2 additions & 1 deletion src/scripts/services/ariaNgSettingService.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@
rpcInterface: setting.rpcInterface,
protocol: setting.protocol,
httpMethod: setting.httpMethod,
secret: setting.secret
httpHeader: setting.httpHeader,
secret: setting.secret,
};
};

Expand Down
11 changes: 11 additions & 0 deletions src/views/settings-ariang.html
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,17 @@
</select>
</div>
</div>
<div class="row" ng-if="setting.protocol === 'http' || setting.protocol === 'https'">
<div class="setting-key setting-key-without-desc col-sm-4">
<span translate>Aria2 RPC Http Request Header</span>
<i class="icon-primary fa fa-question-circle" ng-tooltip-container="body" ng-tooltip-placement="top"
ng-tooltip="{{'Append HEADER to Aria2 RPC Http request header. Put one item per line, each item containing &quot;header name: header value&quot;.' | translate}}"></i>
</div>
<div class="setting-value col-sm-8">
<textarea class="form-control ng-pristine ng-valid ng-touched" rows="6" placeholder="" ng-model="setting.httpHeader"
ng-change="updateRpcSetting(setting, 'httpHeader')" style="width: 100%;"></textarea>
</div>
</div>
<div class="row">
<div class="setting-key setting-key-without-desc col-sm-4">
<span translate>Aria2 RPC Secret Token</span>
Expand Down