Skip to content

Commit

Permalink
Explicitly allow "undefined" values in headers (#3456)
Browse files Browse the repository at this point in the history
* Explicitly allow "undefined" values in `headers`

* fix tests types
  • Loading branch information
matthieusieben authored Jan 26, 2025
1 parent 8810885 commit fb64d50
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-laws-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/xrpc": patch
---

Explicitly allow "undefined" values in `headers`
7 changes: 4 additions & 3 deletions packages/bsky/src/api/app/bsky/actor/getSuggestions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { mapDefined, noUndefinedVals } from '@atproto/common'
import { AtpAgent } from '@atproto/api'
import { HeadersMap } from '@atproto/xrpc'
import AppContext from '../../../../context'
import { Server } from '../../../../lexicon'
import { QueryParams } from '../../../../lexicon/types/app/bsky/actor/getSuggestions'
Expand All @@ -12,7 +14,6 @@ import { Views } from '../../../../views'
import { DataPlaneClient } from '../../../../data-plane'
import { parseString } from '../../../../hydration/util'
import { resHeaders } from '../../../util'
import { AtpAgent } from '@atproto/api'

export default function (server: Server, ctx: AppContext) {
const getSuggestions = createPipeline(
Expand Down Expand Up @@ -144,12 +145,12 @@ type Context = {

type Params = QueryParams & {
hydrateCtx: HydrateCtx
headers: Record<string, string>
headers: HeadersMap
}

type Skeleton = {
dids: string[]
cursor?: string
recId?: number
resHeaders?: Record<string, string>
resHeaders?: HeadersMap
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { mapDefined, noUndefinedVals } from '@atproto/common'
import { InvalidRequestError } from '@atproto/xrpc-server'
import AtpAgent from '@atproto/api'
import { HeadersMap } from '@atproto/xrpc'
import { Server } from '../../../../lexicon'
import { QueryParams } from '../../../../lexicon/types/app/bsky/graph/getSuggestedFollowsByActor'
import AppContext from '../../../../context'
Expand Down Expand Up @@ -133,12 +134,12 @@ type Context = {

type Params = QueryParams & {
hydrateCtx: HydrateCtx & { viewer: string }
headers: Record<string, string>
headers: HeadersMap
}

type SkeletonState = {
isFallback: boolean
suggestedDids: string[]
recId?: number
headers?: Record<string, string>
headers?: HeadersMap
}
7 changes: 5 additions & 2 deletions packages/bsky/tests/label-hydration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ describe('label hydration', () => {
expect(res.data.labels?.find((l) => l.src === labelerDid)?.val).toEqual(
'misleading',
)
const labelerHeaderDids = res.headers['atproto-content-labelers'].split(',')
expect(labelerHeaderDids.sort()).toEqual(
const labelerHeaderDids = res.headers['atproto-content-labelers']
?.split(',')
.sort()

expect(labelerHeaderDids).toEqual(
[alice, `${bob};redact`, labelerDid].sort(),
)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/pds/tests/proxied/read-after-write.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ describe('proxy read after write', () => {
{ headers: { ...sc.getHeaders(alice) } },
)
const lag = res.headers['atproto-upstream-lag']
expect(lag).toBeDefined()
assert(lag !== undefined)
const parsed = parseInt(lag)
expect(parsed > 0).toBe(true)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/xrpc/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { z } from 'zod'
import { ValidationError } from '@atproto/lexicon'

export type QueryParams = Record<string, any>
export type HeadersMap = Record<string, string>
export type HeadersMap = Record<string, string | undefined>

export type {
/** @deprecated not to be confused with the WHATWG Headers constructor */
Expand Down

0 comments on commit fb64d50

Please sign in to comment.