Skip to content

Commit

Permalink
upgrade to got 9
Browse files Browse the repository at this point in the history
  • Loading branch information
StarpTech committed Aug 4, 2018
1 parent db65512 commit 3c1ab0a
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 37 deletions.
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
"publish": "lerna publish",
"lint": "eslint ./**/*.js",
"coverage": "npm run test && nyc report --reporter=html",
"coveralls": "nyc report --reporter=text-lcov | coveralls"
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"lerna": "lerna"
},
"devDependencies": {
"code": "^5.2.0",
"concurrently": "^3.6.0",
"concurrently": "^3.6.1",
"coveralls": "^3.0.2",
"delay": "^3.0.0",
"eslint": "^4.19.1",
Expand All @@ -30,7 +31,7 @@
"eslint-plugin-prettier": "^2.6.2",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^3.1.0",
"fastify": "^1.8.0",
"fastify": "^1.9.0",
"husky": "^0.14.3",
"istanbul": "^0.4.5",
"lerna": "^2.11.0",
Expand All @@ -39,9 +40,9 @@
"nock": "^9.4.2",
"nyc": "^12.0.2",
"p-event": "^2.1.0",
"prettier": "^1.13.7",
"prettier": "^1.14.0",
"pretty-quick": "^1.6.0",
"sinon": "^6.1.3",
"sinon": "^6.1.4",
"split2": "^2.2.0",
"ws": "^6.0.0"
},
Expand Down
9 changes: 6 additions & 3 deletions packages/websub-hub-publisher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ module.exports = function build(options) {
options = Hoek.applyToDefaults(defaultOptions, options || {})

const publisher = {}
publisher.httpClient = Got
publisher.httpClient = Got.extend({
timeout: options.timeout,
baseUrl: options.hubUrl,
form: true
})
publisher.publish = publish

return publisher

function publish(url) {
return this.httpClient.post(options.hubUrl + '/publish', {
form: true,
return this.httpClient.post('/publish', {
body: {
'hub.mode': 'publish',
'hub.url': url
Expand Down
2 changes: 1 addition & 1 deletion packages/websub-hub-publisher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"hub"
],
"dependencies": {
"got": "^8.3.2",
"got": "^9.0.0",
"hoek": "^5.0.3"
}
}
14 changes: 8 additions & 6 deletions packages/websub-hub-subscriber/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ module.exports = function build(options) {
options = Hoek.applyToDefaults(defaultOptions, options || {})

const subscriber = {}
subscriber.httpClient = Got
subscriber.httpClient = Got.extend({
timeout: options.timeout,
baseUrl: options.hubUrl,
form: true
})
subscriber.subscribe = subscribe
subscriber.unsubscribe = unsubscribe
subscriber.list = list

return subscriber

function subscribe(topic, callbackUrl, useWebsocket) {
return this.httpClient.post(options.hubUrl, {
form: true,
return this.httpClient.post('/', {
body: {
'hub.callback': callbackUrl,
'hub.mode': 'subscribe',
Expand All @@ -32,8 +35,7 @@ module.exports = function build(options) {
}

function unsubscribe(topic, callbackUrl) {
return this.httpClient.post(options.hubUrl, {
form: true,
return this.httpClient.post('/', {
body: {
'hub.callback': callbackUrl,
'hub.mode': 'unsubscribe',
Expand All @@ -43,7 +45,7 @@ module.exports = function build(options) {
}

function list(start, limit) {
return this.httpClient.get(options.hubUrl + '/subscriptions', {
return this.httpClient.get('/subscriptions', {
query: { start, limit }
})
}
Expand Down
2 changes: 1 addition & 1 deletion packages/websub-hub-subscriber/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"hub"
],
"dependencies": {
"got": "^8.3.2",
"got": "^9.0.0",
"hoek": "^5.0.3"
}
}
28 changes: 11 additions & 17 deletions packages/websub-hub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const defaultOptions = {
url: '',
useNewUrlParser: true
},
retries: 2
retry: 2
}

function build(options) {
Expand Down Expand Up @@ -145,7 +145,10 @@ function WebSubHub(options) {
})
}

this.httpClient = Got
this.httpClient = Got.extend({
timeout: this.options.timeout,
retry: this.options.retry
})
this.hyperid = Hyperid()
this._registerHttpHandler()
}
Expand Down Expand Up @@ -205,8 +208,6 @@ WebSubHub.prototype._verifyIntent = async function(
let response
try {
response = await this.httpClient.get(callbackUrl, {
timeout: this.options.timeout,
retries: this.options.retries,
json: true,
query: {
...callbackQuery,
Expand Down Expand Up @@ -266,16 +267,14 @@ WebSubHub.prototype._distributeContentHTTP = async function(
}

WebSubHub.prototype._sendContentHTTP = async function(sub, stream, headers) {
const output = stream.pipe(
this.httpClient.stream.post(sub.callbackUrl, {
try {
const response = this.httpClient.stream.post(sub.callbackUrl, {
query: sub.callbackQuery,
retries: this.options.retries,
headers,
timeout: this.options.timeout
headers
})
)

try {
const output = stream.pipe(response)

await PEvent(output, 'response')
} catch (err) {
this.log.error(
Expand Down Expand Up @@ -386,14 +385,9 @@ WebSubHub.prototype._fetchTopicContent = async function(sub, stream = false) {
try {
response = await this.httpClient.get(sub.topic, {
stream,
retries: this.options.retries,
headers,
timeout: this.options.timeout
throwHttpErrors: false
})

if (stream) {
await PEvent(response, 'response')
}
} catch (err) {
this.log.error(err, `from topic '%s' could not be fetched`, sub.topic)
throw Boom.notFound('from topic could not be fetched')
Expand Down
6 changes: 3 additions & 3 deletions packages/websub-hub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
],
"dependencies": {
"boom": "^7.2.0",
"fastify": "1.8.0",
"fastify": "1.9.0",
"fastify-boom": "^0.1.0",
"fastify-formbody": "^2.0.0",
"fastify-formbody": "^2.0.1",
"fastify-mongodb": "0.8.2",
"fastify-plugin": "^1.2.0",
"got": "^8.3.2",
"got": "^9.0.0",
"hoek": "^5.0.3",
"hyperid": "^1.4.1",
"jsonwebtoken": "^8.3.0",
Expand Down
3 changes: 2 additions & 1 deletion test/subscription.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('Basic Subscription', function() {
before(function() {
hub = Hub({
logLevel: 'debug',
timeout: 500,
mongo: {
url: mongoInMemory.getMongouri('hub')
}
Expand Down Expand Up @@ -95,7 +96,7 @@ describe('Basic Subscription', function() {
verifyIntentMock.done()
})

it.skip('Should retry when subscription callback respond with e.g statusCode 502', async function() {
it('Should retry when subscription callback respond with e.g statusCode 502', async function() {
const callbackUrl = 'http://127.0.0.1:3001'
const createSubscriptionBody = {
'hub.callback': callbackUrl,
Expand Down

0 comments on commit 3c1ab0a

Please sign in to comment.