Skip to content
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

fix headers no longer readonly #3295

Merged
merged 2 commits into from Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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