- = do res <- readTVar (itrResponse itr)
-
- when (res == Nothing)
- $ setStatus itr InternalServerError
-
- when (itrRequest itr /= Nothing)
- $ relyOnRequest itr
-
- do oldRes <- readTVar (itrResponse itr)
- newRes <- unsafeIOToSTM $ completeUnconditionalHeaders $ fromJust oldRes
- setRes itr newRes
+ = do reqM ← readItr itrRequest itr
+ res ← readItr itrResponse itr
+ let sc = resStatus res
+
+ unless (any (\ p → p sc) [isSuccessful, isRedirection, isError])
+ $ abortSTM InternalServerError []
+ $ Just
+ $ A.toText
+ $ A.fromAsciiBuilder
+ $ A.toAsciiBuilder "The status code is not good for a final status of a response: "
+ ⊕ printStatusCode sc
+
+ when (sc ≡ MethodNotAllowed ∧ getHeader "Allow" res ≡ Nothing)
+ $ abortSTM InternalServerError []
+ $ Just
+ $ A.toText
+ $ A.fromAsciiBuilder
+ $ A.toAsciiBuilder "The status was "
+ ⊕ printStatusCode sc
+ ⊕ A.toAsciiBuilder " but no Allow header."
+
+ when (sc ≢ NotModified ∧ isRedirection sc ∧ getHeader "Location" res ≡ Nothing)
+ $ abortSTM InternalServerError []
+ $ Just
+ $ A.toText
+ $ A.fromAsciiBuilder
+ $ A.toAsciiBuilder "The status code was "
+ ⊕ printStatusCode sc
+ ⊕ A.toAsciiBuilder " but no Location header."
+
+ when (reqM ≢ Nothing) relyOnRequest
+
+ -- itrResponse の内容は relyOnRequest によって變へられてゐる可
+ -- 能性が高い。
+ do oldRes ← readItr itrResponse itr
+ newRes ← unsafeIOToSTM
+ $ completeUnconditionalHeaders (itrConfig itr) oldRes
+ writeItr itrResponse newRes itr