use of sun.net.www.MessageHeader in project jdk8u_jdk by JetBrains.
the class UserAgent method run.
public void run() {
try {
String version = System.getProperty("java.version");
String expected = "foo Java/" + version;
Socket s = server.accept();
MessageHeader header = new MessageHeader(s.getInputStream());
String v = header.findValue("User-Agent");
if (!expected.equals(v)) {
error("Got unexpected User-Agent: " + v);
} else {
success();
}
OutputStream w = s.getOutputStream();
w.write("HTTP/1.1 200 OK\r\n".getBytes());
w.write("Content-Type: text/plain\r\n".getBytes());
w.write("Content-Length: 5\r\n".getBytes());
w.write("\r\n".getBytes());
w.write("12345\r\n".getBytes());
} catch (Exception e) {
error(e.toString());
}
}
use of sun.net.www.MessageHeader in project jdk8u_jdk by JetBrains.
the class NoNTLM method testNTLM.
/**
* Test the http protocol handler with one WWW-Authenticate header with
* the value "NTLM".
*/
static void testNTLM() throws Exception {
// server reply
String reply = authReplyFor("NTLM");
System.out.println("====================================");
System.out.println("Expect client to fail with 401 Unauthorized");
System.out.println(reply);
try (ServerSocket ss = new ServerSocket(0)) {
Client client = new Client(ss.getLocalPort());
Thread thr = new Thread(client);
thr.start();
// client <--- 401 ---- client
try (Socket s = ss.accept()) {
new MessageHeader().parseHeader(s.getInputStream());
s.getOutputStream().write(reply.getBytes("US-ASCII"));
}
// the client should fail with 401
System.out.println("Waiting for client to terminate");
thr.join();
IOException ioe = client.ioException();
if (ioe != null)
System.out.println("Client failed: " + ioe);
int respCode = client.respCode();
if (respCode != 0 && respCode != -1)
System.out.println("Client received HTTP response code: " + respCode);
if (respCode != HttpURLConnection.HTTP_UNAUTHORIZED)
throw new RuntimeException("Unexpected response code");
}
}
use of sun.net.www.MessageHeader in project jdk8u_jdk by JetBrains.
the class CloseOptionHeader method run.
/*
* "Our" http server
*/
public void run() {
try {
Socket s = ss.accept();
/* check the request to find close connection option header */
InputStream is = s.getInputStream();
MessageHeader mh = new MessageHeader(is);
String connHeader = mh.findValue("Connection");
if (connHeader != null && connHeader.equalsIgnoreCase("close")) {
hasCloseHeader = true;
}
PrintStream out = new PrintStream(new BufferedOutputStream(s.getOutputStream()));
/* response 200 */
out.print("HTTP/1.1 200 OK\r\n");
out.print("Content-Type: text/html; charset=iso-8859-1\r\n");
out.print("Content-Length: 0\r\n");
out.print("Connection: close\r\n");
out.print("\r\n");
out.print("\r\n");
out.flush();
s.close();
ss.close();
} catch (Exception e) {
e.printStackTrace();
}
}
use of sun.net.www.MessageHeader in project jdk8u_jdk by JetBrains.
the class HeaderTests method main.
public static void main(String[] args) {
MessageHeader head = createMessageHeader(s1);
Iterator iter = head.multiValueIterator("Foo");
checkHeader(iter, s1_Foo);
iter = head.multiValueIterator("Fub");
checkHeader(iter, s1_Fub);
HeaderParser hp = new HeaderParser(s2).subsequence(1, 12);
check(hp, s23_expect);
hp = new HeaderParser(s3).subsequence(1, 12);
check(hp, s23_expect);
hp = new HeaderParser(s3).subsequence(0, 11);
check(hp, s23_expect1);
hp = new HeaderParser(s2).subsequence(4, 6);
check(hp, s23_expect2);
}
use of sun.net.www.MessageHeader in project jdk8u_jdk by JetBrains.
the class MessageHeaderTest method main.
public static void main(String[] args) throws Exception {
for (int i = 0; i < 7; i++) {
ByteArrayInputStream bis = new ByteArrayInputStream(headers[i].getBytes());
MessageHeader h = new MessageHeader(bis);
String before = h.toString();
before = before.substring(before.indexOf('{'));
boolean result = h.filterNTLMResponses("WWW-Authenticate");
String after = h.toString();
after = after.substring(after.indexOf('{'));
if (!expected[i].equals(after)) {
throw new RuntimeException(Integer.toString(i) + " expected != after");
}
if (result != expectedResult[i]) {
throw new RuntimeException(Integer.toString(i) + " result != expectedResult");
}
}
}
Aggregations