Skip to content

Commit

Permalink
fix: re use received headers
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Jun 2, 2022
1 parent 499bedf commit e1ea575
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/api/package.json
Expand Up @@ -23,7 +23,6 @@
},
"dependencies": {
"@supabase/postgrest-js": "^0.37.2",
"edge-gateway": "^1.5.5",
"itty-router": "^2.4.5",
"multiformats": "^9.6.4",
"nanoid": "^3.1.30",
Expand All @@ -35,6 +34,7 @@
"ava": "^3.15.0",
"browser-env": "^3.3.0",
"dotenv": "^16.0.0",
"edge-gateway": "^1.5.5",
"esbuild": "^0.14.2",
"execa": "^5.1.1",
"git-rev-sync": "^3.0.1",
Expand Down
7 changes: 0 additions & 7 deletions packages/api/src/env.js
Expand Up @@ -57,13 +57,6 @@ export function envAll(request, env, ctx) {

env.log = new Logging(request, env, ctx)
env.log.time('request')

/**
* Add gateway environment
* will be removed once workers bindings are in place.
*/
// @ts-ignore types not complete - Special inputs for Env
env.ipfsGateways = JSON.parse(env.IPFS_GATEWAYS)
}

/**
Expand Down
32 changes: 21 additions & 11 deletions packages/api/src/perma-cache/post.js
Expand Up @@ -212,19 +212,29 @@ function validateCacheControlHeader(cacheControl) {
* @param {Request} request
*/
function getHeaders(request) {
const existingProxies = request.headers.get('X-Forwarded-For')
? `, ${request.headers.get('X-Forwarded-For')}`
const headers = cloneHeaders(request.headers)
const existingProxies = headers.get('X-Forwarded-For')
? `, ${headers.get('X-Forwarded-For')}`
: ''

// TODO: keep headers
// request.headers.set('X-Forwarded-For', `${request.headers.get(
// 'cf-connecting-ip'
// )}${existingProxies}`)
// keep headers
headers.set(
'X-Forwarded-For',
`${headers.get('cf-connecting-ip')}${existingProxies}`
)

// return request.headers
return {
'X-Forwarded-For': `${request.headers.get(
'cf-connecting-ip'
)}${existingProxies}`,
return headers
}

/**
* Clone headers to mutate them.
*
* @param {Headers} reqHeaders
*/
function cloneHeaders(reqHeaders) {
const headers = new Headers()
for (var kv of reqHeaders.entries()) {
headers.append(kv[0], kv[1])
}
return headers
}
3 changes: 0 additions & 3 deletions packages/api/wrangler.toml
Expand Up @@ -21,7 +21,6 @@ NFT_STORAGE_API = "https://api.nft.storage"
DEBUG = "false"
ENV = "production"
GATEWAY_DOMAIN = "nftstorage.link"
IPFS_GATEWAYS = "[\"https://ipfs.io\", \"https://cf.nftstorage.link\", \"https://nft-storage.mypinata.cloud/\"]"

[[env.production.r2_buckets]]
bucket_name = "super-hot"
Expand All @@ -48,7 +47,6 @@ NFT_STORAGE_API = "https://api-staging.nft.storage"
DEBUG = "true"
ENV = "staging"
GATEWAY_DOMAIN = "nftstorage.link"
IPFS_GATEWAYS = "[\"https://ipfs.io\", \"https://cf.nftstorage.link\", \"https://nft-storage.mypinata.cloud/\"]"

[[env.staging.r2_buckets]]
bucket_name = "super-hot-staging"
Expand All @@ -68,7 +66,6 @@ workers_dev = true
DEBUG = "true"
ENV = "test"
GATEWAY_DOMAIN = "localhost:9081"
IPFS_GATEWAYS = "[\"http://127.0.0.1:9081\"]"

# Dev!
[env.vsantos]
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e1ea575

Please sign in to comment.