mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add redirectList property in msg of http-request node
This commit is contained in:
@@ -131,8 +131,16 @@ module.exports = function(RED) {
|
||||
if (msg.hasOwnProperty('followRedirects')) {
|
||||
opts.followRedirect = msg.followRedirects;
|
||||
}
|
||||
var redirectList = [];
|
||||
if (!opts.hasOwnProperty('followRedirect') || opts.followRedirect) {
|
||||
opts.followRedirect = function(res) {
|
||||
var redirectInfo = {
|
||||
location: res.headers.location,
|
||||
};
|
||||
if (res.headers.hasOwnProperty('set-cookie')) {
|
||||
redirectInfo.cookies = extractCookies(res.headers['set-cookie']);
|
||||
}
|
||||
redirectList.push(redirectInfo);
|
||||
if (this.headers.cookie) {
|
||||
delete this.headers.cookie;
|
||||
}
|
||||
@@ -256,17 +264,9 @@ module.exports = function(RED) {
|
||||
msg.headers = res.headers;
|
||||
msg.responseUrl = res.request.uri.href;
|
||||
msg.payload = body;
|
||||
|
||||
msg.redirectList = redirectList;
|
||||
if (msg.headers.hasOwnProperty('set-cookie')) {
|
||||
msg.responseCookies = {};
|
||||
msg.headers['set-cookie'].forEach(function(c) {
|
||||
var parsedCookie = cookie.parse(c);
|
||||
var eq_idx = c.indexOf('=');
|
||||
var key = c.substr(0, eq_idx).trim()
|
||||
parsedCookie.value = parsedCookie[key];
|
||||
delete parsedCookie[key];
|
||||
msg.responseCookies[key] = parsedCookie;
|
||||
});
|
||||
msg.responseCookies = extractCookies(msg.headers['set-cookie']);
|
||||
}
|
||||
msg.headers['x-node-red-request-node'] = hashSum(msg.headers);
|
||||
// msg.url = url; // revert when warning above finally removed
|
||||
@@ -299,6 +299,19 @@ module.exports = function(RED) {
|
||||
this.on("close",function() {
|
||||
node.status({});
|
||||
});
|
||||
|
||||
function extractCookies(setCookie) {
|
||||
var cookies = {};
|
||||
setCookie.forEach(function(c) {
|
||||
var parsedCookie = cookie.parse(c);
|
||||
var eq_idx = c.indexOf('=');
|
||||
var key = c.substr(0, eq_idx).trim()
|
||||
parsedCookie.value = parsedCookie[key];
|
||||
delete parsedCookie[key];
|
||||
cookies[key] = parsedCookie;
|
||||
});
|
||||
return cookies;
|
||||
}
|
||||
}
|
||||
|
||||
RED.nodes.registerType("http request",HTTPRequest,{
|
||||
|
@@ -53,6 +53,8 @@
|
||||
Otherwise, the url of the original request.</dd>
|
||||
<dt>responseCookies <span class="property-type">object</span></dt>
|
||||
<dd>If the response includes cookies, this propery is an object of name/value pairs for each cookie.</dd>
|
||||
<dt>redirectList <span class="property-type">array</span></dt>
|
||||
<dd>If the request was redirected one or more times, the accumulated information will be added to this property. `location` is the next redirect destination. `cookies` is the cookies returned from the redirect source.</dd>
|
||||
</dl>
|
||||
<h3>Details</h3>
|
||||
<p>When configured within the node, the URL property can contain <a href="http://mustache.github.io/mustache.5.html" target="_blank">mustache-style</a> tags. These allow the
|
||||
|
@@ -46,6 +46,8 @@
|
||||
<dd>リクエストの処理時にリダイレクトが発生した場合、このプロパティが最後にリダイレクトされたURLを表します。リダイレクトが起こらなかった場合、最初リクエストのURLを表します。</dd>
|
||||
<dt>responseCookies <span class="property-type">オブジェクト</span></dt>
|
||||
<dd>レスポンスがクッキーを含む場合、このプロパティは各クッキーの名前/値を含むオブジェクトを表します。</dd>
|
||||
<dt>redirectList <span class="property-type">配列</span></dt>
|
||||
<dd>リクエストが一回以上リダイレクトされた場合は、このプロパティに情報が蓄積されます。`location`は、リダイレクト先を示します。`cookies`は、リダイレクト元から返されたクッキー情報です。</dd>
|
||||
</dl>
|
||||
<h3>詳細</h3>
|
||||
<p>ノードの設定でurlプロパティを指定する場合、<a href="http://mustache.github.io/mustache.5.html" target="_blank">mustache形式</a>のタグを含めることができます。これにより、URLを入力メッセージの値から構成することができます。例えば、urlが<code>example.com/{{{topic}}}</code>の場合、<code>msg.topic</code>の値による置き換えを自動的に行います。{{{...}}}表記を使うと、/、&といった文字をmustacheがエスケープするのを抑止できます。</p>
|
||||
|
Reference in New Issue
Block a user