Skip to content

Commit

Permalink
fix: remove http version check (#4962)
Browse files Browse the repository at this point in the history
* make FastifySchemaValidationError.params wider (#4476)

* fix: FastifySchemaValidationError.params could be unknown

* refactor: use FastifySchemaValidationError instead of ValidationResult

* fix: export ValidationResult for backword compatibility

* test: add non-assignable test for AjvErrorObject

* docs(ecosystem): add fastify-hashids (#4934)

* fix: hasPlugin does not track parent plugins (#4929)

Co-authored-by: Carlos Fuentes <me@metcoder.dev>

* docs: early hints plugin is fastify plugin (#4947)

* docs: early hints plugin is fastify plugin

* fix

* Update docs/Guides/Ecosystem.md

Co-authored-by: Frazer Smith <frazer.dev@outlook.com>

---------

Co-authored-by: Frazer Smith <frazer.dev@outlook.com>

* chore: add pull request title check (#4951)

* chore: add pull request title check

* Update .github/workflows/pull-request-title.yml

Co-authored-by: Frazer Smith <frazer.dev@outlook.com>

---------

Co-authored-by: Frazer Smith <frazer.dev@outlook.com>

* chore: Bump @sinclair/typebox from 0.29.6 to 0.30.2 (#4952)

Bumps [@sinclair/typebox](https://github.com/sinclairzx81/typebox) from 0.29.6 to 0.30.2.
- [Commits](sinclairzx81/typebox@0.29.6...0.30.2)

---
updated-dependencies:
- dependency-name: "@sinclair/typebox"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* ci: prove pr title check (#4953)

* improve pr title check

* Apply suggestions from code review

* fix

* fix

* Update .github/workflows/pull-request-title.yml

Co-authored-by: Luis Orbaiceta <luisorbaiceta@gmail.com>

* Apply suggestions from code review

---------

Co-authored-by: Luis Orbaiceta <luisorbaiceta@gmail.com>

* ci: fix warnings in benchmark workflows (#4954)

* improve pr title check

* Apply suggestions from code review

* fix

* fix

* ci: fix warnings in benchmark workflow

* Update .github/workflows/benchmark.yml

* Update .github/workflows/benchmark.yml

* docs: fix removeAdditional comment (#4948)

* docs(Validator Compiler): fix removeAdditional comment

* Update docs/Reference/Validation-and-Serialization.md

Co-authored-by: Uzlopak <aras.abbasi@googlemail.com>

* fix: typo in comment

* Update docs/Reference/Validation-and-Serialization.md

Co-authored-by: Frazer Smith <frazer.dev@outlook.com>

---------

Co-authored-by: Uzlopak <aras.abbasi@googlemail.com>
Co-authored-by: Frazer Smith <frazer.dev@outlook.com>

* fix: Try to fix parser benchmark workflow (#4956)

* fix: infer correct hook handler (#4945)

* fix: infer correct hook handler

* Update test/types/hooks.test-d.ts

* simplify

* remove duplicate typing tests

* remove duplicate test

* remove unused import

* fix

* fix linting

* fix: remove http version check

* test: remove unsupported http version

* remove obsolete documentation

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: cm-ayf <cm.ayf2734@gmail.com>
Co-authored-by: Anderson <andersonjoseph@mailfence.com>
Co-authored-by: Manuel Spigolon <behemoth89@gmail.com>
Co-authored-by: Carlos Fuentes <me@metcoder.dev>
Co-authored-by: Uzlopak <aras.abbasi@googlemail.com>
Co-authored-by: Frazer Smith <frazer.dev@outlook.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Luis Orbaiceta <luisorbaiceta@gmail.com>
Co-authored-by: Mohammed Gomaa <midomaxgomaa@gmail.com>
Co-authored-by: Igor Savin <iselwin@gmail.com>
Co-authored-by: Cem <cembkoztekin@gmail.com>
  • Loading branch information
12 people committed Aug 29, 2023
1 parent bdf4b54 commit dbac4e0
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 121 deletions.
22 changes: 0 additions & 22 deletions docs/Reference/Routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -826,25 +826,3 @@ const secret = {
> }
> })
> ```

### ⚠ HTTP version check

Fastify will check the HTTP version of every request, based on configuration
options ([http2](./Server.md#http2), [https](./Server.md#https), and
[serverFactory](./Server.md#serverfactory)), to determine if it matches one or
all of the > following versions: `2.0`, `1.1`, and `1.0`. If Fastify receives a
different HTTP version in the request it will return a `505 HTTP Version Not
Supported` error.

| | 2.0 | 1.1 | 1.0 | skip |
|:------------------------:|:---:|:---:|:---:|:----:|
| http2 || | | |
| http2 + https || | | |
| http2 + https.allowHTTP1 |||| |
| https | ||| |
| http | ||| |
| serverFactory | | | ||

Note: The internal HTTP version check will be removed in the future when Node
implements [this feature](https://github.com/nodejs/node/issues/43115).
3 changes: 1 addition & 2 deletions fastify.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const {
kChildLoggerFactory
} = require('./lib/symbols.js')

const { createServer, compileValidateHTTPVersion } = require('./lib/server')
const { createServer } = require('./lib/server')
const Reply = require('./lib/reply')
const Request = require('./lib/request')
const Context = require('./lib/context.js')
Expand Down Expand Up @@ -513,7 +513,6 @@ function fastify (options) {
hasLogger,
setupResponseListeners,
throwIfAlreadyStarted,
validateHTTPVersion: compileValidateHTTPVersion(options),
keepAliveConnections
})

Expand Down
15 changes: 0 additions & 15 deletions lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ function buildRouting (options) {
let ignoreDuplicateSlashes
let return503OnClosing
let globalExposeHeadRoutes
let validateHTTPVersion
let keepAliveConnections

let closing = false
Expand All @@ -83,7 +82,6 @@ function buildRouting (options) {
hasLogger = fastifyArgs.hasLogger
setupResponseListeners = fastifyArgs.setupResponseListeners
throwIfAlreadyStarted = fastifyArgs.throwIfAlreadyStarted
validateHTTPVersion = fastifyArgs.validateHTTPVersion

globalExposeHeadRoutes = options.exposeHeadRoutes
genReqId = options.genReqId
Expand Down Expand Up @@ -402,19 +400,6 @@ function buildRouting (options) {
const childLogger = createChildLogger(context, logger, req, id, loggerOpts)
childLogger[kDisableRequestLogging] = disableRequestLogging

// TODO: The check here should be removed once https://github.com/nodejs/node/issues/43115 resolve in core.
if (!validateHTTPVersion(req.httpVersion)) {
childLogger.info({ res: { statusCode: 505 } }, 'request aborted - invalid HTTP version')
const message = '{"error":"HTTP Version Not Supported","message":"HTTP Version Not Supported","statusCode":505}'
const headers = {
'Content-Type': 'application/json',
'Content-Length': message.length
}
res.writeHead(505, headers)
res.end(message)
return
}

if (closing === true) {
/* istanbul ignore next mac, windows */
if (req.httpVersionMajor !== 2) {
Expand Down
51 changes: 0 additions & 51 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const {
} = require('./errors')

module.exports.createServer = createServer
module.exports.compileValidateHTTPVersion = compileValidateHTTPVersion

function defaultResolveServerListeningText (address) {
return `Server listening at ${address}`
Expand Down Expand Up @@ -252,56 +251,6 @@ function listenPromise (server, listenOptions) {
})
}

/**
* Creates a function that, based upon initial configuration, will
* verify that every incoming request conforms to allowed
* HTTP versions for the Fastify instance, e.g. a Fastify HTTP/1.1
* server will not serve HTTP/2 requests upon the result of the
* verification function.
*
* @param {object} options fastify option
* @param {function} [options.serverFactory] If present, the
* validator function will skip all checks.
* @param {boolean} [options.http2 = false] If true, the validator
* function will allow HTTP/2 requests.
* @param {object} [options.https = null] https server options
* @param {boolean} [options.https.allowHTTP1] If true and use
* with options.http2 the validator function will allow HTTP/1
* request to http2 server.
*
* @returns {function} HTTP version validator function.
*/
function compileValidateHTTPVersion (options) {
let bypass = false
// key-value map to store valid http version
const map = new Map()
if (options.serverFactory) {
// When serverFactory is passed, we cannot identify how to check http version reliably
// So, we should skip the http version check
bypass = true
}
if (options.http2) {
// HTTP2 must serve HTTP/2.0
map.set('2.0', true)
if (options.https && options.https.allowHTTP1 === true) {
// HTTP2 with HTTPS.allowHTTP1 allow fallback to HTTP/1.1 and HTTP/1.0
map.set('1.1', true)
map.set('1.0', true)
}
} else {
// HTTP must server HTTP/1.1 and HTTP/1.0
map.set('1.1', true)
map.set('1.0', true)
}
// The compiled function here placed in one of the hottest path inside fastify
// the implementation here must be as performant as possible
return function validateHTTPVersion (httpVersion) {
// `bypass` skip the check when custom server factory provided
// `httpVersion in obj` check for the valid http version we should support
return bypass || map.has(httpVersion)
}
}

function getServerInstance (options, httpHandler) {
let server = null
// node@20 do not accepts options as boolean
Expand Down
31 changes: 0 additions & 31 deletions test/unsupported-httpversion.test.js

This file was deleted.

0 comments on commit dbac4e0

Please sign in to comment.