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

Ssotomayor feature/532 content type hard not send #536

Closed

Conversation

jonathanong
Copy link
Member

closes #532
closes #534

@dougwilson @fundon @ssotomayor how about this?

@ssotomayor
Copy link
Contributor

Seems in the same direction as this, however as i pointed out before, i'm not sure why is application/octet-stream as the default option, there are even tests checking that. If there is no logical reason i support the option of setting null as any header option to NOT send it, then the user decides.

@fundon
Copy link
Contributor

fundon commented Oct 20, 2015

LGTM

@jonathanong
Copy link
Member Author

anyone else?

@tejasmanohar
Copy link
Member

LGTM. agree w/ @dougwilson's comment on the previous PR for this fix

@juliangruber
Copy link
Contributor

+1

1 similar comment
@fengmk2
Copy link
Member

fengmk2 commented Oct 21, 2015

+1

@dougwilson
Copy link
Contributor

LGTM

@tj
Copy link
Member

tj commented Oct 21, 2015

@ssotomayor octet stream is a reasonable default I think, everything is an octet stream haha, but 👍 for being able to unset

@ssotomayor
Copy link
Contributor

Just closed the other PR, i agree with the fixes. 👍

@jonathanong jonathanong force-pushed the ssotomayor-feature/532-content-type-hard-not-send branch from 601f648 to a6cb258 Compare October 22, 2015 22:37
@jonathanong jonathanong force-pushed the ssotomayor-feature/532-content-type-hard-not-send branch from a6cb258 to 37e630d Compare October 22, 2015 22:37
@jonathanong jonathanong deleted the ssotomayor-feature/532-content-type-hard-not-send branch October 22, 2015 22:39
jonathanong pushed a commit that referenced this pull request Oct 22, 2015
@evilive3000
Copy link

evilive3000 commented Jun 27, 2017

Hi. Is there a way to respond with an undefined body and DO NOT set a content-type.

I'm trying to make an internal redirect by nginx depend on the headers that returned from koa's backend. All I need is only one field X-Accel-Redirect; but Koa appends Content-Type: text/plain header which will be transparently proxied through nginx. But if content-type were absent in koa's respond Nginx automatically decides what type it is and sets it correctly.

I found the code where the magic happens application.js#L218:

  // status body
  if (null == body) {
    body = ctx.message || String(code);
    if (!res.headersSent) {
      ctx.type = 'text';
      ctx.length = Buffer.byteLength(body);
    }
    return res.end(body);
  }

according to this I will always get non empty body?

@evilive3000
Copy link

Right after posting prev comment I found that if I explicitly set body to null ctx.body = null; I receive 204 status code as expected. Wonder why it is not default behavior. When I don't set the body shouldn't it be treated as if I set it to null

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

Successfully merging this pull request may close these issues.

'Content-Type' hard not to send
9 participants