Added support for chunked transfer-encoding response.

Implemented correctly the redirection support for NET_HTTP_CLIENT...
Added the possibility to use HTTP/1.0 .
Splitted the manual tests that were using during development.
First step to redesign and clean the new code.
This commit is contained in:
2015-09-10 23:05:56 +02:00
parent 9cd0f0b117
commit 29c4931dc0
8 changed files with 425 additions and 202 deletions

View File

@@ -16,122 +16,175 @@ feature {NONE} -- Initialization
make
-- Run application.
do
requestbin_path := "/15u47xi2"
test_1
test_2
test_3
test_4
test_5
test_6
test_7
end
requestbin_path: STRING
feature -- Tests
test_1
local
sess: NET_HTTP_CLIENT_SESSION
h: STRING_8
l_ctx: HTTP_CLIENT_REQUEST_CONTEXT
l_test_case: INTEGER
l_requestbin_path: STRING
do
l_requestbin_path := "/15u47xi2"
create h.make_empty
l_test_case := 1 -- select which test to execute
inspect l_test_case
when 1 then
-- URL ENCODED POST REQUEST
-- check requestbin to ensure the "Hello World" has been received in the raw body
-- also check that User-Agent was sent
create sess.make("http://requestb.in")
if attached sess.post (l_requestbin_path, Void, "Hello World").headers as hds then
across
hds as c
loop
h.append (c.item.name + ": " + c.item.value + "%R%N")
end
create h.make_empty
create sess.make("http://requestb.in")
if attached sess.post (requestbin_path, Void, "Hello World").headers as hds then
across
hds as c
loop
h.append (c.item.name + ": " + c.item.value + "%R%N")
end
print (h)
when 2 then
end
print (h)
end
test_2
local
sess: NET_HTTP_CLIENT_SESSION
h: STRING_8
l_ctx: HTTP_CLIENT_REQUEST_CONTEXT
do
-- POST REQUEST WITH FORM DATA
-- check requestbin to ensure the form parameters are correctly received
create sess.make("http://requestb.in")
create l_ctx.make
l_ctx.form_parameters.extend ("First Value", "First Key")
l_ctx.form_parameters.extend ("Second Value", "Second Key")
create sess.make("http://requestb.in")
if attached sess.post (l_requestbin_path, l_ctx, "").headers as hds then
across
hds as c
loop
h.append (c.item.name + ": " + c.item.value + "%R%N")
end
create sess.make("http://requestb.in")
create l_ctx.make
l_ctx.form_parameters.extend ("First Value", "First Key")
l_ctx.form_parameters.extend ("Second Value", "Second Key")
create sess.make("http://requestb.in")
create h.make_empty
if attached sess.post (requestbin_path, l_ctx, "").headers as hds then
across
hds as c
loop
h.append (c.item.name + ": " + c.item.value + "%R%N")
end
end
print (h)
end
when 3 then
test_3
local
sess: NET_HTTP_CLIENT_SESSION
h: STRING_8
l_ctx: HTTP_CLIENT_REQUEST_CONTEXT
do
-- POST REQUEST WITH A FILE
-- check requestbin to ensure the form parameters are correctly received
-- set filename to a local file
create sess.make("http://requestb.in")
create l_ctx.make
l_ctx.set_upload_filename ("C:\temp\test.txt")
if attached sess.post (l_requestbin_path, l_ctx, "").headers as hds then
across
hds as c
loop
h.append (c.item.name + ": " + c.item.value + "%R%N")
end
create sess.make("http://requestb.in")
create l_ctx.make
l_ctx.set_upload_filename ("C:\temp\test.txt")
create h.make_empty
if attached sess.post (requestbin_path, l_ctx, "").headers as hds then
across
hds as c
loop
h.append (c.item.name + ": " + c.item.value + "%R%N")
end
end
print (h)
end
when 4 then
test_4
local
sess: NET_HTTP_CLIENT_SESSION
h: STRING_8
l_ctx: HTTP_CLIENT_REQUEST_CONTEXT
do
-- PUT REQUEST WITH A FILE
-- check requestbin to ensure the file is correctly received
-- set filename to a local file
create sess.make("http://requestb.in")
create l_ctx.make
l_ctx.set_upload_filename ("C:\temp\test.txt")
if attached sess.put (l_requestbin_path, l_ctx, "").headers as hds then
across
hds as c
loop
h.append (c.item.name + ": " + c.item.value + "%R%N")
end
create sess.make("http://requestb.in")
create l_ctx.make
l_ctx.set_upload_filename ("C:\temp\test.txt")
create h.make_empty
if attached sess.put (requestbin_path, l_ctx, "").headers as hds then
across
hds as c
loop
h.append (c.item.name + ": " + c.item.value + "%R%N")
end
end
print (h)
end
when 5 then
test_5
local
sess: NET_HTTP_CLIENT_SESSION
h: STRING_8
l_ctx: HTTP_CLIENT_REQUEST_CONTEXT
do
-- POST REQUEST WITH A FILE AND FORM DATA
-- check requestbin to ensure the file and form parameters are correctly received
-- set filename to a local file
create sess.make("http://requestb.in")
create l_ctx.make
l_ctx.set_upload_filename ("C:\temp\logo.png")
l_ctx.form_parameters.extend ("First Value", "First Key")
l_ctx.form_parameters.extend ("Second Value", "Second Key")
if attached sess.post (l_requestbin_path, l_ctx, "").headers as hds then
across
hds as c
loop
h.append (c.item.name + ": " + c.item.value + "%R%N")
end
create sess.make("http://requestb.in")
create l_ctx.make
l_ctx.set_upload_filename ("C:\temp\logo.png")
l_ctx.form_parameters.extend ("First Value", "First Key")
l_ctx.form_parameters.extend ("Second Value", "Second Key")
create h.make_empty
if attached sess.post (requestbin_path, l_ctx, "").headers as hds then
across
hds as c
loop
h.append (c.item.name + ": " + c.item.value + "%R%N")
end
end
print (h)
end
when 6 then
test_6
local
sess: NET_HTTP_CLIENT_SESSION
h: STRING_8
l_ctx: HTTP_CLIENT_REQUEST_CONTEXT
do
-- GET REQUEST, Forwarding (google's first answer is a forward)
-- check headers received (printed in console)
create sess.make("http://google.com")
if attached sess.get ("/", Void).headers as hds then
across
hds as c
loop
h.append (c.item.name + ": " + c.item.value + "%R%N")
end
create sess.make("http://google.com")
create h.make_empty
if attached sess.get ("/", Void).headers as hds then
across
hds as c
loop
h.append (c.item.name + ": " + c.item.value + "%R%N")
end
print (h)
when 7 then
-- GET REQUEST WITH AUTHENTICATION, see http://browserspy.dk/password.php
-- check header WWW-Authendicate is received (authentication successful)
create sess.make("http://test:test@browserspy.dk")
if attached sess.get ("/password-ok.php", Void).headers as hds then
across
hds as c
loop
h.append (c.item.name + ": " + c.item.value + "%R%N")
end
end
print (h)
else
end
print (h)
end
test_7
local
sess: NET_HTTP_CLIENT_SESSION
h: STRING_8
l_ctx: HTTP_CLIENT_REQUEST_CONTEXT
do
-- GET REQUEST WITH AUTHENTICATION, see http://browserspy.dk/password.php
-- check header WWW-Authenticate is received (authentication successful)
create sess.make("http://test:test@browserspy.dk")
create h.make_empty
if attached sess.get ("/password-ok.php", Void).headers as hds then
across
hds as c
loop
h.append (c.item.name + ": " + c.item.value + "%R%N")
end
end
print (h)
end
end
end

View File

@@ -7,49 +7,27 @@ note
revision: "$Revision$"
testing: "type/manual"
class
TEST_HTTP_CLIENT
deferred class
TEST_HTTP_CLIENT_I
inherit
EQA_TEST_SET
feature -- Factory
new_session (a_url: READABLE_STRING_8): HTTP_CLIENT_SESSION
deferred
end
feature -- Test routines
test_libcurl_http_client
test_http_client
-- New test routine
local
sess: LIBCURL_HTTP_CLIENT_SESSION
sess: like new_session
h: STRING_8
do
create sess.make ("http://www.google.com")
if attached sess.get ("/search?q=eiffel", Void) as res then
assert ("Get returned without error", not res.error_occurred)
create h.make_empty
if attached res.headers as hds then
across
hds as c
loop
h.append (c.item.name + ": " + c.item.value + "%R%N")
end
end
if attached res.body as l_body then
assert ("body not empty", not l_body.is_empty)
else
assert ("missing body", False)
end
assert ("same headers", h.same_string (res.raw_header))
else
assert ("Not found", False)
end
end
test_socket_http_client
-- New test routine
local
sess: NET_HTTP_CLIENT_SESSION
h: STRING_8
do
create sess.make ("http://www.google.com")
sess := new_session ("http://www.google.com")
if attached sess.get ("/search?q=eiffel", Void) as res then
assert ("Get returned without error", not res.error_occurred)
create h.make_empty
@@ -71,13 +49,13 @@ feature -- Test routines
end
end
test_socket_http_client_requestbin
test_http_client_requestbin
local
sess: NET_HTTP_CLIENT_SESSION
sess: like new_session
h: STRING_8
do
--| Add your code here
create sess.make("http://requestb.in")
sess := new_session ("http://requestb.in")
create h.make_empty
if attached sess.get ("/1a0q2h61", Void).headers as hds then
across

View File

@@ -0,0 +1,43 @@
note
description: "[
Eiffel tests that can be executed by testing tool.
]"
author: "EiffelStudio test wizard"
date: "$Date$"
revision: "$Revision$"
testing: "type/manual"
class
TEST_LIBCURL_HTTP_CLIENT
inherit
TEST_HTTP_CLIENT_I
feature -- Factory
new_session (a_url: READABLE_STRING_8): HTTP_CLIENT_SESSION
do
create {LIBCURL_HTTP_CLIENT_SESSION} Result.make (a_url)
end
feature -- Tests
test_libcurl_http_client
do
test_http_client
end
test_libcurl_http_client_requestbin
do
test_http_client_requestbin
end
test_libcurl_headers
do
test_headers
end
end

View File

@@ -0,0 +1,42 @@
note
description: "[
Eiffel tests that can be executed by testing tool.
]"
author: "EiffelStudio test wizard"
date: "$Date$"
revision: "$Revision$"
testing: "type/manual"
class
TEST_NET_HTTP_CLIENT
inherit
TEST_HTTP_CLIENT_I
feature -- Factory
new_session (a_url: READABLE_STRING_8): HTTP_CLIENT_SESSION
do
create {NET_HTTP_CLIENT_SESSION} Result.make (a_url)
end
feature -- Tests
test_net_http_client
do
test_http_client
end
test_net_http_client_requestbin
do
test_http_client_requestbin
end
test_net_headers
do
test_headers
end
end