HTTPSocket>>#getResponseUpTo: and HTTPSocket>>#getResponseUpTo:ignoring: are ugly and misleading

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

HTTPSocket>>#getResponseUpTo: and HTTPSocket>>#getResponseUpTo:ignoring: are ugly and misleading

Peter Hugosson-Miller
Both these methods suffer from the same problem, and I speculate that this is due to copy/paste.

In both cases there is a local variable "response" which is set to a WriteStream on "buf" ( := String new: 2000).

However "response" is never written to using the methods on WriteStream, but "buf" is written to directly via the #primSocket:receiveDataInto: method. In several places, "response position" is used to determine how many characters have been read into "buf", and what's worse, the value of "response position" is updated using #instVarAt:put: (!!)

The methods have each two possible returns. In one, "response position" is used as the second argument to #copyFrom:to:, and in the other, "response contents" is used to achieve the same effect.

In other words, "response" is not being used as a WriteStream, but as a placeholder for an integer: its "position". There is a comment in each method ("horrible, but fast") next to the invocation of #instVarAt:put:, but the true significance has been missed.

I have made a new version of the methods using a new temporary variable "position", initialized to 0, and used throughout as an Integer. This reveals the true intent of the method much better than the rather ugly implementations currently in place.

Here is the link to the issue: http://code.google.com/p/pharo/issues/detail?id=1152

I have made the fix, and will submit it as soon as 10432 is available.

--
Cheers,
Peter

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project