I would like to change the http-header "Server: " value dynamically (while building the respond) in yaws. I tried:-
[{status, 200},
{allheaders,
[{header,
["Server: ","ASP.NET Development Server/10.0.0.0"]
}]
},
{html,Body}
]
it returned two "Server: " headers instead of one. But it worked for all other headers.
For Older Versions of yaws (yaws-1.90 and below) the answer below works
[{header,"Server: MyOther Server Name"}]
, yaws will enforce and tag its name and version before your server header value, like this: Server: Yaws 1.91, MyOther Server Name
. This occurs when in your out/1
function you end with a header value, server like this:
out(_A)->
[{header,"Server: ASP.NET Server"},
{html,"<p>I love klacke and yaws ! </p>"}].
Checking your browser, using Firebug you see the Response headers specified as follows:
Date Thu, 17 Nov 2011 07:59:17 GMT Content-Length 22 Content-Type text/html Server Yaws 1.91, ASP.NET Server
Now the solution:
In the yaws src
, there is a module called yaws.erl
. In this module, check around line: 1332
, you will find a function like this:
make_server_header() -> HasDav = ?sc_has_dav(get(sc)), ["Server: ", (get(gc))#gconf.yaws, "\r\n" | if HasDav == true -> ["DAV: 1\r\n"]; true -> [] end].
This is the piece of code that appends the yaws version and server name on top of your server header specified value. We need to change it and comment out the lines and let it return an empty list [ ]
or empty string ""
to look like this:
make_server_header() -> %%HasDav = ?sc_has_dav(get(sc)), %%["Server: ", (get(gc))#gconf.yaws, "\r\n" | %% if HasDav == true -> %% ["DAV: 1\r\n"]; %% true -> %% [] %% end]. []. %% force it to just return empty
Last step
Now we need to re-compile this module and replace the existing yaws.beam file in YAWS-{VSN}/ebin
with the new resulting .beam file we get after compiling this new source. Then reload it in the VM. I hope you can find your way in this last step. One way of pulling this off is by changing the current working directory of your yaws running erlang shell
1> cd("PATH/TO/YAWS/src"). PATH/TO/YAWS/srcThen, execute this (still in the yaws shell) after changing the source of the yaws.erl as we have mentioned above
2> c(yaws). {ok,yaws}
Now move the generated yaws.beam file from src to ebin. Overwrite/ replace the existing yaws.beam file in ebin with the one from src
$ mv PATH/TO/YAWS/src/yaws.beam PATH/TO/YAWS/ebin/So, if yaws is running, reload that code by entering in its shell:
3> l(yaws).
For Newer versions of yaws (yaws-1.91 and above)
yaws.conf
file server_signature = "MY SERVER SIGNATURE"
Server: MY SERVER SIGNATURE
As of version 1.90 of Yaws, released in May 2011, you can set the global configuration variable server_signature
to customize the Server
HTTP response header. We're also, as of this writing, in the process of making server_signature
override-able on a per-virtual-server basis, so you can serve different Server
headers from different virtual servers if you like. This change will be added to the yaws github repo in early Feb 2012 and will later appear in Yaws 1.93, whenever we decide to release that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With