{
if ( debug )
System.out.println(conn+": runs[11ts] "+request.getURL());
RequestObserver o = request.getObserver();
OutputStream os = conn.getOutputStream();
MimeParser p = conn.getParser();
Reply reply = null;
boolean needsChunk = false;
if (request.getContentLength() < 0 ) {
needsChunk = true;
String tes[] = request.getTransferEncoding();
if (tes == null) {
request.addTransferEncoding("chunked"); // FIXME intern this
} else {
boolean addIt = true;
for (int i=0; !addIt && (i < tes.length); i++) {
addIt = addIt && !tes[i].equals("chunked");
}
if (addIt) {
// FIXME intern thi
request.addTransferEncoding("chunked");
} else {
if (os instanceof ChunkedOutputStream) {
needsChunk = false;
}
}
}
}
try {
request.emit(os, Request.EMIT_HEADERS);
os.flush();
if ( o != null )
notifyObserver(o, new ConnectedEvent(this, request, os));
reply = (Reply) p.parse(manager.isLenient());
boolean bodySent = false;
while ((reply.getStatus() / 100) == 1 ||
reply.getStatus() == HTTP.EXPECTATION_FAILED) {
if (reply.getStatus() == HTTP.EXPECTATION_FAILED)
return reply; // FIXME observer?
reply = null;
// Notify the observer if any:
if ( o != null ) {
notifyObserver(o, new ContinueEvent(this, request, reply));
}
// Finish the request normally:
if (!bodySent) {
bodySent = true;
if (needsChunk) {
DataOutputStream dos = new DataOutputStream(os);
ChunkedOutputStream cos = new ChunkedOutputStream(dos);
request.emit(cos, Request.EMIT_BODY);
cos.flush();
cos.close(false);
request.emit(os,Request.EMIT_FOOTERS);
} else {
request.emit(os,
Request.EMIT_BODY|Request.EMIT_FOOTERS);
}
os.flush();
}
reply = (Reply) p.parse(manager.isLenient());
// if we don't have any observer, eat the 100 continue!
while ((reply.getStatus() / 100) == 1 ) {
if (o != null) {
notifyObserver(o,
new ContinueEvent(this, request, reply));
}
reply = (Reply) p.parse(manager.isLenient());
}
}
} catch (MimeParserException ex) {
return null;
} catch (IOException ieox) {