python - keep-alive的http会话中用新的cookie、user-agent发起请求会怎样?
怪我咯
怪我咯 2017-04-18 10:16:32
0
1
590

我理解keep-alive的http会话中多次请求在“合理”的情况下是不会出现cookie、user-agent被改变的情况的,但一些hack方法确实可以改变它们;如果上述前提是正确的,那么http协议以及主流的http server对这类情形的处理有成型方案吗?

这主要是个http协议、http server的问题,因为对python比较熟悉,所以拿python的requests包写示例代码。

import requests
# 全局变量Session实例
s = requests.Session()
s.mount('http://', requests.adapters.HTTPAdapter(pool_connections=1, pool_maxsize=1, max_retries=0, pool_block=False))

# 访问url获取响应
def openUrl(url, headers):
    r = s.get(url, headers = headers, allow_redirects = False)
    return r

url = "https://www.example.com"

# 同一个会话中,两次请求,不同的ua和cookie
headers = {'user-agent': 'ua1', "cookie": "sid: 1"}
r1 = openUrl(url, headers = headers)

headers = {'user-agent': 'ua2', "cookie": "sid: 2"}
r2 = openUrl(url, headers = headers)

apache、nginx等会对r2做非法处理吗?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(1)
刘奇

Tragic questioner, you have misunderstood the concept.

Cookies are processed and analyzed by background applications. Whether you mess with cookies or delete them. Neither apache nor nginx will care about this.

In addition, keep-alive is an operation of the connection layer. Basically it has nothing to do with the HTTP layer. If N websites are built on a certain server, and you use a TCP link to request website A and maintain the TCP connection, and continue to request website B, the http server will not care about you.

Any questions?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!