from webob import Request
from pprint import pprint
requests=[]
httpbin='httpbin.org'
task1=Request.blank('wikipedia.org')
task1.host='ru.wikipedia.org'
task1.environ['SERVER_NAME']='wikipedia.org'
task1.accept='text/html'
task1.user_agent="User-Agent: Mozilla/5.0 (X11; U; Linux i686; ru; rv:1.9b5) Gecko/2008050509 Firefox/3.0b5"
requests.append(task1)
task2_1=Request.blank('ip')
task2_1.host=httpbin
task2_1.environ['SERVER_NAME']=httpbin
task2_1.accept='*/*'
requests.append(task2_1)
task2_2=Request.blank('get?foo=bar&1=2&2/0&error=True')
task2_2.host=httpbin
task2_2.environ['SERVER_NAME']=httpbin
task2_2.accept='*/*'
requests.append(task2_2)
task2_3=Request.blank('post')
task2_3.host=httpbin
task2_3.environ['SERVER_NAME']=httpbin
task2_3.method='POST'
task2_3.content_type='application/x-www-form-urlencoded'
text = 'foo=bar&1=2&2%2F0=&error=True'.encode('ascii')
task2_3.body=text
task2_3.content_length=len(text)
task2_3.headers['Connection']='close'
requests.append(task2_3)
task2_4=Request.blank('cookies/set?country=Ru')
task2_4.host = httpbin
task2_4.environ["SERVER_NAME"] = httpbin
task2_4.accept = '*/*'
task2_4.headers['Connection'] = 'close'
requests.append(task2_4)
task2_5=Request.blank('cookies')
task2_5.host=httpbin
task2_5.environ['SERVER_NAME']=httpbin
task2_5.accept='*/*'
task2_5.headers['Connection']='close'
requests.append(task2_5)
task2_6 = Request.blank('redirect/4')
task2_6.host = httpbin
task2_6.environ["SERVER_NAME"] = httpbin
task2_6.accept = '*/*'
task2_6.headers['Connection'] = 'close'
requests.append(task2_6)
post = Request.blank("post")
post.host = 'httpbin.org'
post.environ["SERVER_NAME"] = 'httpbin.org'
post.method = 'POST'
text = "firstname=Alexandr&lastname=Vakhtin&group=FO-340001&message=good".encode('ascii')
post.content_length = len(text)
post.content_type = "application/x-www-form-urlencoded"
post.body = text
post.headers['Connection'] = 'close'
requests.append(post)
for request in requests:
response=request.get_response()
response.content_type = 'text/plain'
response.charset = 'utf-8'
print(request)
print
print
print
print(response)
GET wikipedia.org HTTP/1.0
Accept: text/html
Host: ru.wikipedia.org
User-Agent: User-Agent: Mozilla/5.0 (X11; U; Linux i686; ru; rv:1.9b5) Gecko/2008050509 Firefox/3.0b5
301 TLS Redirect
Server: Varnish
Location: https://ru.wikipedia.org/wikipedia.org
Content-Length: 0
Accept-Ranges: bytes
Date: Sat, 29 Oct 2016 17:10:08 GMT
X-Varnish: 1988242610
Age: 0
Via: 1.1 varnish
Connection: close
X-Cache: cp3042 int
X-Cache-Status: int
Set-Cookie: WMF-Last-Access=29-Oct-2016;Path=/;HttpOnly;secure;Expires=Wed, 30 Nov 2016 12:00:00 GMT
X-Client-IP: 5.189.102.65
Set-Cookie: GeoIP=RU:SVE:Yekaterinburg:56.86:60.61:v4; Path=/; secure; Domain=.wikipedia.org
Content-Type: text/plain; charset=utf-8
GET ip HTTP/1.0
Accept: */*
Host: httpbin.org
200 OK
Server: nginx
Date: Sat, 29 Oct 2016 17:10:08 GMT
Content-Length: 31
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Content-Type: text/plain; charset=utf-8
{
"origin": "5.189.102.65"
}
GET get?foo=bar&1=2&2/0&error=True HTTP/1.0
Accept: */*
Host: httpbin.org
200 OK
Server: nginx
Date: Sat, 29 Oct 2016 17:10:09 GMT
Content-Length: 317
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Content-Type: text/plain; charset=utf-8
{
"args": {
"1": "2",
"2/0": "",
"error": "True",
"foo": "bar"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "identity",
"Content-Length": "0",
"Host": "httpbin.org"
},
"origin": "5.189.102.65",
"url": "http://httpbin.org/get?foo=bar&1=2&2%2F0&error=True"
}
POST post HTTP/1.0
Connection: close
Content-Length: 29
Content-Type: application/x-www-form-urlencoded
Host: httpbin.org
foo=bar&1=2&2%2F0=&error=True
200 OK
Server: nginx
Date: Sat, 29 Oct 2016 17:10:09 GMT
Content-Length: 389
Connection: close
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Content-Type: text/plain; charset=utf-8
{
"args": {},
"data": "",
"files": {},
"form": {
"1": "2",
"2/0": "",
"error": "True",
"foo": "bar"
},
"headers": {
"Accept-Encoding": "identity",
"Content-Length": "29",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org"
},
"json": null,
"origin": "5.189.102.65",
"url": "http://httpbin.org/post"
}
GET cookies/set?country=Ru HTTP/1.0
Accept: */*
Connection: close
Host: httpbin.org
302 FOUND
Server: nginx
Date: Sat, 29 Oct 2016 17:10:09 GMT
Content-Length: 223
Connection: close
Location: /cookies
Set-Cookie: country=Ru; Path=/
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Content-Type: text/plain; charset=utf-8
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
<p>You should be redirected automatically to target URL: <a href="/cookies">/cookies</a>. If not click the link.
GET cookies HTTP/1.0
Accept: */*
Connection: close
Host: httpbin.org
200 OK
Server: nginx
Date: Sat, 29 Oct 2016 17:10:10 GMT
Content-Length: 20
Connection: close
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Content-Type: text/plain; charset=utf-8
{
"cookies": {}
}
GET redirect/4 HTTP/1.0
Accept: */*
Connection: close
Host: httpbin.org
302 FOUND
Server: nginx
Date: Sat, 29 Oct 2016 17:10:10 GMT
Content-Length: 247
Connection: close
Location: /relative-redirect/3
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Content-Type: text/plain; charset=utf-8
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
<p>You should be redirected automatically to target URL: <a href="/relative-redirect/3">/relative-redirect/3</a>. If not click the link.
POST post HTTP/1.0
Connection: close
Content-Length: 64
Content-Type: application/x-www-form-urlencoded
Host: httpbin.org
firstname=Alexandr&lastname=Vakhtin&group=FO-340001&message=good
200 OK
Server: nginx
Date: Sat, 29 Oct 2016 17:10:10 GMT
Content-Length: 426
Connection: close
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Content-Type: text/plain; charset=utf-8
{
"args": {},
"data": "",
"files": {},
"form": {
"firstname": "Alexandr",
"group": "FO-340001",
"lastname": "Vakhtin",
"message": "good"
},
"headers": {
"Accept-Encoding": "identity",
"Content-Length": "64",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org"
},
"json": null,
"origin": "5.189.102.65",
"url": "http://httpbin.org/post"
}