Skip to content

Commit

Permalink
fix http-server-test
Browse files Browse the repository at this point in the history
  • Loading branch information
d-t-w committed Jan 17, 2025
1 parent f5c5c89 commit bda1789
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
29 changes: 16 additions & 13 deletions slipway-jetty12/src/slipway/connector/http.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@
HttpConnectionFactory ProxyConnectionFactory Server ServerConnector)))

(defn default-config ^HttpConfiguration
[{::keys [http-forwarded? send-server-version? send-date-header?]
:or {send-server-version? false
send-date-header? false}}]
[{::keys [http-forwarded? send-server-version? send-date-header? relative-redirect-allowed?]
:or {send-server-version? false
send-date-header? false
relative-redirect-allowed? false}}]
(let [config (doto (HttpConfiguration.)
(.setSendServerVersion send-server-version?)
(.setSendDateHeader send-date-header?))]
(.setSendDateHeader send-date-header?)
(.setRelativeRedirectAllowed relative-redirect-allowed?))]
(when http-forwarded? (.addCustomizer config (ForwardedRequestCustomizer.)))
config))

(comment
#:slipway.connector.http{:host "the network interface this connector binds to as an IP address or a hostname. If null or 0.0.0.0, then bind to all interfaces. Default null/all interfaces"
:port "port this connector listens on. If set to 0 a random port is assigned which may be obtained with getLocalPort(), default 80"
:idle-timeout "max idle time for a connection, roughly translates to the Socket.setSoTimeout. Default 200000 ms"
:http-forwarded? "if true, add the ForwardRequestCustomizer. See Jetty Forward HTTP docs"
:proxy-protocol? "if true, add the ProxyConnectionFactor. See Jetty Proxy Protocol docs"
:http-config "a concrete HttpConfiguration object to replace the default config entirely"
:configurator "a fn taking the final connector as argument, allowing further configuration"
:send-server-version? "if true, send the Server header in responses"
:send-date-header? "if true, send the Date header in responses"})
#:slipway.connector.http{:host "the network interface this connector binds to as an IP address or a hostname. If null or 0.0.0.0, then bind to all interfaces. Default null/all interfaces"
:port "port this connector listens on. If set to 0 a random port is assigned which may be obtained with getLocalPort(), default 80"
:idle-timeout "max idle time for a connection, roughly translates to the Socket.setSoTimeout. Default 200000 ms"
:http-forwarded? "if true, add the ForwardRequestCustomizer. See Jetty Forward HTTP docs"
:proxy-protocol? "if true, add the ProxyConnectionFactor. See Jetty Proxy Protocol docs"
:http-config "a concrete HttpConfiguration object to replace the default config entirely"
:configurator "a fn taking the final connector as argument, allowing further configuration"
:send-server-version? "if true, send the Server header in responses"
:send-date-header? "if true, send the Date header in responses"
:relative-redirect-allowed? "if true, allow relative redirects, default false"})

(defmethod server/connector ::connector
[^Server server {::keys [host port idle-timeout proxy-protocol? http-forwarded? configurator http-config]
Expand Down
14 changes: 7 additions & 7 deletions slipway-jetty12/test/slipway/http_server_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@

;; requires authentication
(is (= {:protocol-version {:name "HTTP" :major 1 :minor 1}
:status 303
:reason-phrase "See Other"
:status 302
:reason-phrase "Found"
:orig-content-encoding nil
:body ""}
(-> (client/do-get "http" "localhost" 3000 "")
(select-keys of-interest))))

(is (= 303 (:status (client/do-get "http" "localhost" 3000 "/"))))
(is (= 303 (:status (client/do-get "http" "localhost" 3000 "/user"))))
(is (= 302 (:status (client/do-get "http" "localhost" 3000 "/"))))
(is (= 302 (:status (client/do-get "http" "localhost" 3000 "/user"))))

;; auth redirect goes to expected login page
(is (= "http://localhost:3000/login" (get-in (client/do-get "http" "localhost" 3000 "") [:headers "Location"])))
Expand All @@ -111,7 +111,7 @@
(is (= 200 (:status (client/do-get "http" "localhost" 3000 "/login-retry"))))

;; jetty nukes session and redirects to /login regardless
(is (= 303 (:status (client/do-get "http" "localhost" 3000 "/logout")))))
(is (= 302 (:status (client/do-get "http" "localhost" 3000 "/logout")))))

(testing "login"

Expand Down Expand Up @@ -179,8 +179,8 @@
(testing "logout"

(is (= {:protocol-version {:name "HTTP" :major 1 :minor 1}
:reason-phrase "See Other"
:status 303}
:reason-phrase "Found"
:status 302}
(let [session (-> (client/do-login "http" "localhost" 3000 "" "admin" "admin")
(select-keys [:cookies]))]
(client/do-get "http" "localhost" 3000 "/logout" session)
Expand Down

0 comments on commit bda1789

Please sign in to comment.