0

I'd like to remove the server header from Payara Micro's output.

For example, it reports this:

HTTP/1.1 200 OK
Server: Payara Micro #badassfish

I'd like to get rid of that Server line.

I see that issue 32 provided the capability in theory to disable this. The associated pull request certainly seems to show that there is some sort of property being consulted to disable this. And I can infer from this that I could presumably go into the administration GUI if this were a full-fledged server and click a checkbox somewhere.

But I'm running Payara Micro which needs to be fully configured from the command line at startup.

What I'm lacking is a simple "put this on the command line"-type of instruction and I can't seem to locate that anywhere. Is there a setting in, say, glassfish-web.xml-as-modified-by-Payara I could use? Or a command line switch? Or a specific asadmin attribute I could set in a pre-boot script? Ideas?

Laird Nelson
  • 15,321
  • 19
  • 73
  • 127

1 Answers1

2

The change that you referenced linked to a pull request which added a boolean server-header property to the http-listener which would disable the header.

There is no native asadmin command to set this property, so you will need to use an asadmin set command with the correct dotted name for the listener you want to modify. To find out what this is, you can use the get command with a wildcard and grep for the value you want, as shown below with Payara Server:

➜  ~ /opt/payara/server/171.1/bin/asadmin get "*" | grep server-header  
configs.config.default-config.network-config.protocols.protocol.http-listener-2.http.server-header=true
configs.config.default-config.network-config.protocols.protocol.http-listener-1.http.server-header=true
configs.config.default-config.network-config.protocols.protocol.admin-listener.http.server-header=true
configs.config.server-config.network-config.protocols.protocol.admin-listener.http.server-header=true
configs.config.default-config.network-config.protocols.protocol.sec-admin-listener.http.server-header=true
configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.server-header=true
configs.config.server-config.network-config.protocols.protocol.http-listener-2.http.server-header=true

Since the default-config is just a template and not used, we want the listeners from server-config. http-listener-1 is for HTTP by default and http-listener-2 is for HTTPS by default. To modify the server-header property in Payara Micro, you would need to create a file with the following command in (note that Payara Micro only has a single listener by default called http-listener):

set configs.config.server-config.network-config.protocols.protocol.http-listener.http.server-header=false

You can then apply these with a prebootcommandfile as follows:

java -jar /opt/payara/micro/173/payara-micro.jar --prebootcommandfile myCommands.txt

You may also wish to disable the xpowered-by property via the same method.

Mike
  • 4,852
  • 1
  • 29
  • 48
  • Thanks very much! I tried this on Payara Micro 172 and it did not work. Does the `--preBootCommandFile` need to be first after the `.jar` file? (Note also my use of camel case in case it matters; I seem to recall these options are case-insensitive as of 171.) – Laird Nelson Sep 08 '17 at 21:56
  • The order of the commands doesn't matter (order is only important where you've got things like multiple deploy commands). You might try using the file as a postbootcommandfile though. The problem with the prebootcommandfile is that it's so early in the boot sequence that things may not have initialized properly when the file is run. It's hard to tell ahead of time if it's too early without trying it first. – Mike Sep 08 '17 at 22:04
  • 1
    I think there might also be an issue with the `--systemProperties` argument, which I'm also using. Leaving that aside for the moment, indeed when I remove `--systemProperties` then I see `WARNING: Boot Command set failed PlainTextActionReporterFAILURENo configuration found for configs.config.server-config.network-config.protocols.protocol.http-listener-1.http` in the output. I'll see if changing to post-boot works (seems like it should). Thanks again! – Laird Nelson Sep 08 '17 at 22:15
  • 1
    Ah, it is probably the http listener name is wrong. I think in Micro, there is only one (unless you specify another) and it is probably just called `http-listener`. I can't check right now, but you could use the --rootDir option to dump out the config to a directory of your choice. You can then look in the domain.xml and see what it's called. – Mike Sep 08 '17 at 22:18
  • For posterity: indeed there is only one, and it is (seemingly) called `http-listener`. Thanks for your prompt help. – Laird Nelson Sep 08 '17 at 22:29