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
Now, by default, any header specified as
[{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 yourout/1function you end with a header value, server like this:Checking your browser, using Firebug you see the Response headers specified as follows:
Now the solution:
In the yaws
src, there is a module calledyaws.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 [ ]orempty 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 emptyLast step
Now we need to re-compile this module and replace the existing yaws.beam file in
YAWS-{VSN}/ebinwith 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 shell1> 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
So, if yaws is running, reload that code by entering in its shell:
For Newer versions of yaws (yaws-1.91 and above)
There is a parameter you will just add to your
yaws.conffileserver_signature = "MY SERVER SIGNATURE"And so the headers will come with
Server: MY SERVER SIGNATURE