Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
antSword
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
HuangJunbo
antSword
Commits
52dc08c1
Commit
52dc08c1
authored
Jun 29, 2016
by
Antoor
Committed by
GitHub
Jun 29, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #65 from antoor/v2.0-beta-request-headers
v2.0-beta::custom request headers && body
parents
caee03a6
56d4cc6c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
10 deletions
+25
-10
request.js
modules/request.js
+22
-9
base.js
source/core/base.js
+3
-1
No files found.
modules/request.js
View file @
52dc08c1
...
@@ -93,16 +93,23 @@ class Request {
...
@@ -93,16 +93,23 @@ class Request {
onRequest
(
event
,
opts
)
{
onRequest
(
event
,
opts
)
{
logger
.
debug
(
'onRequest::opts'
,
opts
);
logger
.
debug
(
'onRequest::opts'
,
opts
);
superagent
const
_request
=
superagent
.
post
(
opts
[
'url'
]);
.
post
(
opts
[
'url'
])
// 设置headers
.
set
(
'User-Agent'
,
USER_AGENT
)
_request
.
set
(
'User-Agent'
,
USER_AGENT
);
// 自定义headers
for
(
let
_
in
opts
.
headers
)
{
_request
.
set
(
_
,
opts
.
headers
[
_
]);
}
// 自定义body
const
_postData
=
Object
.
assign
({},
opts
.
body
,
opts
.
data
);
_request
.
proxy
(
APROXY_CONF
[
'uri'
])
.
proxy
(
APROXY_CONF
[
'uri'
])
.
type
(
'form'
)
.
type
(
'form'
)
// 超时
// 超时
.
timeout
(
REQ_TIMEOUT
)
.
timeout
(
REQ_TIMEOUT
)
// 忽略HTTPS
// 忽略HTTPS
.
ignoreHTTPS
(
opts
[
'ignoreHTTPS'
])
.
ignoreHTTPS
(
opts
[
'ignoreHTTPS'
])
.
send
(
opts
[
'data'
]
)
.
send
(
_postData
)
.
parse
((
res
,
callback
)
=>
{
.
parse
((
res
,
callback
)
=>
{
this
.
parse
(
opts
[
'tag_s'
],
opts
[
'tag_e'
],
(
chunk
)
=>
{
this
.
parse
(
opts
[
'tag_s'
],
opts
[
'tag_e'
],
(
chunk
)
=>
{
event
.
sender
.
send
(
'request-chunk-'
+
opts
[
'hash'
],
chunk
);
event
.
sender
.
send
(
'request-chunk-'
+
opts
[
'hash'
],
chunk
);
...
@@ -139,17 +146,23 @@ class Request {
...
@@ -139,17 +146,23 @@ class Request {
let
indexEnd
=
-
1
;
let
indexEnd
=
-
1
;
let
tempData
=
[];
let
tempData
=
[];
// 开始HTTP请求
const
_request
=
superagent
.
post
(
opts
[
'url'
]);
superagent
// 设置headers
.
post
(
opts
[
'url'
])
_request
.
set
(
'User-Agent'
,
USER_AGENT
);
.
set
(
'User-Agent'
,
USER_AGENT
)
// 自定义headers
for
(
let
_
in
opts
.
headers
)
{
_request
.
set
(
_
,
opts
.
headers
[
_
]);
}
// 自定义body
const
_postData
=
Object
.
assign
({},
opts
.
body
,
opts
.
data
);
_request
.
proxy
(
APROXY_CONF
[
'uri'
])
.
proxy
(
APROXY_CONF
[
'uri'
])
.
type
(
'form'
)
.
type
(
'form'
)
// 设置超时会导致文件过大时写入出错
// 设置超时会导致文件过大时写入出错
// .timeout(timeout)
// .timeout(timeout)
// 忽略HTTPS
// 忽略HTTPS
.
ignoreHTTPS
(
opts
[
'ignoreHTTPS'
])
.
ignoreHTTPS
(
opts
[
'ignoreHTTPS'
])
.
send
(
opts
[
'data'
]
)
.
send
(
_postData
)
.
pipe
(
through
(
.
pipe
(
through
(
(
chunk
)
=>
{
(
chunk
)
=>
{
// 判断数据流中是否包含后截断符?长度++
// 判断数据流中是否包含后截断符?长度++
...
...
source/core/base.js
View file @
52dc08c1
...
@@ -239,7 +239,9 @@ class Base {
...
@@ -239,7 +239,9 @@ class Base {
tag_s
:
opt
[
'tag_s'
],
tag_s
:
opt
[
'tag_s'
],
tag_e
:
opt
[
'tag_e'
],
tag_e
:
opt
[
'tag_e'
],
encode
:
this
.
__opts__
[
'encode'
],
encode
:
this
.
__opts__
[
'encode'
],
ignoreHTTPS
:
(
this
.
__opts__
[
'otherConf'
]
||
{})[
'ignore-https'
]
===
1
ignoreHTTPS
:
(
this
.
__opts__
[
'otherConf'
]
||
{})[
'ignore-https'
]
===
1
,
headers
:
(
this
.
__opts__
[
'httpConf'
]
||
{})[
'headers'
]
||
{},
body
:
(
this
.
__opts__
[
'httpConf'
]
||
{})[
'body'
]
||
{}
});
});
})
})
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment