Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

fix: make http api only accept POST requests #2977

Merged
merged 5 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/ipfs-http-client/src/lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { URL } = require('iso-url')
const parseDuration = require('parse-duration')
const log = require('debug')('ipfs-http-client:lib:error-handler')
const HTTP = require('ipfs-utils/src/http')
const merge = require('merge-options')

const isMultiaddr = (input) => {
try {
Expand Down Expand Up @@ -126,6 +127,19 @@ class Client extends HTTP {
return out
}
})

delete this.get
delete this.put
delete this.delete
delete this.options

const fetch = this.fetch

this.fetch = (resource, options = {}) => {
return fetch.call(this, resource, merge(options, {
method: 'POST'
}))
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/ipfs/src/http/api/routes/bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ const resources = require('../resources')

module.exports = [
{
method: '*',
method: 'POST',
path: '/api/v0/bitswap/wantlist',
options: {
validate: resources.bitswap.wantlist.validate
},
handler: resources.bitswap.wantlist.handler
},
{
method: '*',
method: 'POST',
path: '/api/v0/bitswap/stat',
options: {
validate: resources.bitswap.stat.validate
},
handler: resources.bitswap.stat.handler
},
{
method: '*',
method: 'POST',
path: '/api/v0/bitswap/unwant',
options: {
pre: [
Expand Down
8 changes: 4 additions & 4 deletions packages/ipfs/src/http/api/routes/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const resources = require('../resources')

module.exports = [
{
method: '*',
method: 'POST',
path: '/api/v0/block/get',
options: {
pre: [
Expand All @@ -14,7 +14,7 @@ module.exports = [
handler: resources.block.get.handler
},
{
method: '*',
method: 'POST',
path: '/api/v0/block/put',
options: {
payload: {
Expand All @@ -29,7 +29,7 @@ module.exports = [
handler: resources.block.put.handler
},
{
method: '*',
method: 'POST',
path: '/api/v0/block/rm',
options: {
pre: [
Expand All @@ -40,7 +40,7 @@ module.exports = [
handler: resources.block.rm.handler
},
{
method: '*',
method: 'POST',
path: '/api/v0/block/stat',
config: {
pre: [
Expand Down
12 changes: 6 additions & 6 deletions packages/ipfs/src/http/api/routes/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ const resources = require('../resources')

module.exports = [
{
method: '*',
method: 'POST',
path: '/api/v0/bootstrap',
handler: resources.bootstrap.list
},
{
method: '*',
method: 'POST',
path: '/api/v0/bootstrap/add',
options: {
pre: [
Expand All @@ -19,17 +19,17 @@ module.exports = [
handler: resources.bootstrap.add.handler
},
{
method: '*',
method: 'POST',
path: '/api/v0/bootstrap/add/default',
handler: resources.bootstrap.addDefault
},
{
method: '*',
method: 'POST',
path: '/api/v0/bootstrap/list',
handler: resources.bootstrap.list
},
{
method: '*',
method: 'POST',
path: '/api/v0/bootstrap/rm',
options: {
pre: [
Expand All @@ -39,7 +39,7 @@ module.exports = [
handler: resources.bootstrap.rm.handler
},
{
method: '*',
method: 'POST',
path: '/api/v0/bootstrap/rm/all',
handler: resources.bootstrap.rmAll
}
Expand Down
10 changes: 5 additions & 5 deletions packages/ipfs/src/http/api/routes/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const resources = require('../resources')

module.exports = [
{
method: '*',
method: 'POST',
path: '/api/v0/config/{key?}',
options: {
pre: [
Expand All @@ -14,12 +14,12 @@ module.exports = [
handler: resources.config.getOrSet.handler
},
{
method: '*',
method: 'POST',
path: '/api/v0/config/show',
handler: resources.config.show
},
{
method: '*',
method: 'POST',
path: '/api/v0/config/replace',
options: {
payload: {
Expand All @@ -33,7 +33,7 @@ module.exports = [
handler: resources.config.replace.handler
},
{
method: '*',
method: 'POST',
path: '/api/v0/config/profile/apply',
options: {
pre: [
Expand All @@ -44,7 +44,7 @@ module.exports = [
handler: resources.config.profiles.apply.handler
},
{
method: '*',
method: 'POST',
path: '/api/v0/config/profile/list',
handler: resources.config.profiles.list.handler
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs/src/http/api/routes/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const gauge = new client.Gauge({ name: 'number_of_peers', help: 'the_number_of_c

// Endpoint for handling debug metrics
module.exports = {
method: 'GET',
method: 'POST',
path: '/debug/metrics/prometheus',
async handler (request, h) {
if (!process.env.IPFS_MONITORING) {
Expand Down
12 changes: 6 additions & 6 deletions packages/ipfs/src/http/api/routes/dht.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@ const resources = require('../resources')

module.exports = [
{
method: '*',
method: 'POST',
path: '/api/v0/dht/findpeer',
options: {
validate: resources.dht.findPeer.validate
},
handler: resources.dht.findPeer.handler
},
{
method: '*',
method: 'POST',
path: '/api/v0/dht/findprovs',
options: {
validate: resources.dht.findProvs.validate
},
handler: resources.dht.findProvs.handler
},
{
method: '*',
method: 'POST',
path: '/api/v0/dht/get',
options: {
validate: resources.dht.get.validate
},
handler: resources.dht.get.handler
},
{
method: '*',
method: 'POST',
path: '/api/v0/dht/provide',
options: {
validate: resources.dht.provide.validate
},
handler: resources.dht.provide.handler
},
{
method: '*',
method: 'POST',
path: '/api/v0/dht/put',
options: {
pre: [
Expand All @@ -47,7 +47,7 @@ module.exports = [
handler: resources.dht.put.handler
},
{
method: '*',
method: 'POST',
path: '/api/v0/dht/query',
options: {
validate: resources.dht.query.validate
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs/src/http/api/routes/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const resources = require('../resources')

module.exports = {
method: '*',
method: 'POST',
path: '/api/v0/dns',
handler: resources.dns
}
18 changes: 6 additions & 12 deletions packages/ipfs/src/http/api/routes/files-regular.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ const resources = require('../resources')

module.exports = [
{
// TODO fix method
method: '*',
method: 'POST',
path: '/api/v0/cat',
options: {
pre: [
Expand All @@ -15,8 +14,7 @@ module.exports = [
handler: resources.filesRegular.cat.handler
},
{
// TODO fix method
method: '*',
method: 'POST',
path: '/api/v0/get',
options: {
pre: [
Expand All @@ -26,8 +24,7 @@ module.exports = [
handler: resources.filesRegular.get.handler
},
{
// TODO fix method
method: '*',
method: 'POST',
path: '/api/v0/add',
options: {
payload: {
Expand All @@ -40,8 +37,7 @@ module.exports = [
handler: resources.filesRegular.add.handler
},
{
// TODO fix method
method: '*',
method: 'POST',
path: '/api/v0/ls',
options: {
pre: [
Expand All @@ -51,8 +47,7 @@ module.exports = [
handler: resources.filesRegular.ls.handler
},
{
// TODO fix method
method: '*',
method: 'POST',
path: '/api/v0/refs',
options: {
pre: [
Expand All @@ -63,8 +58,7 @@ module.exports = [
handler: resources.filesRegular.refs.handler
},
{
// TODO fix method
method: '*',
method: 'POST',
path: '/api/v0/refs/local',
handler: resources.filesRegular.refs.local.handler
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs/src/http/api/routes/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const resources = require('../resources')

module.exports = {
method: '*',
method: 'POST',
path: '/api/v0/id',
handler: resources.id.get
}
12 changes: 6 additions & 6 deletions packages/ipfs/src/http/api/routes/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@ const resources = require('../resources')

module.exports = [
{
method: '*',
method: 'POST',
path: '/api/v0/key/list',
handler: resources.key.list
},
{
method: '*',
method: 'POST',
path: '/api/v0/key/gen',
handler: resources.key.gen
},
{
method: '*',
method: 'POST',
path: '/api/v0/key/rm',
handler: resources.key.rm
},
{
method: '*',
method: 'POST',
path: '/api/v0/key/rename',
handler: resources.key.rename
},
{
method: '*',
method: 'POST',
path: '/api/v0/key/export',
handler: resources.key.export
},
{
method: '*',
method: 'POST',
path: '/api/v0/key/import',
handler: resources.key.import
}
Expand Down
10 changes: 5 additions & 5 deletions packages/ipfs/src/http/api/routes/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ const resources = require('../resources')

module.exports = [
{
method: '*',
method: 'POST',
path: '/api/v0/name/resolve',
options: {
validate: resources.name.resolve.validate
},
handler: resources.name.resolve.handler
},
{
method: '*',
method: 'POST',
path: '/api/v0/name/publish',
options: {
validate: resources.name.publish.validate
},
handler: resources.name.publish.handler
},
{
method: '*',
method: 'POST',
path: '/api/v0/name/pubsub/state',
handler: resources.name.pubsub.state.handler
},
{
method: '*',
method: 'POST',
path: '/api/v0/name/pubsub/subs',
handler: resources.name.pubsub.subs.handler
},
{
method: '*',
method: 'POST',
path: '/api/v0/name/pubsub/cancel',
options: {
validate: resources.name.pubsub.cancel.validate
Expand Down
Loading