W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
http庫無需初始化, 導入后直接使用.
此方法在使用
httpd
對象注冊了before
處理方法之后, 可以直接return http.ok()
.
當before函數(shù)正確檢測到返回http.ok()后, 允許當前路由繼續(xù)執(zhí)行到用戶回調(diào)函數(shù)(類).
此方法在使用
httpd
對象注冊了before
處理方法之后, 可以直接return http.redirect(your url)
.
當before函數(shù)正確檢測到返回http.redirect()后, 將會任務將請求重定向到其它http[s]鏈接上.
第二個參數(shù)code為可選的http跳轉(zhuǎn)碼, 只能是
301
或302
(不傳入code默認情況下是302
);
此方法在使用
httpd
對象注冊了before
處理方法之后, 可以直接return http.throw(code, html)
.
當before函數(shù)正確檢測到返回http.throw()后, 將會使用指定的code狀態(tài)碼來進行返回(僅允許
400
-499
之間的錯誤碼);
第二個參數(shù)為可選的html代碼, 作為自定義錯誤碼的內(nèi)容(可以在調(diào)試階段將錯誤日志打印出來).
app:before(function (content)
if true then
return http.ok()
end
if true then
return http.redirect('https://github.com/CandyMi/core_framework')
-- return http.redirect('https://github.com/CandyMi/core_framework', 301 or 302)
end
if true then
return http.throw(431, '<h1> This is 413 Error, too long request header</h1>')
end
end)
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: