Comments (29)
I think we can close this :).
from fastify.
I think we should support 'TRACE' and 'CONNECT' as methods but not add any route, possibly creating a plugin that is spec compliant instead. I see most of our users not needing those.
from fastify.
I would commit the current state, but git hooks prevent me from doing so before the tests work)
You can skip git hooks with git commit -n
.
from fastify.
What methods did you need to add that were not there?
All of them 😄
I'm creating a demo where the user can set whatever method they like to see if the browser allow the request through (it's a CORS demo).
Would you like to send a Pull Request to address this issue? Remember to add unit tests.
Nah, I'm ok. I'm not even sure if it's in the spirit of this library. I was able to do what I wanted in express with:
app.options('/resource', (req, res) => {
// Handle preflight
});
app.all('/resource', (req, res) => {
// Handle main request
});
Edit: Express might support more methods, but it doesn't support arbitrary ones due to limitations in Node's HTTP implementation.
from fastify.
I might be talking shit here, I'm not sure express supports any method either, it might just support more 😄
from fastify.
That's what we're talking about.
from fastify.
It's likely not the main use case, but it would be good for the framework to be flexible enough. At the minimum we should support all methods that Node.js is supporting.
from fastify.
@mcollina Sure, how should I start working?
See https://gist.github.com/jsumners/461ef7a64545108635cc437fde112721
from fastify.
Should we implement TRACE
and CONNECT
as well?
from fastify.
@mcollina @delvedor, as far as I can see in the documentation, CONNECT
and TRACE
are not supported? I'm building sort of a custom proxy protocol and would like to add a CONNECT
endpoint to establish a bi-directional tunnel. I can do that with a separate net
socket, but having all the HTTP stuff in fastify would definitely be more desirable :)
from fastify.
@Radiergummi would you like to send a PR?
from fastify.
I didn't peek into the fastify source yet, but I'll give it a go. Depends on the scope you'd image though:
TL;DR: Either we could simply add explicit support for these two methods or drop the method name restriction altogether.
-
TRACE
calls are described by MDN like this:The final recipient of the request should reflect the message received, excluding some fields described below, back to the client as the message body of a 200 (OK) response with a Content-Type of
message/http
. The final recipient is either the origin server or the first server to receive aMax-Forwards
value of 0 in the request.This is something I guess fastify could do out of the box, unless otherwise suppplemented with a custom implementation by the user. Meaning fastify should probably adhere to the docs and mirror the request in the response, but users may provide a custom route handler for
TRACE
requests to handle it themselves.
Though I have a feeling this is so obscure it might be better off as a plugin for those that really need support forTRACE
. -
CONNECT
calls have the following description:The HTTP CONNECT method starts two-way communications with the requested resource. It can be used to open a tunnel.
I think this might be easier to implement, as a handler for this method would only need direct access to the underlying request and response streams and keep them open, but as
raw
is part of fastify's request and reply, that is there already. Of course fastify could include a higher-level API, but again that might be a better job for a plugin.
The other direction a PR might go into would be to simply allow any request method string, which is perfectly legal according to RFC 7231. Fastify could still provide helper methods for the common request methods and keep the Typescript interfaces but union them with the string type.
This would have the additional benefit of making it possible to build a webdav implementation based on fastify, should anyone fancy doing so.
from fastify.
Though I have a feeling this is so obscure it might be better off as a plugin for those that really need support for TRACE.
I agree, a plugin for this it is already doable
but as raw is part of fastify's request and reply, that is there already
Right now the stream are consumed by the content type parser, so in this case, we should skip this setup and it is doable in a plugin, but the plugin must add a content type parser that could lead to security issues (and I would not force the user to add a content type parser if it is not need at all)
So for this usage, I think it would impact a bit in core
from fastify.
I'm actively working on a PR right now, but a single test is failing for TRACE
requests for me... In # Subtest: TRACE returns 413 - Payload Too Large
, fastify returns a 400 instead of a 413. Stepping through the tests with the debugger, I noticed after the 413 is correctly sent, something somewhere throws a FST_ERR_CTP_EMPTY_JSON_BODY
, right after that node prints
test/trace.test.js 2> (node:430773) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [Socket]. Use emitter.setMaxListeners() to increase limit
test/trace.test.js 2> at _addListener (events.js:389:17)
test/trace.test.js 2> at Socket.addListener (events.js:405:10)
test/trace.test.js 2> at Socket.Readable.on (_stream_readable.js:852:35)
test/trace.test.js 2> at Socket.socketListenerWrap [as on] (_http_server.js:831:54)
test/trace.test.js 2> at Socket.socketOnError (_http_server.js:599:8)
test/trace.test.js 2> at onParserExecuteCommon (_http_server.js:618:19)
test/trace.test.js 2> at onParserExecute (_http_server.js:577:3)
test/trace.test.js 2> at HTTPParser.callbackTrampoline (internal/async_hooks.js:129:14)
The test file is copied from the PUT
tests:
'use strict'
const t = require('tap')
require('./helper').payloadMethod('trace', t)
require('./input-validation').payloadMethod('trace', t)
Which I would have guessed should work out of the box. Any ideas?
(I would commit the current state, but git hooks prevent me from doing so before the tests work)
from fastify.
FST_ERR_CTP_EMPTY_JSON_BODY
This is throw when the content type of the response is application/json but the reply.send()
has been run
After the commit open a PR so we could help you to check it 👍
from fastify.
Draft PR is open, see #2454.
from fastify.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from fastify.
I had to switch back to using expressjs for a project because fastify doesn't support adding routes for arbitrary HTTP methods. The thing I was working on was a lower-level test thing, so maybe that's fine. Just thought I'd let you know!
Edit: Express might support more methods, but it doesn't support arbitrary ones due to limitations in Node's HTTP implementation.
from fastify.
What methods did you need to add that were not there?
from fastify.
I had to switch back to using expressjs for a project because fastify doesn't support adding routes for arbitrary HTTP methods. The thing I was working on was a lower-level test thing, so maybe that's fine. Just thought I'd let you know!
Would you like to send a Pull Request to address this issue? Remember to add unit tests.
from fastify.
We support the ones Node support in the router: https://github.com/delvedor/find-my-way/blob/c561d220e6c0c93b76b72a7461dcdc8620158ba2/index.js#L102, not sure how we can support more 😅.
Maybe there is some specific behavior that we are missing?
from fastify.
Maybe I'm reading it wrong, but require('http').METHODS
is:
[
'ACL', 'BIND', 'CHECKOUT',
'CONNECT', 'COPY', 'DELETE',
'GET', 'HEAD', 'LINK',
'LOCK', 'M-SEARCH', 'MERGE',
'MKACTIVITY', 'MKCALENDAR', 'MKCOL',
'MOVE', 'NOTIFY', 'OPTIONS',
'PATCH', 'POST', 'PROPFIND',
'PROPPATCH', 'PURGE', 'PUT',
'REBIND', 'REPORT', 'SEARCH',
'SOURCE', 'SUBSCRIBE', 'TRACE',
'UNBIND', 'UNLINK', 'UNLOCK',
'UNSUBSCRIBE'
]
Whereas fastify only supports a subset of that https://github.com/fastify/fastify/blob/main/lib/route.js#L7.
But yes, you're ultimately restricted by Node here. My new plan is to use Deno which doesn't seem to have that restriction, but I might be talking shit again.
Sorry for the noise!
from fastify.
Well according to the HTTP spec, the method can be an arbitrary string: RFC 7231, section 4.1.
from fastify.
I think we can relax those checks, they are mostly for developer experience. I don't think there are any actual limitations in supporting those.
I can add an option if you'd like.
from fastify.
🤷♂️
The thing I'm building ended up needing something lower level than Node was able to support, so I'd totally understand if you didn't see this as a good fit for fastify.
from fastify.
Please support WebDAV http methods. WebDAV extension http methods are very useful, sometimes I need to process WebDAV requests especially some files related applications.
from fastify.
@hungtcs would you like to work on it? There #3635 which is not complete but a good starting point for two.
from fastify.
@hungtcs would you like to work on it? There #3635 which is not complete but a good starting point for two.
@mcollina Sure, how should I start working?
from fastify.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from fastify.
Related Issues (20)
- OPTIONS HTTP method body processing HOT 3
- Dependency update for v5 HOT 1
- Merge main into next HOT 4
- Scoped FastifyRequest Customization via Generic Parameter in FastifyInstance HOT 1
- Flaky test on N|Solid 20 MacOS HOT 2
- Implement simple B-Tree for faster string comparisons HOT 9
- Throwing error in setErrorHandler after a JSON parse SyntaxError causes app to crash
- Where is the documentation for <Reply>.sendFile? HOT 2
- Switch to ajv/2020 for fastify 5 HOT 7
- Fastify v5 coordination HOT 7
- Does Validation-and-Serialization document's outdated?
- Should we drop Node.js v18 for v5? HOT 11
- `disableErrorLogging` option HOT 1
- Request hangs if you `await reply.status` in an async handler. HOT 15
- querystring with property of type number fails HOT 7
- onError hook is called before errorHandler when error is thrown in onRequest hook HOT 7
- Approval Request for Future State Proposal HOT 20
- Expose .writeEarlyHints()
- Logger methods are not bound to this HOT 4
- Whole API breaks when passing non-async function to fastify.register HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastify.