@adonisjs/http-server 5.5.7 → 5.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -534,7 +534,7 @@ declare module '@ioc:Adonis/Core/Request' {
534
534
  * Shape of the request config
535
535
  */
536
536
  export type RequestConfig = {
537
- forceContentNegotiationTo?: string;
537
+ forceContentNegotiationTo?: string | ((ctx: HttpContextContract) => string);
538
538
  subdomainOffset: number;
539
539
  generateRequestId: boolean;
540
540
  allowMethodSpoofing: boolean;
@@ -153,16 +153,17 @@ class Server {
153
153
  * server
154
154
  */
155
155
  async handle(req, res) {
156
- /*
157
- * Reset accept header when `forceContentNegotiationToJSON = true`
158
- */
159
- if (this.httpConfig.forceContentNegotiationTo) {
160
- req.headers['accept'] = this.httpConfig.forceContentNegotiationTo;
161
- }
162
156
  const request = new Request_1.Request(req, res, this.encryption, this.httpConfig);
163
157
  const response = new Response_1.Response(req, res, this.encryption, this.httpConfig, this.router);
164
158
  const requestAction = this.getProfilerRow(request);
165
159
  const ctx = this.getContext(request, response, requestAction);
160
+ /*
161
+ * Reset accept header when `forceContentNegotiationTo` is defined
162
+ */
163
+ const accept = this.httpConfig.forceContentNegotiationTo;
164
+ if (accept) {
165
+ req.headers['accept'] = typeof accept === 'function' ? accept(ctx) : accept;
166
+ }
166
167
  if (LocalStorage_1.usingAsyncLocalStorage) {
167
168
  return LocalStorage_1.httpContextLocalStorage.run(ctx, () => this.handleRequest(ctx, requestAction, res));
168
169
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonisjs/http-server",
3
- "version": "5.5.7",
3
+ "version": "5.6.0",
4
4
  "description": "AdonisJS HTTP server with support packed with Routing and Cookies",
5
5
  "main": "build/providers/HttpServerProvider.js",
6
6
  "files": [