codecamp

HTTP

介绍

http库无需初始化, 导入后直接使用.

http.ok()

此方法在使用httpd对象注册了before处理方法之后, 可以直接return http.ok().

当before函数正确检测到返回http.ok()后, 允许当前路由继续执行到用户回调函数(类).

http.redirect(url, code)

此方法在使用httpd对象注册了before处理方法之后, 可以直接return http.redirect(your url).

当before函数正确检测到返回http.redirect()后, 将会任务将请求重定向到其它http[s]链接上.

第二个参数code为可选的http跳转码, 只能是301302(不传入code默认情况下是302);

http.throw(code, html)

此方法在使用httpd对象注册了before处理方法之后, 可以直接return http.throw(code, html).

当before函数正确检测到返回http.throw()后, 将会使用指定的code状态码来进行返回(仅允许400-499之间的错误码);

第二个参数为可选的html代码, 作为自定义错误码的内容(可以在调试阶段将错误日志打印出来).

使用示例

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)
HTTPC
Mail
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

API 使用手册

HTTP API

Mail API

DB API

DB

Cache API

class API

MQ API

MQ

Crypt API

cf API

cf

System API

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }