johngeorgewright / grunt-http Goto Github PK
View Code? Open in Web Editor NEWSends a HTTP request and deals with the response.
License: MIT License
Sends a HTTP request and deals with the response.
License: MIT License
Hello,
I would like to set the body
(json
, actually) of a POST request in runtime without using multipart forms. This seems to be impossible because body
must be a constant and is set via options
which is interpreted before tasks get to run.
Am I missing something obvious...? :)
If not, it would seem easy enough to implement in tasks/http.js:call
:
if (typeof(options.body) === 'function') options.body = options.body();
if (typeof(options.json) === 'function') options.json = options.json();
If i want to pass a multipart/form-data, what arguments i need to write the gruntfile.
1.2.0
to 1.3.0
.This version is covered by your current version range and after updating it in your project the build failed.
http-signature is a optionalDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 3 commits.
c8e8805
Bump version due to Signature header support (#83)
2424e96
Updating sshpk version (#86)
276bd13
Add Signature header support. (#83)
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
2.4.3
to 2.5.0
.This version is covered by your current version range and after updating it in your project the build failed.
tough-cookie is a optionalDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 18 commits.
7c1fdf1
2.5.0
9ff4ba5
Qualify the store.removeAllCookies documentation
1855bf3
Additional documentation for removeAllCookies
5cc9bd2
Extract tests, cover multiple error path
28f0808
Only call removeAllCookies if actually implemented
62802ef
remove all cookies from cookie jar at once (#115)
8783d46
Remove left-over mention of MPL from README
8302ebc
Merge pull request #121 from salesforce/punycode-2.1
d6ea115
Merge pull request #120 from salesforce/no-package-lock
b897b49
Merge pull request #119 from salesforce/inline-version
31ad267
Upgrade to punycode 2.1
550f951
Purposefully don't lock dependencies
3d8570c
2.4.4-1
4cbd182
Merge pull request #118 from salesforce/deps-2018jul30
55a41c1
inline package version using genversion
There are 18 commits in total.
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
2 optional dependencies fail, which may or may not be ok. But I'm not able to use the plugin, getting a form-data error.
2 failing deps:
I'm using grunt-http to fetch some data during runtime.
On a some API calling I observe "ESOCKETTIMEDOUT" error as follows:
Now I observe grunt-http
have dependency on request
, which is deprecated now.
Also checked request.js
in node_modules
and observer the error as follows:
Check through postman it's working fine and when I'm configured same data through grunt it's not working. It was working previously, but from october,2023 I observe the issue.
Can you give me any suggestion, what is exact issue and how to resolve this?
I have a task that does the following:
The collection is read correctly and the first HTTP DELETE is also executed correctly. Then no additional HTTP DELETE commands are send. It appears that the first one never closes.
I included the code. The task in question is reset=images. Thanks in advance for your help!
Object.size = function(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
module.exports = function(grunt) {
grunt.initConfig({
debug: {
options: {
open: false // do not open node-inspector in Chrome automatically
}
},
'read-person': {
options: {
id: '348920c8-fd34-40a8-98bf-6a412600c20c'
}
},
'read-people': {
options: {
id: '25d3ecdd-00e4-4e4c-98b1-35b487fd1cde'
}
},
'read-project': {
options: {
id: '25d3ecdd-00e4-4e4c-98b1-35b487fd1cde'
}
},
'reset-image': {
options: {
id: '503a7a1d-21a2-44b3-81f5-2e9f2b4b151f'
}
},
'config': grunt.file.readJSON('config.json'),
'personNames': grunt.file.readJSON('personNames.json'),
'personTitles': grunt.file.readJSON('personTitles.json'),
'companyNames': grunt.file.readJSON('companyNames.json'),
'projectNames': grunt.file.readJSON('projectNames.json')
});
// This property is required by all tasks
grunt.config.requires('config');
grunt.config.requires('personNames');
grunt.config.requires('personTitles');
grunt.config.requires('companyNames');
grunt.config.requires('projectNames');
var config = grunt.config.get('config'),
personNames = grunt.config.get('personNames'),
personTitles = grunt.config.get('personTitles'),
companyNames = grunt.config.get('companyNames'),
projectNames = grunt.config.get('projectNames');
grunt.loadNpmTasks('grunt-debug-task');
grunt.registerTask('reset-images', 'Reset Images', function(server){
grunt.log.writeln('MD-INIT: Reset Images Host: ' + getHost(server, config));
var $this = this,
done = this.async(),
http = require('http'),
requestOptions = {
//http://integration.markodojo.com/markodojo_solution/rest/person
host: getHost(server, config),
path: getPath(config, 'person', null),
port: 80,
method: 'GET'
},
imageDeleteHandler = function(bufferJson) {
grunt.log.writeln("Deleted image for: " + bufferJson["id"])
},
readPeopleHandler = function (bufferJson) {
// show images that have and have not images
var bufferJsonLength = bufferJson.length;
for(var i=0; i<bufferJsonLength; i++) {
var id = bufferJson[i]["id"];
var name = bufferJson[i]["name"];
var image = bufferJson[i]["image"];
if (Object.size(image) != 4) {
grunt.log.writeln('MD-INIT: Reset Images Path: ' + getPath(config, 'image/' + image.id, null));
requestOptions = {
//http://integration.markodojo.com/markodojo_solution/rest/person
host: getHost(server, config),
path: getPath(config, 'image/' + image.id, null),
port: 80,
method: 'DELETE'
};
httpCmd(requestOptions, $this.async(), imageDeleteHandler);
}
}
};
httpCmd(requestOptions, done, readPeopleHandler);
});
var getHost = function (server, config) {
var host;
if (server == null) server = config.server;
host = server + "." + config.domain;
return host;
};
var getPath = function (config, resource, taskProperty) {
var path;
path = '/';
path += config.path;;
path += '/' ;
path += resource;
if (taskProperty != null) {
path += '/';
path += grunt.config.get(taskProperty);
}
return path;
}
var httpCmd = function (requestOptions, done, callback) {
grunt.log.writeln('Running request function');
// https://www.npmjs.org/package/grunt-http
var http = require('http') ,
request = http.request(requestOptions, function(response) {
var bufferJoined = '';
//grunt.log.writeln('request');
response.on('data', function(data){
bufferJoined += data;
});
response.on('end', function() {
grunt.log.writeln("Response status: " + response.statusCode);
//grunt.log.writeln(bufferJoined);
var bufferJson = JSON.parse(bufferJoined);
done();
callback(bufferJson)
});
response.on('finish', function(){
callback(bufferJson);
});
response.on('close', function(){
callback(bufferJson);
});
});
if (requestOptions.method == "POST") {
request.write(requestOptions.json);
}
request.end();
};
function getRandomArrayElement (array) {
var arrayLength = array.length;
var randomIndex = Math.floor(Math.random() * arrayLength);
var randomElement = array[randomIndex];
return randomElement;
}
};
how to execute callback function after http request complete?
I have to say, grunt-http document & example is not too much.
To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:
.nvmrc
with the new onepackage.json
files, so that was left aloneIf you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.
Greenkeeper has checked the engines
key in any package.json
file, the .nvmrc
file, and the .travis.yml
file, if present.
engines
was only updated if it defined a single version, not a range..nvmrc
was updated to Node.js 10.travis.yml
was only changed if there was a root-level node_js
that didn’t already include Node.js 10, such as node
or lts/*
. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.For many simpler .travis.yml
configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
Can i define a user agent? If yes, how?
Hi,
I just want to grab a file via http and save it for further use in my Grunt task. I tried your example:
grunt.initConfig({
http: {
your_service: {
options: {
url: 'your/url.com',
},
dest: 'optional/file/to/save/response'
}
}
})
but got the following error: Cannot call method 'map' of undefined
. (See https://github.com/johngeorgewright/grunt-http/blob/master/tasks/http.js#L63).
To get it working for now, I'm providing an empty src-array, which is – of cause – not ideal:
grunt.initConfig({
http: {
your_service: {
options: {
url: 'your/url.com',
},
src: [],
dest: 'optional/file/to/save/response'
}
}
})
2.0.0
to 2.1.0
.This version is covered by your current version range and after updating it in your project the build failed.
grunt-contrib-nodeunit is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 3 commits.
d370717
v2.1.0
02089d5
Clean up and update to latest contrib (#58)
deca505
Upgrade nodeunit-x from 0.12.1 to 0.13.0 and tap from ^12.0.1 to ^14.10.6 (#57)
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
7.0.7
to 7.0.9
.This version is covered by your current version range and after updating it in your project the build failed.
hawk is a optionalDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 8 commits.
15eef2e
7.0.9
b117bce
Update deps. Closes #248
587dc7d
Close #245
886087a
Update README.md
cb1678d
Merge pull request #237 from JSteunou/patch-1
0526b77
Fix typo in example code
7f6a973
Update README.md
f6f7373
Update README.md
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
2.3.3
to 2.4.0
.This version is covered by your current version range and after updating it in your project the build failed.
form-data is a optionalDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 7 commits.
8512eef
Updated build/test/badges
0f8da06
Bumped version 2.4.0
ff085f3
Merge pull request #419 from JBtje/add-getBuffer
953a2af
Merge pull request #425 from byr-gdp/feature/add-axios-integration-doc
4e3954d
docs(readme): remove unnecessary bracket
b729a7e
docs(readme): add axios integration document
e90a76a
Updated: Certificate
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
I try to do it, but don't know how to exec multiple http request.
Hope to your reply, thank you!
Version 1.4.1 is being used...
The Following snippet does work perfectly fine, but the 'body' part does not cause the module to send the data (yes, the file ./dist/usher.min.js exists):
http: {
local: {
options: {
url: 'http://0.0.0.0:8765/root/js',
method: 'POST',
headers: {
'Content-Type': 'text/javascript'
},
body: function () {
return grunt.file.read(path.join(__dirname, 'dist', 'usher.min.js'));
},
encoding: 'utf8',
auth: {
user: '<%= httpauth.HTTPUser %>',
pass: '<%= httpauth.HTTPPass %>'
}
}
}
}
Also, if I substitute the 'body' func with "body: 'test', ", the server still recieves an empty body.
After run http:index I get this error:
Running "http:index" (http) task
Fatal error: 500 Error: connect ECONNREFUSED<br> at exports._errnoException (util.js:746:11)<br> at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1010:19)
File http.js
:
module.exports = {
index: {
options: {
url: 'http://<%= connect.fetch.options.hostname %>:<%= connect.fetch.options.port %>/'
},
dest: '.tmp/index.html'
}
};
Any Idea about this issue? Thanks!
OSX 10.10
am getting "Fatal error: tunneling socket could not be established, cause=Parse Error" while accessing internal corporate web services & verified with/without npm proxy and system proxy. still getting the same error but its working fine with others machines on same network. please help me to solve this problem.
machine: windows 7
grunt-cli v0.1.13
grunt v0.4.5
npm -v 2.14.7
node -v v4.2.2
Tried running the tests but kept failing when running "grunt default":
Running "jshint:all" (jshint) task
>> 3 files lint free.
Running "clean:tests" (clean) task
Cleaning "tmp"...OK
Running "http:basic" (http) task
>> 200
Running "http:closure" (http) task
>> 200
Running "http:bodyAtRuntime" (http) task
>> 200
Running "http:ignoreErrors" (http) task
>> 0
Running "http:multipart" (http) task
>> 200
Running "http:callback" (http) task
>> 200
Running "nodeunit:tests" (nodeunit) task
Testing http_test.jsFF...
>> http - it can fetch something just using a destination
>> Message: different content to what's been downloaded
>> Error: '<!DOCTYPE html><html><head><meta encoding="utf8"><meta name="robots" content="index, follow"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>John Wright | Web Developer | SEO Webmaster |
UX Designer</title><link rel="stylesheet" href="/stylesheets/base.css"><script>document.getElementsByTagName(\'html\')[0].className+=\'js-enabled js-loading\'\n</script></head><body><ul class="ah"><li><a href="#body">Skip to co
ntent</a></li></ul><div class="navbar navbar-fixed-top navbar-inverse"><div class="navbar-inner"><div class="container"><a data-toggle="collapse" data-target=".nav-collapse" href="#main-nav" class="btn btn-navbar">Menu</a><nav
id="main-nav"><a href="/" class="brand"><abbr title="John Wright"><span class="jw-logo-tag-delim"><</span>j<span class="jw-logo-tag-delim">></</span>w<span class="jw-logo-tag-delim">></span></abbr></a><div class="na
v-collapse collapse"><ul class="nav pull-right"><!--mixin navItem(\'/professional-background\', \'Professional Background\')--><li class=""><a href="/portfolio">Portfolio</a></li><li class=""><a href="/technologies">Technologie
s</a></li><li class=""><a href="/prices">Prices</a></li><li class=""><a href="https://github.com/johngeorgewright">Find me on GitHub</a></li><li class=""><a href="/docs/CV.pdf">Download CV</a></li><li class=""><a href="mailto:j
[email protected]">Contact</a></li></ul></div></nav></div></div></div><div id="body" class="container"><article><header><div class="media header-media"><img src="http://www.gravatar.com/avatar/2ad6ebafae880b4bedcadb214
c558caa.png" alt="Wee Mee" class="img-rounded pull-left"><div class="media-body"><h1>Web Developer</h1><p class="lead">Specialising in profitable, commercial and communication solutions for you unique business requirements.</p>
</div></div></header><p>Hi there,</p><p>My name is John Wright and I\'m a freelance Web Developer. I\'ve had over 5 years experience with web sites large and small. I\'m senior in both backend and frontend development and I\'m
highly skilled in search engine optimisation helping you get the customers to your site.</p><p>If you\'d like to hire me, have any enquiries or just fancy a chat, please don\'t hesitate to <a href="mailto:johngeorge.wright
@gmail.com">contact me</a></p></article></div><script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script><script src="/javascripts/bootstrap-min.js"></script><script>jQuery(function(){jQuery(\'html\').add
Class(\'js-loaded\').removeClass(\'js-loading\')})\n</script></body></html>' == '<!DOCTYPE html><html><head><meta encoding="utf8"><meta name="robots" content="index, follow"><meta name="viewport" content="width=device-width, in
itial-scale=1.0"><title>John Wright | Web Developer | SEO Webmaster | UX Designer</title><link rel="stylesheet" href="/stylesheets/base.css"><script>document.getElementsByTagName(\'html\')[0].className+=\'js-enabled js-loading\
'\r\n</script></head><body><ul class="ah"><li><a href="#body">Skip to content</a></li></ul><div class="navbar navbar-fixed-top navbar-inverse"><div class="navbar-inner"><div class="container"><a data-toggle="collapse" data-targ
et=".nav-collapse" href="#main-nav" class="btn btn-navbar">Menu</a><nav id="main-nav"><a href="/" class="brand"><abbr title="John Wright"><span class="jw-logo-tag-delim"><</span>j<span class="jw-logo-tag-delim">></</sp
an>w<span class="jw-logo-tag-delim">></span></abbr></a><div class="nav-collapse collapse"><ul class="nav pull-right"><!--mixin navItem(\'/professional-background\', \'Professional Background\')--><li class=""><a href="/portf
olio">Portfolio</a></li><li class=""><a href="/technologies">Technologies</a></li><li class=""><a href="/prices">Prices</a></li><li class=""><a href="https://github.com/johngeorgewright">Find me on GitHub</a></li><li class=""><
a href="/docs/CV.pdf">Download CV</a></li><li class=""><a href="mailto:[email protected]">Contact</a></li></ul></div></nav></div></div></div><div id="body" class="container"><article><header><div class="media header-m
edia"><img src="http://www.gravatar.com/avatar/2ad6ebafae880b4bedcadb214c558caa.png" alt="Wee Mee" class="img-rounded pull-left"><div class="media-body"><h1>Web Developer</h1><p class="lead">Specialising in profitable, commerci
al and communication solutions for you unique business requirements.</p></div></div></header><p>Hi there,</p><p>My name is John Wright and I\'m a freelance Web Developer. I\'ve had over 5 years experience with web sites large a
nd small. I\'m senior in both backend and frontend development and I\'m highly skilled in search engine optimisation helping you get the customers to your site.</p><p>If you\'d like to hire me, have any enquiries or just fancy
a chat, please don\'t hesitate to <a href="mailto:[email protected]">contact me</a></p></article></div><script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script><script src="/javascripts/b
ootstrap-min.js"></script><script>jQuery(function(){jQuery(\'html\').addClass(\'js-loaded\').removeClass(\'js-loading\')})\r\n</script></body></html>'
>> at Object.exports.http.it can fetch something just using a destination (test\http_test.js:9:10)
>> http - it should have downloaded compiled code from the closure service
>> Message: different content to what's been downloaded
>> Error: 'function hello(a){alert("Hello, "+a)}hello("New user");\n' == 'function hello(a){alert("Hello, "+a)}hello("New user");\r\n'
>> at Object.exports.http.it should have downloaded compiled code from the closure service (test\http_test.js:19:10)
Warning: 2/6 assertions failed (11ms) Use --force to continue.
Aborted due to warnings.
7.3.2
to 7.4.1
.This version is covered by your current version range and after updating it in your project the build failed.
sinon is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 44 commits.
671330c
Update docs/changelog.md and set new release id in docs/_config.yml
dce58d4
Add release documentation for v7.4.1
56b00a7
7.4.1
7637eef
Update CHANGELOG.md and AUTHORS for new release
9b61f26
Update nise and lolex (minor versions)
e4f9ad4
Make eslint happy
a9fedea
npm audit
9a34598
Upgrade mocha to v6
55231d5
Update @babel/core and babel-plugin-istanbul
33f0163
Update @sinonjs/referee and fix deprecations
6caa89b
Update @sinonjs/samsam
0bd5066
Update puppeteer and mochify
985a827
Merge pull request #2063 from dustinfarris/pass-through-class
85d3f2a
add docs for callThroughWithNew
8e00c22
use slice to convert arguments object into an array
There are 44 commits in total.
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
2.3.2
to 2.3.3
.This version is covered by your current version range and after updating it in your project the build failed.
form-data is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
The latest version [email protected] uses hawk ^4.0.0. However, [email protected] has a vulnerability which is introduced by [email protected]. More information is here:
https://nodesecurity.io/advisories/566
https://snyk.io/vuln/npm:hoek:20180212
Could you please update hawk to the latest version to solve the vulnerability? Thank you so much.
Hello,
Is it possible to have multiple service endpoints when using the multipart/form-data, I can see that there is another one who have filed an issue:
grunt-http can't support multiple http requests?
#10
where you show how it is possible to have multiple service endpoints when not using multipart/form-data.
Is it possible - if yes how to? :)
If there´s provided a callback function via options, it will only be executed, if the response contains a body. But there are status codes which may not or even must not contain a message body (e.g. 204, 401, ...).
The callback function should also be executed, if the body is empty.
Hi,
Awesome module :)
I would like to create a WP user with grunt. To do this, I need to login with grunt. Can you help me with this? This is my code: http://pastebin.com/ctXQDQB6
Thanks! :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.