Skip to content

Commit

Permalink
Appview: add user-agent for feeds and resolving blobs (#3450)
Browse files Browse the repository at this point in the history
appview: add user-agent for feeds and resolving blobs
  • Loading branch information
devinivy authored Jan 24, 2025
1 parent e5d4c74 commit 8c777f0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/bsky/src/api/app/bsky/feed/getFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
isDataplaneError,
unpackIdentityServices,
} from '../../../../data-plane'
import { resHeaders } from '../../../util'
import { BSKY_USER_AGENT, resHeaders } from '../../../util'
import { ids } from '../../../../lexicon/lexicons'

export default function (server: Server, ctx: AppContext) {
Expand All @@ -55,6 +55,7 @@ export default function (server: Server, ctx: AppContext) {
const labelers = ctx.reqLabelers(req)
const hydrateCtx = await ctx.hydrator.createContext({ labelers, viewer })
const headers = noUndefinedVals({
'user-agent': BSKY_USER_AGENT,
authorization: req.headers['authorization'],
'accept-language': req.headers['accept-language'],
'x-bsky-topics': Array.isArray(req.headers['x-bsky-topics'])
Expand Down
3 changes: 3 additions & 0 deletions packages/bsky/src/api/blob-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
import { parseCid } from '../hydration/util'
import { httpLogger as log } from '../logger'
import { Middleware, proxyResponseHeaders, responseSignal } from '../util/http'
import { BSKY_USER_AGENT } from './util'

export function createMiddleware(ctx: AppContext): Middleware {
return async (req, res, next) => {
Expand Down Expand Up @@ -298,6 +299,8 @@ function getBlobHeaders(
): Map<string, string> {
const headers = new Map<string, string>()

headers.set('user-agent', BSKY_USER_AGENT)

if (bypassKey && bypassHostname) {
const matchesUrl = bypassHostname.startsWith('.')
? url.hostname.endsWith(bypassHostname)
Expand Down
1 change: 1 addition & 0 deletions packages/bsky/src/api/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ParsedLabelers, formatLabelerHeader } from '../util'

export const BSKY_USER_AGENT = 'BskyAppView'
export const ATPROTO_CONTENT_LABELERS = 'Atproto-Content-Labelers'
export const ATPROTO_REPO_REV = 'Atproto-Repo-Rev'

Expand Down

0 comments on commit 8c777f0

Please sign in to comment.