Skip to content

Commit

Permalink
fix headers no longer readonly (#3295)
Browse files Browse the repository at this point in the history
* fix headers no longer readonly

* test that headers can be set
  • Loading branch information
jonnyynnoj committed Sep 6, 2021
1 parent 33290ee commit c92c822
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion test/types/request.test-d.ts
@@ -1,6 +1,6 @@
import { expectType } from 'tsd'
import fastify, { RouteHandler, RawRequestDefaultExpression, RequestBodyDefault, RequestGenericInterface } from '../../fastify'
import { RawServerDefault, RequestParamsDefault, RequestHeadersDefault, RequestQuerystringDefault, RawReplyDefaultExpression } from '../../types/utils'
import { RequestParamsDefault, RequestHeadersDefault, RequestQuerystringDefault } from '../../types/utils'
import { FastifyLoggerInstance } from '../../types/logger'
import { FastifyRequest } from '../../types/request'
import { FastifyReply } from '../../types/reply'
Expand Down Expand Up @@ -50,7 +50,10 @@ const getHandler: RouteHandler = function (request, _reply) {
expectType<RawRequestDefaultExpression>(request.raw)
expectType<RequestBodyDefault>(request.body)
expectType<RequestParamsDefault>(request.params)

expectType<RequestHeadersDefault & RawRequestDefaultExpression['headers']>(request.headers)
request.headers = {}

expectType<RequestQuerystringDefault>(request.query)
expectType<any>(request.id)
expectType<FastifyLoggerInstance>(request.log)
Expand Down
2 changes: 1 addition & 1 deletion types/request.d.ts
Expand Up @@ -23,6 +23,7 @@ export interface FastifyRequest<
params: RouteGeneric['Params'];
raw: RawRequest;
query: RouteGeneric['Querystring'];
headers: RawRequest['headers'] & RouteGeneric['Headers']; // this enables the developer to extend the existing http(s|2) headers list
log: FastifyLoggerInstance;
server: FastifyInstance;
body: RouteGeneric['Body'];
Expand All @@ -34,7 +35,6 @@ export interface FastifyRequest<
* @deprecated Use `raw` property
*/
readonly req: RawRequest;
readonly headers: RawRequest['headers'] & RouteGeneric['Headers']; // this enables the developer to extend the existing http(s|2) headers list
readonly ip: string;
readonly ips?: string[];
readonly hostname: string;
Expand Down

0 comments on commit c92c822

Please sign in to comment.