0

How can I remove the Server HTTP response header in Yesod? I found code that's responsible for setting that header, but I don't know what to do next. I know that I can replace the header value with an empty string by using addHeader "Server" "", but I'd prefer to remove it entirely.

Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177

2 Answers2

0

I made an issue on GitHub Warp repository and they changed it that when the server name is empty, the "Server" header is not sent. Therefore, the solution is to set the server name to an empty string using setServerName "". In my case I had to add this to the warpSettings function in Application.hs. Note that you have to use the Warp version which contains the fix (as of May 3 '17, it has not been released yet, but you can pull it directly from GitHub).

Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177
-1

You must call the methods inside of the function you linked. That function will "The Date and Server header is added if not exist in HTTP response header" so you need to reimplement it if you don't want that behavior.

This is why people always say to keep your code modular and your functions small; this function is too big for your use case, and there is no specific smaller function that does exactly what you want (or else it would have been called by this function!)

Lazersmoke
  • 1,741
  • 10
  • 16
  • Uh, but this is not my code, so I can't change it, unless I make my own version of this library. – Michał Perłakowski Apr 20 '17 at 16:43
  • @MichałPerłakowski Exactly, you must write a function just like that one, except it does the headers how you like. I'm commenting on the library's poor design forcing you to do this. – Lazersmoke Apr 20 '17 at 20:04
  • I can't just "write a function", because it's an internal function in an internal module and it uses other internal functions. Moreover, I'm not even using this function directly, because I'm just using Yesod and Yesod uses Warp (which is where this function is). – Michał Perłakowski Apr 20 '17 at 20:12
  • Then you can't; it would violate the invariant set by that function. If Warp only exposes that part, then you can only use that part. You could request that feature if you want (or write it yourself), but I suspect there is a good reason for it to be designed that way. – Lazersmoke Apr 20 '17 at 20:36