获取传入请求的HTTP版本

时间:2016-06-15 08:09:21

标签: node.js http express

如何使用express提取传入请求的HTTP版本?

我需要类似的东西:

app.use('/', (req, res, next) => {
    req.getHttpVersion() // 'HTTP 1.0'/'HTTP 1.1'/'HTTP 2.0'
});

2 个答案:

答案 0 :(得分:7)

试试这个:

app.use('/', (req, res, next) => {
    console.log('Request HTTP Version: ', req.httpVersion)
});

答案 1 :(得分:0)

我知道这是旧的,但仍然.. 您可以尝试:

def count_users(group):
    count = 0
    for member in get_members(group):
    #count += 1
        if is_group(member):
            count += count_users(member)
        else:
            count+=1
    return count

print(count_users("sales")) # Should be 3
print(count_users("engineering")) # Should be 8
print(count_users("everyone")) # Should be 18