Last active
July 13, 2017 08:04
-
-
Save dcharbonnier/b4f9ff9a30bfa4fd17e4ed2813508f28 to your computer and use it in GitHub Desktop.
alpine node-libcurl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git clone git@gist.github.com:b4f9ff9a30bfa4fd17e4ed2813508f28.git; | |
cd b4f9ff9a30bfa4fd17e4ed2813508f28; | |
docker build .; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM node:7.5-alpine | |
RUN mkdir -p /opt/node-lib-curl | |
WORKDIR /opt/node-lib-curl | |
RUN apk add -q --no-progress --no-cache libcurl openssl openssl-dev python python-dev alpine-sdk curl-dev py-pip \ | |
&& npm install shelljs mocha | |
ADD test.js ./test/ | |
ADD pycurl_exec.py . | |
ADD node-libcurl.js . | |
RUN ./node_modules/mocha/bin/mocha -c --timeout 60000 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Curl = require('node-libcurl').Curl; | |
let url = process.argv[2]; | |
const curl = new Curl(); | |
curl.setOpt('URL', url); | |
curl.setOpt('FOLLOWLOCATION', true); | |
curl.on('end', () => process.exit(0)); | |
curl.on('error', (err)=> { | |
curl.close(); | |
console.error(err); | |
process.exit(1); | |
}); | |
curl.perform(); | |
// Timeout if it take too long google reply in less than 5 seconds | |
setTimeout(()=> { | |
console.error("Timeout"); | |
process.exit(1); | |
}, 5000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import pycurl | |
PY3 = sys.version_info[0] > 2 | |
class Test: | |
def __init__(self): | |
self.contents = '' | |
if PY3: | |
self.contents = self.contents.encode('ascii') | |
def body_callback(self, buf): | |
self.contents = self.contents + buf | |
url = sys.argv[1] | |
t = Test() | |
c = pycurl.Curl() | |
c.setopt(c.URL, url) | |
c.setopt(c.WRITEFUNCTION, t.body_callback) | |
c.perform() | |
c.close() | |
if t.contents is not None: | |
exit(0) | |
else: | |
exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('shelljs/global'); | |
const assert = require('assert'); | |
let version_install = "https://github.com/JCMais/node-libcurl/archive/develop.tar.gz"; | |
describe('pycurl', function () { | |
before(() => { | |
exec( | |
"PYCURL_SSL_LIBRARY=openssl " + | |
"pip install pycurl", {silent: true}); | |
}); | |
it('should get an http url', (done) => { | |
let result = exec("python pycurl_exec.py http://www.google.fr", {silent: true}); | |
if (result.code === 0) { | |
done(); | |
} else { | |
throw new Error(result.stderr + result.stdout); | |
} | |
}); | |
it('should get an https url', (done) => { | |
let result = exec("python pycurl_exec.py https://www.google.fr", {silent: true}); | |
if (result.code === 0) { | |
done(); | |
} else { | |
throw new Error(result.stderr + result.stdout); | |
} | |
}); | |
}); | |
describe('node-libcurl', function () { | |
beforeEach(()=> { | |
cd('/tmp'); | |
rm('-rf', '/tmp/*'); | |
}); | |
describe('npm install', () => { | |
it('should succeed', (done) => { | |
let result = exec(`npm --loglevel silent install ${version_install}`, {silent: true}); | |
if (result.code === 0) { | |
done(); | |
} else { | |
throw new Error(result.stderr + result.stdout); | |
} | |
}); | |
it('should import without error', (done) => { | |
exec(`npm --loglevel silent install ${version_install}`, {silent: true}); | |
let result = exec('echo "require(\'node-libcurl\')" | node', {silent: true}); | |
if (result.code === 0) { | |
done(); | |
} else { | |
throw new Error(result.stderr + result.stdout); | |
} | |
}); | |
}); | |
describe('npm install --build-from-source', () => { | |
it('should succeed', (done) => { | |
let result = exec(`npm --loglevel silent install ${version_install} --build-from-source`, {silent: true}); | |
if (result.code === 0) { | |
done(); | |
} else { | |
throw new Error(result.stderr + result.stdout); | |
} | |
}); | |
it('should import without error', (done) => { | |
exec(`npm --loglevel silent install ${version_install} --build-from-source`, {silent: true}); | |
let result = exec('echo "require(\'node-libcurl\')" | node', {silent: true}); | |
if (result.code === 0) { | |
done(); | |
} else { | |
throw new Error(result.stderr + result.stdout); | |
} | |
}); | |
it('should get an http url', (done) => { | |
exec(`npm --loglevel silent install ${version_install} --build-from-source`, {silent: true}); | |
cp("/opt/node-lib-curl/node-libcurl.js", "/tmp/"); | |
let result = exec("node /tmp/node-libcurl.js http://google.fr", {silent: true}); | |
if (result.code === 0) { | |
done(); | |
} else { | |
throw new Error(result.stderr + result.stdout); | |
} | |
}); | |
it('should get an https url', (done) => { | |
exec(`npm --loglevel silent install ${version_install} --build-from-source`, {silent: true}); | |
cp("/opt/node-lib-curl/node-libcurl.js", "/tmp/"); | |
let result = exec("node /tmp/node-libcurl.js https://google.fr", {silent: true}); | |
if (result.code === 0) { | |
done(); | |
} else { | |
throw new Error(result.stderr + result.stdout); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adobe-CEP/Samples@8f42382