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 set headers other than Content-type? #9

Open
robynitp opened this issue Nov 24, 2014 · 5 comments
Open

How to set headers other than Content-type? #9

robynitp opened this issue Nov 24, 2014 · 5 comments

Comments

@robynitp
Copy link

Is there a way to send additional headers besides the content type used in header()? Is there a way to access the response object so I could, for example, set an access control header or send a 404?

If it's not possible with the existing servi API, I'm trying to figure out if there's a way to use another module to do it while still using servi for everything else. Basically, I see that node's http is being used behind the scenes, but can't figure out if there's a way to access it through any of servi's available methods.

@robynitp robynitp changed the title How to manually headers other than Content-type? How to send headers other than Content-type? Nov 24, 2014
@robynitp robynitp changed the title How to send headers other than Content-type? How to set headers other than Content-type? Nov 24, 2014
@shiffman
Copy link
Contributor

shiffman commented Dec 2, 2014

In prepping examples I just ran into this as well. I'm trying to think of what might be appropriate API. For example, we currently have the beautifully simple:

function something(request) {
  request.respond('hello!');
}

Some awful looking ideas are:

function something(request) {
  request.responseType('text');
  request.respond('hello');
}
function something(request, response) {
  response.type('text');
  response.send('hello');
}

Will think some more.

@robynitp
Copy link
Author

robynitp commented Dec 2, 2014

Well, we have:

request.header("application/json");

but the only header it sets is the Content-type.

@shiffman
Copy link
Contributor

shiffman commented Dec 2, 2014

ah, zoinks, sorry I missed that. Perfect! Maybe for other headers it should take two arguments:

request.header("some header type","the value");

@robynitp
Copy link
Author

robynitp commented Dec 2, 2014

I like that. Wonder if it could be called multiple times for multiple headers, or if an object might be the way to go, similar to response.writeHead in node http:

{
  'Content-Length': 1234,
  'Content-Type': 'text/plain',
  'Access-Control-Allow-Origin': '*'
 }

Maybe sending a string param indicates you're setting just the content-type, and sending an object lets you set a bunch of stuff.

@vanevery
Copy link
Collaborator

vanevery commented Dec 3, 2014

Agreed.. We should do this at the very least:
request.header("some header type","the value");

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

3 participants