请求
req
对象表示 HTTP 请求,并具有请求查询字符串、参数、正文、HTTP 标头等的属性。在本文档中,按照惯例,该对象始终称为 req
(HTTP 响应为 res
),但其实际名称由您正在使用的回调函数的参数确定。
例如:
app.get('/user/:id', (req, res) => {
res.send(`user ${req.params.id}`)
})
但你也可以拥有:
app.get('/user/:id', (request, response) => {
response.send(`user ${request.params.id}`)
})
req
对象是Node自带请求对象的增强版,支持所有内置字段和方法。
req.app
此属性包含对使用中间件的 Express 应用程序实例的引用。
3syuHkPqQ0PAq2NAmBG7FWYcdokZbmHCrzgWNiT97vK9DxQEneIgG/9NlHWFWUevVE3YwGa0WDaqIFNjmpxQNzj4Hu/Jt64DG13w7XpnhfZnY/32LO5ynexIPs7r92nuYQz/P9karilPtr9UwFkFugNmz82cQl5vnBnKNel0bJ8318hj1JI7Mkaf9HO5Vg9gGtkjAvmB+YiKRTea/cCJJOMF+kKdW99cosbIIFmBscDIBVaM9YiYm0qw4W40fmEICeDhjd45LefkFx3hu67miA==
4h5+3DAGYIrQZh8xCRRFCA==
// index.js
app.get('/viewdirectory', require('./mymiddleware.js'))
// mymiddleware.js
module.exports = (req, res) => {
res.send(`The views directory is ${req.app.get('views')}`)
}
req.baseUrl
cfd8cQgxsU8o4ceNazft/IJauo4W6scyJ7qlzMyrX1+p+4XgoocYrdX5rNnjgy/m
951AiV64YvuExLHp5iLgUrnR8qC8/YAhjPKzZctY0Onfag/1SoR0HhLmGgnh5BcH6inqVhtHZp7E+EUNR7qOmp+tNt+8NaRb27SKcaG4OFSIoTLx+lWbvrMxzSpRcQYO4p5ugoMYt2f2Xe1t4/FZRS4dSYJ5lZ55NJvTapTdYP8GOStMDpeW9IdJ5ydKyoY5s3Rdhl8oCK0t7mj3b07UAcA2mptIR7JZbyjSYYmlY1ywk76jVRvFdgRqtmfMbZSnsiKMbwlqvx6dro1qUtCH/Q==
4h5+3DAGYIrQZh8xCRRFCA==
const greet = express.Router()
greet.get('/jp', (req, res) => {
console.log(req.baseUrl) // /greet
res.send('Konichiwa!')
})
app.use('/greet', greet) // load the router on '/greet'
VLdPLSOOgpp1qoYzlyYej0MAKrbX7NrVi22TVX9MjixBJYI3O6rX8OLU8bBTmMGFpSKwHcy9DmFAeWsR6u63RMbw8QnRD0ahR/hBWRmeXn1323YdyfFWC533mB2tS1l+KZrojaX9UgGcy1clzy0LdXvV4Z+DNEmRR5Z+c5q8jVRGDEp29ljbasSMq4o33ia/xpBgXV7H6RNet7JPr0fFc4psr3tEzodWZHmysTPq/NiQCF5egBWsCeVt7dAhwcfm7n5WngHIsXNdTsWigjc05nx+fdHfPIpo9ulrwnQyi1U=
app.use(['/gre+t', '/hel{2}o'], greet) // load the router on '/gre+t' and '/hel{2}o'
FfksolmwZUJcFF/nDyasUJfCdM8V2Rx4o3vC23dG6YHIAQs2WNwniTxbb/iJgSBqJV0nLxCGPYGXtAA7VdnFsjVQf+/nVFYbWtYPalFDKTdbobS6ZD+OBOePwyDjnAcrs0ZU5CM2ffnVcV20T/v8ETIJkwzxmLTW907JuSpCHPKh/daccE6RwBQ4aFoF717VA9DNpJeEgO+kOmj3nfdplUQ7EuhwaqcMT6/kA6Fyj2+RRjsBXbUf/TvhvdyD4hJ/
req.body
1xB5Urn1GGxKKEutp3/rpnKA4JwOniSC2DOn1uDlm2VueH6q/lcsROgPnW/BOpg4iIztRzmT/JaeS1l5hKgd9NYMev0usvx1gbUjATzmLZdNlTDJdQ9wCjVjxuL0wT0xFvTk/IXRRrg2la/3D14VtQ01QumfTUH9jBb4CTQHm4iuRrN/bvKe/XViNc6X7xuzT94MXKxNz2GUu151v2gdVei1uKwzBo2P2BQsfGtpdqdYp8D5dV1+VKXo6bS37nOGoB7cX/i6ZMLah9LZFByTabzntdeRxfSOHlgNUM+H9Q8IyVQ8HDjGmm6x35/WoGSqpXph0qFVxh4BPyrYaA2g065KGN4A7vKL6Gq5sRDPU9Ot7meuuCRwBaOjD+DhW7xo
CEE+c2tOj7HBPk4SmWZa4yEZk26sNOh+QPjevfvManqg11YJhQgFfrfcSEeoAq/4xN2v9bCrqAm4xYR4eEbb8zCZ/zUrLz15LqdQZs/NlEpVDLwvc/eBGOmpy7OyElKcVnqaEsfl3Ar8oc09MmacGjvkKUxMBFgvmZ2wj6uwgEaExCl+mBeYnN03BM5Vy516+uXzpV32hl4H1NJt2RMbkdwIRoDdO+MBabv/oQsBRUI9PKaqmxPpN2K3el6VV0z/iwl0u+ilX+9olSelFyxgPOSOVSX5dTbpdG5BnCJJZOuOXHigEq3kAcX9tP1hAcewzunLPurCLuza3o1J29US7/+U/PoIGqUhTAv2Xnp2U4p3IC+SkVWwJ1nEO50J3EYexiyVtJcDFSNc8Hoid+mH7cOmiJc74456k3SsW6B2V04SdVkuhhkVjMAdEdw45xLPZP6Kg1uvwBbncIB0vmzuqpFlo6TUQIhTrFtr72ugs6d6SdZpy8gruGn4OH+7gusjziq87Jab2V4Jy79N4YFB/A==
laCjC9T/Bas0TOIMbqegKBQSO8Fz+6DIf1Qb9JXHi6aj2NoTDu1vJYV/hF+wv03diDtsMXfd7A+eAFr3g6UbWeVSdjf2OrFG7v4RAIisr2uqyI8lyW2Fydxw16NuvOsx
const app = require('express')()
const bodyParser = require('body-parser')
const multer = require('multer') // v1.0.5
const upload = multer() // for parsing multipart/form-data
app.use(bodyParser.json()) // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded
app.post('/profile', upload.array(), (req, res, next) => {
console.log(req.body)
res.json(req.body)
})
req.cookies
BpDIkXRUnkPiBz8iBceshHRho+n2gRQ/Ye0EOGheBhDUobeNi1kK4uP4CBLDHFAkUXNBvfKktLS9DV+CYNGZbJnI8zl7E8t0uauViSrVpaj/a+bCHkTwByl+/i9MernD50PorQDpo6lai5cGnwJwnPXtf5Uv5SYRH4fMH/BRY5CxN85jldnxWcXNW6mQZMJDE8diVbKu+Oq2xFZ/zVjx5T9ZqawbkkxREaG+hEUYaVK/6eXvYJnkn/i1fgjwb7Qn8viXsHWCdTm6r5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ir(req.fresh)
// => true
req.host
4dT0eRDfIwmT5T/KdkIuJQu97AoYjmC/HUfl8qzf2W9e1e8XRayGnxvgH1wNIrj9W0ICgdvj1IK2TTIUKZKcoA==
BScAQYDKWCG5hAiJ2bZrc857lCAIjKrJGyrXWBMDEO5d92sKJGk1iT4LCKtAdxWl2oBN2ESa2mG1sQA/8jcoAsStLbPWu8yiTfj1zRegCa4V4H5kzHVAn0BT5n0d3Hig7pIsMm9HhedwjujNjx/Y21sgY2UmGzJv8ovwknLiK5OhgXkbT1B3Y6ALoqIkU2SW3t6IFaakGnRlJm1kcBMrDP8QJGT2x86SRb9yc/hu+SSyfbEfPqEZ+6hlIfk0cdeBtYPE7U5LsOpUH2G0TgMOYFk7dRKI5tGGOnJqgQrwRXeHN+zDShrFb5Eokp5inArkcwuNT1cx9W6b+ov58SKP9w==
ArXoQnxbZN1Ff9UFK4DiizbuJTrD9OoudaRP/YjtPykWgRlKO/EXCER4Y2kWzppKYianb74CXglyEiLmTau2xp2j6OBWuzD3Tw70WUlODsmfLc49O/yKlaXbo2gC3HhyBMQEM+v5bxUXdMd/77vnILeSpYvTscrXxILoGt69MDJRtjdsp3Lk4a5e6IiIyE7c72Cg74X6u7VD5NJTFUhDlVEgn4GIwoItTOOTLkXGW4g=
// Host: "example.com:3000"
console.dir(req.host)
// => 'example.com:3000'
// Host: "[::1]:3000"
console.dir(req.host)
// => '[::1]:3000'
req.hostname
4dT0eRDfIwmT5T/KdkIuJQu97AoYjmC/HUfl8qzf2W9e1e8XRayGnxvgH1wNIrj9TqMPDsUjO/iSUvg0FJn5jg==
037cAlzAqyMPf2JuGJH2fy7U/HC9TD+ga+i/t+jMbM4A3R8msM+pjgpDrsdTwi1PvLkbZns7rp40CcDVWwb+YLWHImy4d/zDfaU6IbA2a4Axhy2cxHDd4gbkmyTBRfNrxDi0Yx+KHLpzOkKfdUn4Vo7Fy+eCGnmz8hqaLKtP7qHmoGI7kaJA2o/Fc/ScOl3n1kB3VU9sQ9FU5z9ofwA0iCQNiLtMFP7n57y4DGF2JWj+Ct3fVFLLVjznZQ36dx74LoV5Mf2Z0kbz7NJaTr0iOLhPGs2u+dg4IvgliItTbRaX4OTKIHdsNf9WwKpFaEruiMIqCF2GdCfdUokwNsihOw==
ArXoQnxbZN1Ff9UFK4DiizbuJTrD9OoudaRP/YjtPykWgRlKO/EXCER4Y2kWzppKYianb74CXglyEiLmTau2xp2j6OBWuzD3Tw70WUlODsmfLc49O/yKlaXbo2gC3HhyBMQEM+v5bxUXdMd/77vnILeSpYvTscrXxILoGt69MDJRtjdsp3Lk4a5e6IiIyE7c72Cg74X6u7VD5NJTFUhDlVEgn4GIwoItTOOTLkXGW4g=
wG8rtuhI1W+zLVlA2gaTFMuggkJLudNFNaR9fomKqMOrOLJLAXB6g8WJlGBO//OywZV1YQD74Cu6DA4DOj7wBGevNdixwQS3P2DrC8fQt9SzaN0bgczCFM2VdYaTIuHbzOL2Zm66WtQtJD2CFddCZg==
// Host: "example.com:3000"
console.dir(req.hostname)
// => 'example.com'
req.ip
3BJEo/PsygbrqtkGmat+6RlMNr7xnKLx7T65EmylzCbqNqZ0XpCIO8wmhpqwdnGZ
037cAlzAqyMPf2JuGJH2fy7U/HC9TD+ga+i/t+jMbM4A3R8msM+pjgpDrsdTwi1PvLkbZns7rp40CcDVWwb+YLWHImy4d/zDfaU6IbA2a4Axhy2cxHDd4gbkmyTBRfNrxDi0Yx+KHLpzOkKfdUn4Vo7Fy+eCGnmz8hqaLKtP7qGmepvhz5THwf+CLOusmnt1iKhqjyT0keayUJRuUDIJXmWUIn6wk/hsiMClV+5UjO8bzldWc7ilskpvMMBH6LD5d+noQluvJ4l8tjrvgUgpXFynukk0CtMttciHKmhvlUIgDxecJb8w/rGrVueQrgHWaeCvHpW0FvB+QhlXDL3asQ==
console.dir(req.ip)
// => "127.0.0.1"
req.ips
037cAlzAqyMPf2JuGJH2fy7U/HC9TD+ga+i/t+jMbM4A3R8msM+pjgpDrsdTwi1PvLkbZns7rp40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nRHNgo0wlFATjRTm0AVWuCZKrUr/7RuInHoJfTNxk4N3cCq+qMqMdTkANzhyYMx5r0SCdVQ7uLkFehUz0EIzWYzAvrb5oE8WeeWEo/sTXT+XEjkkkaKzQfAUi3lwgmAgK6/P0MnYybqCiX86zeFr/d+jIVXMczJtz3IFLqvSQObF3Bz8iFMEtlJXr1UUNgnWacFQbH0scdX8Yy0eUJl3WsymhzRyhbCy+vejRWihkmRLY1fH5dyD9X7yU3ra6TigToJRz7yvceSfFomH4a/yW1S0yI80LLBlz3qthLBAwiCofsUh1XxN870m5ThUfRXDW1assP3lSeagRiWzwIcryATt0FdqW8etHylg==
// GET /search?q=something
console.dir(req.originalUrl)
// => "/search?q=something"
GaTx6MjTW3HWnP1vId+6LvraqTGygafnAu0824A7lDrGfiG48+pQyZAuAyzbWXmA4IoHzjBDeKNP7QsgQnXh04c0wNQuEi8H4OJOkxW4JuQiQtczL5ehJdo2A4d/zfwbM1FK0RziMKZuIU+7i25wAagQIRMpQsbNLR7GkPN7fiHxgPHu0gYUnQfPLESzEhsridAwUHiHCX6IDdKrol3aWSEOWL4OGiV+UgYnHKKILuk=
// GET 'http://www.example.com/admin/new?sort=desc'
app.use('/admin', (req, res, next) => {
console.dir(req.originalUrl) // '/admin/new?sort=desc'
console.dir(req.baseUrl) // '/admin'
console.dir(req.path) // '/new'
next()
})
req.params
pQtsVgzX4Wlriy0tAl8Ok4Frr1e0yx+hypsnJVEw9/ykruWJ2zNn3rqNFtOVGpAUQo0qXXI85Z5VsChL7oi0oPgiNSTaqGJQLucN02esUFhmVHfZ2pHDXOd7XJJBLwEz/SieT/TPb4zwr5U2AK+VSjB0ogaRS3HKX7JFfVDZH82PSCtt7ga72UxZ12dlzwoZD8PnHaa/puK0njSg4q5CFkhxynTAVTDGp3sG7NRgV5GJJjcT+LyFEy0T/WrQVYxIwPA57ClJW9TCy1MElmzHbVmGgitJIaWGRUIQ3HvmlZdblXe+h13OXliVQndpa8rp6QkvRGECKKmqmeBSEqqgKpyIq5l3Oj4mVrzIZkwuXSU8/08v/hv0FIAkZxqPMdn4
// GET /user/tj
console.dir(req.params.name)
// => "tj"
Vn8I062MpExQ/xlNBkGhab5EuGs73FrYRKtehOTPohczjwrlANhVju0Vwrw7iYLrJQ3xeQKzbPazWJcSSzcj1D1l9DZhYWOwinPEo/puG6hLpcXQrDOB9fopEycFMm1iGYkhKoD6bP7Uhtkys58kKPy8iACNh/NBDxuiileopEl/1DlKo80oxfasOQ9Vf2P1mScivfo+2u8IfaEI3NZXwqLZSwGR/cDluJkmlpkiKne4i4D90zSx3hdTwLQxMNWYsQzxyp59dO3LvlvC+G5a/TBJO+jjTAuFq6ITV8MEBKnN1oTNQ2eL5IsmG26D7k+PurgIJa1GNRHXyXCyImEJiAKqrWuhG7ge9htLjHvyT0M=
// GET /file/javascripts/jquery.js
console.dir(req.params[0])
// => "javascripts/jquery.js"
CMyfzLNJZrUlcHFBSDtMgvdDZ+LbcgwrzzrJUFLQqNdQbH7uW/uiV8yrExDDPxEd7Xv7+QeEsg8cwVvm8+teApB1mRGJ2av87d92sdZu2gaewlZCNiLCrfX+18Z8/CWMd1QvzdD4ybfvGFl6KhsYax7W+fQHssn8i3nxrC4ecdkTBVJlYi+j8NmeUguHGBbRKzZFym8G4YBSgk4BvLBhU+jQ1caeGmXYsbpqqJLmCiX41MvqUEauKTwBivqs1hxcpqDLgLSSCbXp/+lXiX+gGdA4NBDW/tcV0WCMnuk3oTHw114KApMbAyWVpDd1WkK5iH08MM/3ACO3RE8m2Rhf4w==
W42mVb62rBYz2pXLvBLmgolMfSy62fgF/jCuKucfFJFB2NbZlzlQ/9yF5tL4bkpoKR6SsxtNZhUCEMh0EWLJZCQ04652g0p4H1tFKO/GNlk1cWehSWRbZJu32yjRkA3LJ79PS7qXpR4B7ZyWvnUsuA==
NTW5j9kMzXlX+G60B/WceJZwyxoFMz+s4NZIYtQAnKHnkPXaI1DuB6TPYUMkNfjQjS7MZ/jT9ObzOmIMogzCO4wBVn8fkOSVX9c6yVCERahN4ZKudMSTZuDpMiPZqd1Hgy3+XT7qSRqmLWOedSSXRQ==
req.path
bRq87VxNG5+St2HKHlPFH9h+N+DyHjEVp9mvojSA7ND/uA0CkdlRFsSwhllGNxBS
// example.com/users?sort=desc
console.dir(req.path)
// => "/users"
ZzqpOuGbKO0HrOpGhboBcIul/CPtMbK7KUFvInFVC5Mq+DwBrtxTe+zxpNdZJLLA1GxBcENqS105dxNa/Ca/nKismhfN9xIZUzSi2h3lt1v/jivMhDCN2f7JxZghUp0/FoSiSXAHvTzArhl14eL5yixbOlGv8hMdu5FlVi8KsL8tR3XRvLcgvivDeAv6pfm+rLLa7sAqR7mQxOGMVf2V2M9l+YzCtgBfr/DzdD218Ys=
req.protocol
H17HOl8dOVoFCEg8EpQU0aOVn1uqnQDQ9Y4vbn2xG3Z3sxvrVQWJpSGjcpRJ26gMb5IMPckg7pCiCjfOLPXVnT9uYh6abWV/n8NWgii9DBPfm5vftz0o0knHqjbgEYku
037cAlzAqyMPf2JuGJH2fy7U/HC9TD+ga+i/t+jMbM4A3R8msM+pjgpDrsdTwi1PvLkbZns7rp40CcDVWwb+YLWHImy4d/zDfaU6IbA2a4Axhy2cxHDd4gbkmyTBRfNrxDi0Yx+KHLpzOkKfdUn4Vo7Fy+eCGnmz8hqaLKtP7qHGwNKwlOfcyC3YUV+g+kQjs0hthKUvqTjSioCE9aMOOQ2bUjCvLEO4TVjh69ZJHbKFOp0lQBQc1A78rvLtaqD38kdVl5BKJ0Rrk2OzW94FMNXlyTZy3P3nnJPE0Z8muvDlqcEGBl7ce06I1tjo+bqpZWi5W/ySZZwEjz7reVlm4fRwUXTq18IAUxnSHnSndQs=
console.dir(req.protocol)
// => "http"
req.query
pQtsVgzX4Wlriy0tAl8Ok5OywBs1gn1eHuf5O5142IDK4FLYvEumeUmwk9up2UR7jejTcDA6xI049NQuF0EOTiDZwGCLpbJs7B/GslpadWx3HMsowXiDt1IxZLwPM3hyNoM2EzXawX1tzKjLnUx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Cdxml9rKt/WZURf/ar9SDPXTLhucTLKD2FPHQgTF2pBcJYM8Xy+MA+t7lnz+7a9JZaTD05AM/ESkdSjAFFx2WwfnMHK4wP3+pJWSVwD4iBUPeCJK/Kc3APoldKOOhAUm57zdFvSZlVDHgWSmOQ7ERF8l2xvmXUpzLsL5m4XqRwh0KTvMfZhx9AAcCzk4l4AKYcZ8L/w9CM7vXT8/53KJ3wqw58TEm6XYGGo230wMsWQj2652Xd/UlzSijvo1TBuN4wPiWAeibTO46fDLeYhVZlE713tJ2Co5Kcq0q8SwYB1dU=
const qs = require('qs')
app.setting('query parser',
(str) => qs.parse(str, { /* custom options */ }))
xuu7IDQrdDS8aOZtgxsAzYxkxFMXgT1GGKkz/HyXrji0K7PXGZdhtQfFLNZMseC31anbxHdX8OOhubTqSnyqLrogsz5YK6kg8suK9ELF0LbZdCUUWyZRtYfT8QAuWVQuifEyH+LJ8XvRCgIywNf69KMSoQQsRI3FpmyMtceemrg=
req.res
B0Y2h48Xu5+yWZnT7DQ5LLzc2pXKuCmv2T5Kv13FizEoJ93/wHt1tt6WB/buPp7/FYdafFiTTsENwMGFmJ4xw+4YVVnXNVe04GQCGU2viotG65i4KOVXztlDz7kfnwxMpdoRmdZcpoJtGHzQ71L2upToe+o9436fBxFYffBBQ04=
req.route
8VID1cYaBXYrXVuxGTMkPmoWGt5ZgRT7rXU82ymzvd2OKI4lOCxzhk0JeW3yBdfUeFXaGJ0+pB6f86lqCTbAQg==
app.get('/user/:id?', (req, res) => {
console.log(req.route)
res.send('GET')
})
sGkJOgUtyHH5mL1h1gYSHFihwmChP5UzYqkXXnrGS2xyvpnWlQQyBxVy8YTAYWXs
{ path: '/user/:id?',
stack:
[ { handle: [Function: userIdHandler],
name: 'userIdHandler',
params: undefined,
path: undefined,
keys: [],
regexp: /^\/?$/i,
method: 'get' } ],
methods: { get: true } }
req.secure
aCqAQ+Fqd7hkNpeEerrHjQP11PNfoJKwD9OeWgeU/Uifz82dVoRXnL4H9Pf7tLj831TvopjU7jfdYAVT7Wb3eLltuml7s0EHB0S02xG1SvVuSHRh+ZUT3mq+MxYvFXFo
req.protocol === 'https'
req.signedCookies
BpDIkXRUnkPiBz8iBceshHRho+n2gRQ/Ye0EOGheBhDUobeNi1kK4uP4CBLDHFAkUXNBvfKktLS9DV+CYNGZbJnI8zl7E8t0uauViSrVpahwlwk1c8vlqYRU5fxHG4cHr82oVJo6oC4+la1XdDtkHX2IC2Z2+kUtLIQHP2y9gb03l13veHMSDKGKjVS8ERs9QM9HWoB0/XhVg8twppHQQ+7W/TkBm+zE7VEjo+QFerMUeCE+iE6gfE5rqHEXAyuISy3Y81yZhW72AgLi40Zd2Kem4BKlUe0ELrIGfu5X/RXnWr00o+WtPWRn2yA87c5vF2lgzeCYIYJFwDPAlYI16MiKLE8B+9YQpzh5ZHOzrbBen5jwsy1GT0oZ8QFaUXLwBZOYU6dDmkGKrfL4RsUB2XWP4FpzNUY7TSWqKxq8xPbkOH1uKrCoCpKphIsP3xt6LzvgdNLJliNHoFv2kPHzwPg9+HGztNfer8hTQMQx9hgEgi14MZlJJymgGItCmT5RW60JfdR9iiToci8PB2MzEsjvhfgL57DjuAuhwOi3Q0rTdpPkoj32+QR2yrScSnItSHfeD4OYW+zCuiLn3MXzLw0ZUMHm1VjyE9+ru9V/R9i7tRa/Kb371vxhp3baCOf+
o7bKJJuxIKU76Am5eiTNMOJiFGJXD3+f6VhTXWBjrDyxkHvc9LkmvjCBih9Tt6y74YNnMk+467cS5UHjBhF0lJV+uKSAs/y16uZDUwD5390=
// Cookie: user=tobi.CP7AWaXDfAKIRfH49dQzKJx7sKzzSoPq7/AcBBRVwlI3
console.dir(req.signedCookies.user)
// => "tobi"
vLQ6D36bWQ06eLzFTMHAxKaZxH3b9Qa+BBdXc9GjSgEZN70crj60HbX4lL6sgLOHEtNuSjBJIUH6gj2zGZS/xl8f7irZC8Tf++DMvQcdmIbvYCD2ShPXIarxvGNhThiyOHZmw7zLIH2eP54AOlF8LoLjZyvIhhoYiMp/yTilKQ4=
req.stale
ffqa3DwI54yWedHbNB3K2OL9MBLv5sISdnJ9j5DPfl6NU3NLmqUp+XMA0wEoNvH+83k+uQtbsHqZTSXcN6Mkcx225ovr3Jq63taz2ObHpq9IjeR4jtOU8DDeI9fFyAZS1SuKgVNaeelrCvCuUKZa1mRFJyfN5cq1Nw1ZseZ+LrjATlg9b9F966gpQrpSLnuBWd9iOLF+/A0KVQjYXNSlSQ==
console.dir(req.stale)
// => true
req.subdomains
9u7uXf9bP09ZavqsmtsJ5OGPVg/ayanJ0ummkQTgtJP2u4q5/jfaC+PtR4drLeLI
// Host: "tobi.ferrets.example.com"
console.dir(req.subdomains)
// => ["ferrets", "tobi"]
JrmE6zcd4AdTuouISKWc4q4stkl+O17VtcwpAMrlk3LiYeETmGJGHXejhxpuKWHlbYyJt+kSHXttJb4qet2etxYAMFzvcgpV9k2lgESeTdEkB8PHW8pnokY9bQtkiZZjg7N2zNp3CfN+3xIQo0HPPA1u1Nf+csI9fri5E5jPX8Ew+kTIIVWWwqUaaQgcaaa3LgRvV/jmXc8d4+xP/1cnvEu1zjI1k8twbDukLVdanNyagtFjb9WyltnMTXTQMag7rnKyqTr0e+9m4qGpFa0hmA==
req.xhr
TVT8ciczgyL/aHiQaL7uYuv6tWh+30zI1RB4R1DBjsNlPd0gR5QtBikHFuJbLTB78XYWiXWMLOnxgmmGz86Ebl/gcR0x7/fuB6aOtFp9GvUnzKB1q1ym4EAJVBckRT048grfmRsgW18Ns772hvB9gbq7fb4StetXDfE5N1XDFstV+OCX8335VnPv11PIoK2qM6EcNgIT6HlpG7o/g7BwoZmfe567qIiae0VxHwnLhTGlmlfKX8px9CZPCS6413GW
console.dir(req.xhr)
// => true
req.accepts(types)
cD7gDkor3TG++WgEHxoc/hYtDnQp9igLS94exRuYr/wauq8JjvKrlXveU2rJ5xapzs17MV75BSAZ7elhsc30NQm62ovx3SxyzJy8QH1WxdJhT5/HOB4yygNRhJs//S+lLUz7Val4adD52sFkJuWc2HDB39tHEt5eP+Hc6goOwOFrtP/Gurbz4AS07aJ9Wv/llN5wNe/TQPb+TpYcxG+Thph63OeKRGc4pkq6YgGk/CCviwrsHXA01L04qdqmT0kAN2ZOTKZ1IKY/smw8QsHgIsLajNxFH/22f4UEtdXY8xudJAZFzmvEN+bX6X+ZZvFB2ARgGb8v2gVkAW2TJCOR7FUUb6w6bA8v7WR+8TqOa8q0fiOBwQRaquCZIPj70fSWlNgjyc9U8xEOqnF9sbt9fw==
KgX2FNZy2CgemGmp0FiQ8TXR66j/xenfNyUbwBFelyWuf/QYyMXTQ53WArevomZn2ZELFhpe6rfp4V7J9ej+VhnOwLWjkTmsJ9RWuUg6UdzGJ4CKswUAqmp/mL8GPy1pA7M2ZYnWn0BwOU7AxrZ8AEQPXtUfD0Ndvi3tKumVDZca/ydJR9kms2sfbjM21pn7FVdqsVxUnE0Rw2Y38qMC4B9giMqoFMgfDeTL36/h3UOx0MvoCCxC4Jt4i4Ni5GKHmXTLJHMq5k7AQOXX9RMA5WGp01mTee1e5WDJdlmTPIk/VZj/LF+jJ5L/LB89+iQt
// Accept: text/html
req.accepts('html')
// => "html"
// Accept: text/*, application/json
req.accepts('html')
// => "html"
req.accepts('text/html')
// => "text/html"
req.accepts(['json', 'text'])
// => "json"
req.accepts('application/json')
// => "application/json"
// Accept: text/*, application/json
req.accepts('image/png')
req.accepts('png')
// => false
// Accept: text/*;q=.5, application/json
req.accepts(['html', 'json'])
// => "json"
i5mH/polGS/9PLtgcrAy2vyzhQztu97ADJUyNEshuw3pSP9tk3OqdCBesgaJAdHl54nkjZ86A59NebvjLMuHwtnoqPCdD2SzSMG7LWryMcPr3IKxYntNZJYdKcYWoPiTiketin/JtpgB3RY+b4B/QmH/nDhzVg+NYez/sfIUdak=
req.acceptsCharsets(charset [, ...])
cD7gDkor3TG++WgEHxoc/sN1NsXHOu6LzGxtZaugFBJY/+KqQ14RbK1V/DEYKs4tGVmt0o2u+tkDtKTkyEi1m8MI4KJ7e3ped3fqmfD9ECbG+oLaFiyk7E8/lxi8gpIMNCmqzjpaLr7tjbrdsfXmIbMFqsO1MfU9NA32qa/FM8jiOPuugj35yIc66tM1HIcWTXmOBY8Pmw8qLJicSbKlDYS2j/RHUBj6dqyNbbYhco4caBIxH1lN3Ykv+YLTch7U
i5mH/polGS/9PLtgcrAy2vyzhQztu97ADJUyNEshuw3pSP9tk3OqdCBesgaJAdHl54nkjZ86A59NebvjLMuHwtnoqPCdD2SzSMG7LWryMcPr3IKxYntNZJYdKcYWoPiTiketin/JtpgB3RY+b4B/QmH/nDhzVg+NYez/sfIUdak=
req.acceptsEncodings(encoding [, ...])
cD7gDkor3TG++WgEHxoc/njgGvNtP8whLyUzz0EopoOnHFoiIysk8CfCOyi+bkic4Tm3gjTqkRQxzl4SA6olf764VW83jdqXv9wsZepARLmVxOp2KG1woW1O8saDHZF8lf36WbokBBMiCgUnKHHgLykK/xey+CPUa+DkYEC4W0TVs8wCp/14Xsgs5sX3t8gjKDhROiARjAkoRX4cHHEqIWXZkAyx6HD+nDOSMLn7cMMwk+KDqEWHuXUIJ5CKhTrQ
i5mH/polGS/9PLtgcrAy2vyzhQztu97ADJUyNEshuw3pSP9tk3OqdCBesgaJAdHl54nkjZ86A59NebvjLMuHwtnoqPCdD2SzSMG7LWryMcPr3IKxYntNZJYdKcYWoPiTiketin/JtpgB3RY+b4B/QmH/nDhzVg+NYez/sfIUdak=
req.acceptsLanguages(lang [, ...])
cD7gDkor3TG++WgEHxoc/m/AD8ct5tLfqlyiA02ncFx5V93yYMA8Jzsib6xhBNa4owZUvLK6slOE3N/evYl0qVmm22o2eab1ymaB/NUBD5xWyqo3c8j7Ymf1DUjuV2EBwll77QChmWgwXw6KsCqWnleh2ocWiNmskp6nT7RBSD2jBFPgxxm2ZeQIRSDdqZHRbqY+srxJgDlc7lg5MGRKGMc62g2Rk58GjAYSla+cAsUlvo5FT9970zbMfssSx37i
i5mH/polGS/9PLtgcrAy2vyzhQztu97ADJUyNEshuw3pSP9tk3OqdCBesgaJAdHl54nkjZ86A59NebvjLMuHwtnoqPCdD2SzSMG7LWryMcPr3IKxYntNZJYdKcYWoPiTiketin/JtpgB3RY+b4B/QmH/nDhzVg+NYez/sfIUdak=
req.get(field)
DDrHS6idc1uQdV8dy1scJjwJRc1H1nDuLotF3exMjVVewCuC5m3XRPsNoj1rhUT0whfjkF2Ok93dstsITmDFKYblzRcM6nRVIZDXdL2fCQYan4R3E5+UT2eupBFZXYHTH7hF9fr8b5VubztCkT8AdHDd1Imd34BuTJrJybLw4HPjHvohFZ6+RUggGHWVnLZ9
req.get('Content-Type')
// => "text/plain"
req.get('content-type')
// => "text/plain"
req.get('Something')
// => undefined
wRyUjsLDVE8WOzo7+RSrXK7drHUDS5nGqG1QAlZ7G4t4pcnyaMPvCZOsrNjtemqA
req.is(type)
HgqMU3Zu6GrJn624mUGy6ni0jSS6Fw3wCdU0uHXGJ/KuIufgaulSYzlku8tLCjYEC2lqkUDn3YH+clEt2TzSiym+MUXPAqxcEAzFwcngOeeuh4z2+JQmezB++bsHZvgxwoB+zNCOyYI2UsHXtHbxa8z5Jpie6xwD+LJIRmVLukILvUaS/eR4Y+VqY0nvXo0u8kyXxz2XBUBO/nMrzw8fs3Sjsf6je+ubkQlQjibnP4r5MjcJRM8y+v3utTP8mKccWlVVDPJcOtjGDFCJutRmRt69CUgWmMlL7GpjRV91eWrm3eoQN1wOxNC5ekfPN5ou
// With Content-Type: text/html; charset=utf-8
req.is('html') // => 'html'
req.is('text/html') // => 'text/html'
req.is('text/*') // => 'text/*'
// When Content-Type is application/json
req.is('json') // => 'json'
req.is('application/json') // => 'application/json'
req.is('application/*') // => 'application/*'
req.is('html')
// => false
i5mH/polGS/9PLtgcrAy2vyzhQztu97ADJUyNEshuw3pSP9tk3OqdCBesgaJAdHl54nkjZ86A59NebvjLMuHwnjlLsvO+aNtr/cU0X7a5+rvw3Prx6Y/YrW0vvd/WK2c6EXE9NrSupWS3fpWtKw1Xtg3hYLKvT9HKPai+1TMjq8=
req.range(size[, options])
eUCwoB3pVYyzlam+XzWNG4+5P3X+4eM195VsrWg9YVFJ9CAPnpSV08cCrtE9zy2f
IYTTHrEzZpsVo1CmUlHnSvuUYJ5B7xFFWv6dfJDEnTIKkeYcbGIUzS9PP1l+KSSS9wem3+j4/oTKaMgyHfr7Cg==
MgO71yypnOaPB2lZbuh367cVTn/kf2wiFjadRW0QZie3z4xyBRy1hz3nb/hvwobWaZi7wzpxuCK+IMG7THg0yBKhZXHI+FKVEhSP4KTwgqA=
属性 | 类型 | 描述 |
---|---|---|
combine | 布尔值 | 指定是否应合并重叠和相邻范围,默认为 false 。当 true 时,范围将被组合并返回,就好像它们在标题中以这种方式指定一样。 |
JqaF53yvaUqUb9txDrhTZ4u55UUqtDEsSCH/3aXnuzfbTsxZBBVmFcWV+YsbieWEGyoNeSuyPEErcavyZtjTrg==
- SdtQvIq+iG6Yjjw0J6XunbSV3d7+p+I4koa/24wbtYT8gfR8zxmNYka+H5vf5fFEFbyARz/jei8RCB2FImcriaBpyAPIps+QPK0+UvUXMXiJoG2j17FJpmdqxWMAprqtyy7tAYbbdqO66uCo6hskZ5M5rH5Tw4TMhORmW7ohsyM=
// parse header from request
const range = req.range(1000)
// the type of the range
if (range.type === 'bytes') {
// the ranges
range.forEach((r) => {
// do something with r.start and r.end
})
}