[squeak-dev] The Trunk: WebClient-Tests-jr.49.mcz

commits at source.squeak.org commits at source.squeak.org
Tue Jan 3 14:12:12 UTC 2017


Tobias Pape uploaded a new version of WebClient-Tests to project The Trunk:
http://source.squeak.org/trunk/WebClient-Tests-jr.49.mcz

==================== Summary ====================

Name: WebClient-Tests-jr.49
Author: jr
Time: 3 January 2017, 2:02:24.562318 pm
UUID: 69152681-25b5-e84a-9c59-c68167eaff09
Ancestors: WebClient-Tests-topa.48

add test for chunk stream reading

=============== Diff against WebClient-Tests-topa.48 ===============

Item was added:
+ ----- Method: WebClientServerTest>>testChunkedLoopbackWithStream (in category 'tests - chunked') -----
+ testChunkedLoopbackWithStream
+ 	"Test HTTP loopback streaming using chunked transfer-encoding"
+ 
+ 	| queue response stream |
+ 	queue := SharedQueue new.
+ 	server addService: '/recv' action:[:req |
+ 
+ 		"The /recv service establishes the write-end for the server.
+ 		In a real environment we would access protect the request
+ 		and also pass a token to be used to link the incoming /send
+ 		request from the client."
+ 
+ 		req sendResponse: 200 chunked:[:writeEnd|
+ 			| chunk |
+ 			"There is no reason to wait for the client to send a request,
+ 			the protocol is entirely freestyle. Send something just because
+ 			we can"
+ 			writeEnd nextChunkPut: 'Initial response'.
+ 			"And from here on echo any incoming data"
+ 			[chunk := queue next.
+ 			chunk == nil] whileFalse:[writeEnd nextChunkPut: chunk].
+ 			"And some final data"
+ 			writeEnd nextChunkPut: 'Final response'.
+ 		].
+ 	] methods: #('GET'). "only allow GET requests"
+ 
+ 	server addService: '/send' action:[:req |
+ 
+ 		"The /send service establishes the read-end for the server.
+ 		Simply read the chunks as they come in and stick them in
+ 		our loopback queue to send them back to the client."
+ 
+ 		| chunk |
+ 		[chunk := req nextChunk.
+ 		chunk == nil] whileFalse:[queue nextPut: chunk].
+ 		queue nextPut: nil. "end conversation"
+ 		req send200Response: 'ok'.
+ 	] methods: #('POST'). "only allow POST requests"
+ 
+ 	"Establish the server response stream"
+ 	response := WebClient new httpGet: self localHostUrl, '/recv'.
+ 	self assert: response code = 200.
+ 	self assert: (response headerAt: 'Transfer-Encoding') = 'chunked'.
+ 	stream := response contentStream.
+ 	self assert: (stream next: 'Initial response' size) equals: 'Initial response'.
+ 
+ 	"Establish the client request stream"
+ 	WebClient 
+ 		httpPostChunked: self localHostUrl, '/send'
+ 		content:[:request|
+ 			"We've set up both ends, try our loopback server"
+ 			request nextChunkPut: 'Hello World'.
+ 			self assert: (stream next: 'Hello World' size) equals: 'Hello World'.
+ 			request nextChunkPut: 'The answer is 42'.
+ 			self assert: (stream next: 'The answer is 42' size) equals: 'The answer is 42'.
+ 		] type: nil.
+ 
+ 	self assert: (stream next: 'Final response' size) equals: 'Final response'.
+ !



More information about the Squeak-dev mailing list