Skip to content

Commit

Permalink
fix: return HTTP 415 if unsupported content type (#1313)
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <timo@animo.id>
  • Loading branch information
TimoGlastra authored Mar 11, 2023
1 parent 582c711 commit 122cdde
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/node/src/transport/HttpInboundTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type { Server } from 'http'
import { DidCommMimeType, AriesFrameworkError, TransportService, utils, MessageReceiver } from '@aries-framework/core'
import express, { text } from 'express'

const supportedContentTypes: string[] = [DidCommMimeType.V0, DidCommMimeType.V1]

export class HttpInboundTransport implements InboundTransport {
public readonly app: Express
private port: number
Expand All @@ -22,12 +24,19 @@ export class HttpInboundTransport implements InboundTransport {
this.app = app ?? express()
this.path = path ?? '/'

this.app.use(
text({
type: [DidCommMimeType.V0, DidCommMimeType.V1],
limit: '5mb',
})
)
this.app.use((req, res, next) => {
const contentType = req.headers['content-type']

if (!contentType || !supportedContentTypes.includes(contentType)) {
return res
.status(415)
.send('Unsupported content-type. Supported content-types are: ' + supportedContentTypes.join(', '))
}

return next()
})

this.app.use(text({ type: supportedContentTypes, limit: '5mb' }))
}

public async start(agent: Agent) {
Expand Down

0 comments on commit 122cdde

Please sign in to comment.