Skip to content

Commit

Permalink
feat: use blockstore sessions (#157)
Browse files Browse the repository at this point in the history
Adds a `USE_SESSIONS` env var that controls whether to use blockstore
sessions or not.

The `session` option will be passed to `@helia/verified-fetch`
accordingly.
  • Loading branch information
achingbrain authored Jul 9, 2024
1 parent 11c87ad commit 5976f65
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ $ npm start
| `USE_DELEGATED_ROUTING` | Whether to use the delegated routing v1 API | `true` |
| `DELEGATED_ROUTING_V1_HOST` | Hostname to use for delegated routing v1 | `https://delegated-ipfs.dev` |
| `USE_DHT_ROUTING` | Whether to use @libp2p/kad-dht for routing when libp2p is enabled | `true` |
| `USE_SESSIONS` | If true, use a blockstore session per IPFS/IPNS path | `true` |

<!--
TODO: currently broken when used in docker, but they work when running locally (you can cache datastore and blockstore locally to speed things up if you want)
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const FASTIFY_DEBUG = process.env.FASTIFY_DEBUG ?? ''

export const USE_SUBDOMAINS = process.env.USE_SUBDOMAINS !== 'false'

export const USE_SESSIONS = process.env.USE_SESSIONS !== 'false'

export const ECHO_HEADERS = process.env.ECHO_HEADERS === 'true'

/**
Expand Down
8 changes: 6 additions & 2 deletions src/helia-http-gateway.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { raceSignal } from 'race-signal'
import { USE_SUBDOMAINS } from './constants.js'
import { USE_SUBDOMAINS, USE_SESSIONS } from './constants.js'
import { dnsLinkLabelEncoder, isInlinedDnsLink } from './dns-link-labels.js'
import { getFullUrlFromFastifyRequest, getRequestAwareSignal } from './helia-server.js'
import { getIpnsAddressDetails } from './ipns-address-utils.js'
Expand Down Expand Up @@ -89,7 +89,11 @@ export function httpGateway (opts: HeliaHTTPGatewayOptions): RouteOptions[] {

// if subdomains are disabled, have @helia/verified-fetch follow redirects
// internally, otherwise let the client making the request do it
const resp = await opts.fetch(url, { signal, redirect: USE_SUBDOMAINS ? 'manual' : 'follow' })
const resp = await opts.fetch(url, {
signal,
redirect: USE_SUBDOMAINS ? 'manual' : 'follow',
session: USE_SESSIONS
})

await convertVerifiedFetchResponseToFastifyReply(url, resp, reply, {
signal
Expand Down

0 comments on commit 5976f65

Please sign in to comment.