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

How to disable built-in formatters? #713

Closed
bsander opened this issue Nov 27, 2014 · 4 comments
Closed

How to disable built-in formatters? #713

bsander opened this issue Nov 27, 2014 · 4 comments

Comments

@bsander
Copy link

bsander commented Nov 27, 2014

We have created our own formatters for various response types (json, xml, html). I want to exclusively use these custom formatters and not allow the use of the built-in restify formatters which are still allowing requests with an accept header of appliction/octet-stream or text/plain for example to get through. How can I remove these built-in formatters from my restify instance?

@micahr
Copy link
Member

micahr commented Jun 5, 2015

if you pass a set of formatters in to your server:

restify.createServer({
    formatters: { 
        'application/javascript; q=0.1': require('./your-jsonp'),
        'application/json; q=0.4': require('./your-json'),
        'text/plain; q=0.3': require('./your-text'),
        'application/octet-stream; q=0.2': require('./your-binary')
    }
});

You should be able to set the q values lower than the built ins, which will pick yours over the built ins.

@micahr micahr closed this as completed Jun 29, 2015
@bsander
Copy link
Author

bsander commented Jul 1, 2015

@micahr but what about actually disabling these response types? I don't have my own to replace them with, I just want restify to return a 406 like it does with any other unsupported type.

@micahr
Copy link
Member

micahr commented Jul 1, 2015

I believe if you pass in a formatters property when creating the server that doesn't have a specific mime-type, that will accomplish what you are looking for. For Example, this would only allow application/javascript as a mime-type.

var javascriptFormatter = require('restify').formatters['application/javascript; q=0.1'];
restify.createServer({
    formatters: { 
        'application/javascript; q=0.1': javascriptFormatter
    }
});

@bsander
Copy link
Author

bsander commented Jul 2, 2015

Unfortunately, that is not the case (at least in 2.8.5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants