-
Notifications
You must be signed in to change notification settings - Fork 155
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 change response header ? #64
Comments
Hi @Runrioter,
You can set contentType now by In the future, I am planning to get rid of special setters (like r.contentType).
|
Is related to #43 |
@xeioex Thanks for your quick reply. I like the njs module. Hope that it will become better. |
Hi @Runrioter , Could you please report the njs version. I am trying to reproduce the delete issue (using 0.2.6).
|
Yes. I use 0.2.6, too.
|
So, how can I reproduce the crash? |
Sorry, I mean the crash is the js exception. Is this js exception
|
It is a special value type (a thin, zero-copy wrapper around nginx C-structures). externals is a way to introduce native nginx object into the engine. For example r - nginx request is external. In C-code, you have to define some C level functions to support the operations (like iterations, property get, property set..) (https://github.com/nginx/njs/blob/master/nginx/ngx_http_js_module.c#L478). In the future, I hope to get rid of the externals, but it is not easy. Currently, there is no C-level function which implements delete operation for r.headersOut object.
njs aims to implement strict mode only. In the strict mode, you get TypeError exception (according to ES5.1 https://www.ecma-international.org/ecma-262/5.1/#sec-11.4.1) if delete operator fails (njs treats absence of C-level delete function as a configure:false). |
@xeioex Thank you. I learnt a lot. You can close this issue at any time. |
Hi! I'm having the problem when trying to change the content type. Using
When using the proposed
Any solution on this? I would prefer if the content type Awesome project btw! Very helpful for doing security testing. EDIT: Seems that the following code works: r.status = 200;
r.headersOut['Content-Type'] = 'text/plain';
r.sendHeader();
r.finish(); Which returns the following correct response:
|
Hi @mfaerevaag, The issue with some special headers still persists (the reason for that is explaned here). As a workaround: or the following code (r.response object is deprecated, and will be removed in the future): r.response.contentType = 'text/plain'; // <- modifies resulting content_type header in-place.
r.return(200, "Hello world\n"); |
Alright, thanks! |
When I try to set nginx.1 | 2020/01/08 08:10:27 [error] 59#59: *138 js exception: TypeError: property set on primitive undefined type |
To change Content-Type header:
|
Hi buddies:
I set response header.
But I got two
Content-Type
header (another comes from default_type).I try to delete it, but it doesn't work either. (crash)
The text was updated successfully, but these errors were encountered: