practicalli / clojure-web-services

Develop production grade server-side web services and APIs using Clojure and REPL driven development
https://practical.li/clojure-web-services
Creative Commons Attribution Share Alike 4.0 International
11 stars 14 forks source link

Configuring the webserver - examples #79

Open practicalli-johnny opened 3 years ago

practicalli-johnny commented 3 years ago

Hiding details about the web server

:send-server-version? false to stop returning the Server details in the header of its responses. :send-date-header? false to avoid including the date of the response.

Without these settings, the server will return details in the headings:

❯ http --verbose :8080/api/ping
GET /api/ping HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/2.2.0

HTTP/1.1 200 OK
Content-Length: 5
Date: Tue, 29 Sep 2020 06:19:35 GMT
Server: Jetty(9.4.28.v20200408)Pong!

Stop the web server and start after adding config to startup command:

(defn jetty-start
  [handler opts]
  (jetty/run-jetty handler (-> opts (assoc :send-server-version? false
                                           :send-date-header? false
                                           :join? false)))) ;; false so that we can stop it at the repl!

Now the server does not return the details all the detals

❯ http --verbose :8080/api/ping
GET /api/ping HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/2.2.0

HTTP/1.1 200 OK
Content-Length: 5