in axis-rt-compat/src/main/java/org/apache/axis/transport/http/SimpleAxisWorker.java [554:700]
private int parseHeaders(NonBlockingBufferedInputStream is,
byte buf[],
StringBuffer contentType,
StringBuffer contentLocation,
StringBuffer soapAction,
StringBuffer httpRequest,
StringBuffer fileName,
StringBuffer cookie,
StringBuffer cookie2,
StringBuffer authInfo,
MimeHeaders headers)
throws java.io.IOException {
int n;
int len = 0;
// parse first line as GET or POST
n = this.readLine(is, buf, 0, buf.length);
if (n < 0) {
// nothing!
throw new java.io.IOException(Messages.getMessage("unexpectedEOS00"));
}
// which does it begin with?
httpRequest.delete(0, httpRequest.length());
fileName.delete(0, fileName.length());
contentType.delete(0, contentType.length());
contentLocation.delete(0, contentLocation.length());
if (buf[0] == getHeader[0]) {
httpRequest.append("GET");
for (int i = 0; i < n - 5; i++) {
char c = (char) (buf[i + 5] & 0x7f);
if (c == ' ')
break;
fileName.append(c);
}
log.debug(Messages.getMessage("filename01", "SimpleAxisServer", fileName.toString()));
return 0;
} else if (buf[0] == postHeader[0]) {
httpRequest.append("POST");
for (int i = 0; i < n - 6; i++) {
char c = (char) (buf[i + 6] & 0x7f);
if (c == ' ')
break;
fileName.append(c);
}
log.debug(Messages.getMessage("filename01", "SimpleAxisServer", fileName.toString()));
} else {
throw new java.io.IOException(Messages.getMessage("badRequest00"));
}
while ((n = readLine(is, buf, 0, buf.length)) > 0) {
if ((n <= 2) && (buf[0] == '\n' || buf[0] == '\r') && (len > 0)) break;
// RobJ gutted the previous logic; it was too hard to extend for more headers.
// Now, all it does is search forwards for ": " in the buf,
// then do a length / byte compare.
// Hopefully this is still somewhat efficient (Sam is watching!).
// First, search forwards for ": "
int endHeaderIndex = 0;
while (endHeaderIndex < n && toLower[buf[endHeaderIndex]] != headerEnder[0]) {
endHeaderIndex++;
}
endHeaderIndex += 2;
// endHeaderIndex now points _just past_ the ": ", and is
// comparable to the various lenLen, actionLen, etc. values
// convenience; i gets pre-incremented, so initialize it to one less
int i = endHeaderIndex - 1;
// which header did we find?
if (endHeaderIndex == lenLen && matches(buf, lenHeader)) {
// parse content length
while ((++i < n) && (buf[i] >= '0') && (buf[i] <= '9')) {
len = (len * 10) + (buf[i] - '0');
}
headers.addHeader(HTTPConstants.HEADER_CONTENT_LENGTH, String.valueOf(len));
} else if (endHeaderIndex == actionLen
&& matches(buf, actionHeader)) {
soapAction.delete(0, soapAction.length());
// skip initial '"'
i++;
while ((++i < n) && (buf[i] != '"')) {
soapAction.append((char) (buf[i] & 0x7f));
}
headers.addHeader(HTTPConstants.HEADER_SOAP_ACTION, "\"" + soapAction.toString() + "\"");
} else if (server.isSessionUsed() && endHeaderIndex == cookieLen
&& matches(buf, cookieHeader)) {
// keep everything up to first ;
while ((++i < n) && (buf[i] != ';') && (buf[i] != '\r') && (buf[i] != '\n')) {
cookie.append((char) (buf[i] & 0x7f));
}
headers.addHeader("Set-Cookie", cookie.toString());
} else if (server.isSessionUsed() && endHeaderIndex == cookie2Len
&& matches(buf, cookie2Header)) {
// keep everything up to first ;
while ((++i < n) && (buf[i] != ';') && (buf[i] != '\r') && (buf[i] != '\n')) {
cookie2.append((char) (buf[i] & 0x7f));
}
headers.addHeader("Set-Cookie2", cookie.toString());
} else if (endHeaderIndex == authLen && matches(buf, authHeader)) {
if (matches(buf, endHeaderIndex, basicAuth)) {
i += basicAuth.length;
while (++i < n && (buf[i] != '\r') && (buf[i] != '\n')) {
if (buf[i] == ' ') continue;
authInfo.append((char) (buf[i] & 0x7f));
}
headers.addHeader(HTTPConstants.HEADER_AUTHORIZATION, new String(basicAuth) + authInfo.toString());
} else {
throw new java.io.IOException(
Messages.getMessage("badAuth00"));
}
} else if (endHeaderIndex == locationLen && matches(buf, locationHeader)) {
while (++i < n && (buf[i] != '\r') && (buf[i] != '\n')) {
if (buf[i] == ' ') continue;
contentLocation.append((char) (buf[i] & 0x7f));
}
headers.addHeader(HTTPConstants.HEADER_CONTENT_LOCATION, contentLocation.toString());
} else if (endHeaderIndex == typeLen && matches(buf, typeHeader)) {
while (++i < n && (buf[i] != '\r') && (buf[i] != '\n')) {
if (buf[i] == ' ') continue;
contentType.append((char) (buf[i] & 0x7f));
}
headers.addHeader(HTTPConstants.HEADER_CONTENT_TYPE, contentLocation.toString());
} else {
String customHeaderName = new String(buf, 0, endHeaderIndex - 2);
StringBuffer customHeaderValue = new StringBuffer();
while (++i < n && (buf[i] != '\r') && (buf[i] != '\n')) {
if (buf[i] == ' ') continue;
customHeaderValue.append((char) (buf[i] & 0x7f));
}
headers.addHeader(customHeaderName, customHeaderValue.toString());
}
}
return len;
}