http庫(kù)無需初始化, 導(dǎo)入后直接使用.
此方法在使用
httpd
對(duì)象注冊(cè)了before
處理方法之后, 可以直接return http.ok()
.
當(dāng)before函數(shù)正確檢測(cè)到返回http.ok()后, 允許當(dāng)前路由繼續(xù)執(zhí)行到用戶回調(diào)函數(shù)(類).
此方法在使用
httpd
對(duì)象注冊(cè)了before
處理方法之后, 可以直接return http.redirect(your url)
.
當(dāng)before函數(shù)正確檢測(cè)到返回http.redirect()后, 將會(huì)任務(wù)將請(qǐng)求重定向到其它http[s]鏈接上.
第二個(gè)參數(shù)code為可選的http跳轉(zhuǎn)碼, 只能是
301
或302
(不傳入code默認(rèn)情況下是302
);
此方法在使用
httpd
對(duì)象注冊(cè)了before
處理方法之后, 可以直接return http.throw(code, html)
.
當(dāng)before函數(shù)正確檢測(cè)到返回http.throw()后, 將會(huì)使用指定的code狀態(tài)碼來進(jìn)行返回(僅允許
400
-499
之間的錯(cuò)誤碼);
第二個(gè)參數(shù)為可選的html代碼, 作為自定義錯(cuò)誤碼的內(nèi)容(可以在調(diào)試階段將錯(cuò)誤日志打印出來).
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)
更多建議: