-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add content-type interceptor #226
base: main
Are you sure you want to change the base?
add content-type interceptor #226
Conversation
import { Observable } from 'rxjs'; | ||
|
||
@Injectable() | ||
export class ContentTypeInterceptor implements NestInterceptor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A more appropriate name would be JsonContentTypeInterceptor since it handles only the JSON content type.
export class ContentTypeInterceptor implements NestInterceptor { | ||
intercept(context: ExecutionContext, next: CallHandler): Observable<any> { | ||
const request = context.switchToHttp().getRequest(); | ||
if (request.method === 'POST' && request.headers['content-type'] !== 'application/json') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it should also be applicable for PUT/PATCH requests
For POST requests, check if content-type has value application/json
If not, return 400 Bad Request with a proper message