Search in sources :

Example 6 with HTTPMessageHeader

use of APJP.HTTP11.HTTPMessageHeader in project apjp by jvansteirteghem.

the class HTTPSServerWorker method processHTTPRequestMessage.

protected void processHTTPRequestMessage(HTTPRequestMessage httpRequestMessage) throws Exception {
    HTTPMessageHeader httpRequestMessage1Header01 = httpRequestMessage.getHTTPMessageHeader("Proxy-Connection");
    if (httpRequestMessage1Header01 != null) {
        String httpRequestMessage1Header1Value01 = httpRequestMessage1Header01.getValue();
        if (httpRequestMessage1Header1Value01.equalsIgnoreCase("close")) {
            keepAlive = false;
        }
    }
    HTTPMessageHeader httpRequestMessage1Header02 = httpRequestMessage.getHTTPMessageHeader("Connection");
    if (httpRequestMessage1Header02 != null) {
        String httpRequestMessage1Header1Value02 = httpRequestMessage1Header02.getValue();
        if (httpRequestMessage1Header1Value02.equalsIgnoreCase("close")) {
            keepAlive = false;
        }
    }
}
Also used : HTTPMessageHeader(APJP.ANDROID.HTTP11.HTTPMessageHeader)

Example 7 with HTTPMessageHeader

use of APJP.HTTP11.HTTPMessageHeader in project apjp by jvansteirteghem.

the class HTTPServerWorker method processHTTPRequestMessage.

protected void processHTTPRequestMessage(HTTPRequestMessage httpRequestMessage) throws Exception {
    HTTPMessageHeader httpRequestMessage1Header01 = httpRequestMessage.getHTTPMessageHeader("Proxy-Connection");
    if (httpRequestMessage1Header01 != null) {
        String httpRequestMessage1Header1Value01 = httpRequestMessage1Header01.getValue();
        if (httpRequestMessage1Header1Value01.equalsIgnoreCase("close")) {
            keepAlive = false;
        }
    }
    HTTPMessageHeader httpRequestMessage1Header02 = httpRequestMessage.getHTTPMessageHeader("Connection");
    if (httpRequestMessage1Header02 != null) {
        String httpRequestMessage1Header1Value02 = httpRequestMessage1Header02.getValue();
        if (httpRequestMessage1Header1Value02.equalsIgnoreCase("close")) {
            keepAlive = false;
        }
    }
}
Also used : HTTPMessageHeader(APJP.HTTP11.HTTPMessageHeader)

Example 8 with HTTPMessageHeader

use of APJP.HTTP11.HTTPMessageHeader in project apjp by jvansteirteghem.

the class HTTPSProxyServerWorker method run.

public void run() {
    try {
        final Socket inputSocket = this.inputSocket;
        final InputStream inputSocketInputStream = inputSocket.getInputStream();
        final OutputStream inputSocketOutputStream = inputSocket.getOutputStream();
        HTTPRequestMessage httpRequestMessage1 = new HTTPRequestMessage(inputSocketInputStream);
        httpRequestMessage1.read();
        HTTPMessageHeader httpRequestMessage1Header1 = httpRequestMessage1.getHTTPMessageHeader("");
        if (httpRequestMessage1Header1 != null) {
            // CONNECT 127.0.0.1:443 HTTP/1.1
            String httpRequestMessage1Header1Value1 = httpRequestMessage1Header1.getValue();
            String[] httpRequestMessage1Header1Values1 = httpRequestMessage1Header1Value1.split(" ");
            // CONNECT
            String httpRequestMessage1Header1Value2 = httpRequestMessage1Header1Values1[0];
            if (httpRequestMessage1Header1Value2.equalsIgnoreCase("CONNECT")) {
                // 127.0.0.1:443
                String httpRequestMessage1Header1Value3 = httpRequestMessage1Header1Values1[1];
                String[] httpRequestMessage1Header1Values3 = httpRequestMessage1Header1Value3.split(":");
                // 127.0.0.1
                String httpRequestMessage1Header1Value4 = httpRequestMessage1Header1Values3[0];
                int httpRequestMessage1Header1Value5 = 0;
                try {
                    // 443
                    httpRequestMessage1Header1Value5 = new Integer(httpRequestMessage1Header1Values3[1]);
                } catch (Exception e) {
                }
                httpsServer = httpsProxyServer.getHTTPSServer(httpRequestMessage1Header1Value4, httpRequestMessage1Header1Value5);
                final Socket outputSocket = new Socket();
                try {
                    try {
                        outputSocket.connect(new InetSocketAddress(httpsServer.getLocalAddress(), httpsServer.getLocalPort()));
                        inputSocketOutputStream.write(("HTTP/1.0 200 OK\r\n").getBytes());
                        inputSocketOutputStream.write(("Connection: keep-alive\r\n").getBytes());
                        inputSocketOutputStream.write(("\r\n").getBytes());
                    } catch (Exception e) {
                        inputSocketOutputStream.write(("HTTP/1.0 500 Internal Server Error\r\n").getBytes());
                        inputSocketOutputStream.write(("Connection: close\r\n").getBytes());
                        inputSocketOutputStream.write(("\r\n").getBytes());
                        throw e;
                    }
                    final InputStream outputSocketInputStream = outputSocket.getInputStream();
                    final OutputStream outputSocketOutputStream = outputSocket.getOutputStream();
                    Thread thread1 = new Thread() {

                        public void run() {
                            try {
                                byte[] byteArray1;
                                int byteArray1Length;
                                byteArray1 = new byte[5120];
                                byteArray1Length = 0;
                                while ((byteArray1Length = inputSocketInputStream.read(byteArray1)) != -1) {
                                    outputSocketOutputStream.write(byteArray1, 0, byteArray1Length);
                                }
                            } catch (Exception e) {
                            } finally {
                                try {
                                    outputSocket.shutdownInput();
                                    outputSocket.shutdownOutput();
                                } catch (Exception e) {
                                }
                            }
                        }
                    };
                    thread1.start();
                    Thread thread2 = new Thread() {

                        public void run() {
                            try {
                                byte[] byteArray1;
                                int byteArray1Length;
                                byteArray1 = new byte[5120];
                                byteArray1Length = 0;
                                while ((byteArray1Length = outputSocketInputStream.read(byteArray1)) != -1) {
                                    inputSocketOutputStream.write(byteArray1, 0, byteArray1Length);
                                }
                            } catch (Exception e) {
                            } finally {
                                try {
                                    inputSocket.shutdownInput();
                                    inputSocket.shutdownOutput();
                                } catch (Exception e) {
                                }
                            }
                        }
                    };
                    thread2.start();
                    thread1.join();
                    thread2.join();
                } catch (Exception e) {
                    throw e;
                } finally {
                    try {
                        outputSocket.close();
                    } catch (Exception e) {
                    }
                }
            }
        }
    } catch (Exception e) {
        if (thread != null) {
            logger.log(2, "HTTPS_PROXY_SERVER_WORKER: EXCEPTION", e);
        }
    } finally {
        if (thread != null) {
            try {
                httpsProxyServer.stopHTTPSProxyServerWorker(this);
            } catch (Exception e) {
            }
        }
    }
}
Also used : HTTPRequestMessage(APJP.HTTP11.HTTPRequestMessage) InputStream(java.io.InputStream) InetSocketAddress(java.net.InetSocketAddress) OutputStream(java.io.OutputStream) HTTPMessageHeader(APJP.HTTP11.HTTPMessageHeader) Socket(java.net.Socket)

Example 9 with HTTPMessageHeader

use of APJP.HTTP11.HTTPMessageHeader in project apjp by jvansteirteghem.

the class HTTPServerWorker method processHTTPRequestMessage.

protected void processHTTPRequestMessage(HTTPRequestMessage httpRequestMessage) throws Exception {
    HTTPMessageHeader httpRequestMessage1Header01 = httpRequestMessage.getHTTPMessageHeader("Proxy-Connection");
    if (httpRequestMessage1Header01 != null) {
        String httpRequestMessage1Header1Value01 = httpRequestMessage1Header01.getValue();
        if (httpRequestMessage1Header1Value01.equalsIgnoreCase("close")) {
            keepAlive = false;
        }
    }
    HTTPMessageHeader httpRequestMessage1Header02 = httpRequestMessage.getHTTPMessageHeader("Connection");
    if (httpRequestMessage1Header02 != null) {
        String httpRequestMessage1Header1Value02 = httpRequestMessage1Header02.getValue();
        if (httpRequestMessage1Header1Value02.equalsIgnoreCase("close")) {
            keepAlive = false;
        }
    }
}
Also used : HTTPMessageHeader(APJP.ANDROID.HTTP11.HTTPMessageHeader)

Example 10 with HTTPMessageHeader

use of APJP.HTTP11.HTTPMessageHeader in project apjp by jvansteirteghem.

the class HTTPServerWorker method process.

protected void process() throws Exception {
    InputStream inputSocketInputStream = inputSocket.getInputStream();
    OutputStream inputSocketOutputStream = inputSocket.getOutputStream();
    HTTPRequests httpRequests = HTTPRequests.getHTTPRequests();
    HTTPRequestMessage httpRequestMessage1 = new HTTPRequestMessage(inputSocketInputStream);
    httpRequestMessage1.read();
    HTTPMessageHeader httpRequestMessage1Header1 = httpRequestMessage1.getHTTPMessageHeader("");
    if (httpRequestMessage1Header1 == null) {
        keepAlive = false;
        return;
    }
    String httpRequestMessage1Header1Value1 = httpRequestMessage1Header1.getValue();
    if (httpRequestMessage1Header1Value1.equalsIgnoreCase("")) {
        keepAlive = false;
        return;
    }
    processHTTPRequestMessage(httpRequestMessage1);
    HTTPResponseMessage httpResponseMessage1 = null;
    try {
        HTTPRequest httpRequest1 = httpRequests.createHTTPRequest(httpRequestMessage1);
        httpRequest1.open();
        try {
            httpResponseMessage1 = httpRequest1.getHTTPResponseMessage();
            processHTTPResponseMessage(httpResponseMessage1);
            HTTPMessageHeader[] httpResponseMessage1Headers1 = httpResponseMessage1.getHTTPMessageHeaders();
            HTTPMessageHeader httpResponseMessage1Header1 = httpResponseMessage1Headers1[0];
            String httpResponseMessage1Header1Key1 = httpResponseMessage1Header1.getKey();
            String httpResponseMessage1Header1Value1 = httpResponseMessage1Header1.getValue();
            inputSocketOutputStream.write((httpResponseMessage1Header1Value1 + "\r\n").getBytes());
            for (int i = 1; i < httpResponseMessage1Headers1.length; i = i + 1) {
                httpResponseMessage1Header1 = httpResponseMessage1Headers1[i];
                httpResponseMessage1Header1Key1 = httpResponseMessage1Header1.getKey();
                httpResponseMessage1Header1Value1 = httpResponseMessage1Header1.getValue();
                inputSocketOutputStream.write((httpResponseMessage1Header1Key1 + ": " + httpResponseMessage1Header1Value1 + "\r\n").getBytes());
            }
            inputSocketOutputStream.write(("\r\n").getBytes());
            httpResponseMessage1.read(inputSocketOutputStream);
        } catch (Exception e) {
            throw e;
        } finally {
            try {
                httpRequest1.close();
            } catch (Exception e) {
            }
        }
    } catch (Exception e) {
        logger.log(2, "HTTP_SERVER_WORKER/PROCESS: EXCEPTION", e);
        if (httpResponseMessage1 == null) {
            String[] httpRequestMessage1Header1Values1 = httpRequestMessage1Header1Value1.split(" ");
            String httpRequestMessage1Header1Value2 = httpRequestMessage1Header1Values1[0];
            if (!httpRequestMessage1Header1Value2.equalsIgnoreCase("GET")) {
                throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS: REQUEST/METHOD != \"GET\", REQUEST/METHOD == \"" + httpRequestMessage1Header1Value2 + "\"");
            }
            HTTPMessageHeader httpRequestMessage1Header2 = httpRequestMessage1.getHTTPMessageHeader("If-Range");
            if (httpRequestMessage1Header2 != null) {
                String httpRequestMessage1Header2Value1 = httpRequestMessage1Header2.getValue();
                throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS: REQUEST/IF_RANGE != \"\", REQUEST/IF_RANGE == \"" + httpRequestMessage1Header2Value1 + "\"");
            }
            HTTPMessageHeader httpRequestMessage1Header3 = httpRequestMessage1.getHTTPMessageHeader("Range");
            if (httpRequestMessage1Header3 != null) {
                String httpRequestMessage1Header3Value1 = httpRequestMessage1Header3.getValue();
                throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS: REQUEST/RANGE != \"\", REQUEST/RANGE == \"" + httpRequestMessage1Header3Value1 + "\"");
            }
            httpRequestMessage1Header1Values1[0] = "HEAD";
            httpRequestMessage1Header1Value1 = httpRequestMessage1Header1Values1[0];
            for (int i = 1; i < httpRequestMessage1Header1Values1.length; i = i + 1) {
                httpRequestMessage1Header1Value1 = httpRequestMessage1Header1Value1 + " " + httpRequestMessage1Header1Values1[i];
            }
            httpRequestMessage1Header1.setValue(httpRequestMessage1Header1Value1);
            HTTPRequest httpRequest1 = httpRequests.createHTTPRequest(httpRequestMessage1);
            httpRequest1.open();
            try {
                httpResponseMessage1 = httpRequest1.getHTTPResponseMessage();
            } catch (Exception e2) {
                throw e2;
            } finally {
                try {
                    httpRequest1.close();
                } catch (Exception e2) {
                }
            }
            HTTPMessageHeader httpResponseMessage1Header1 = httpResponseMessage1.getHTTPMessageHeader("Accept-Ranges");
            if (httpResponseMessage1Header1 == null) {
                throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS: RESPONSE/ACCEPT_RANGES != \"bytes\", RESPONSE/ACCEPT_RANGES == \"\"");
            }
            String httpResponseMessage1Header1Value1 = httpResponseMessage1Header1.getValue();
            if (!httpResponseMessage1Header1Value1.equalsIgnoreCase("bytes")) {
                throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS: RESPONSE/ACCEPT_RANGES != \"bytes\", RESPONSE/ACCEPT_RANGES == \"" + httpResponseMessage1Header1Value1 + "\"");
            }
            processHTTPResponseMessage(httpResponseMessage1);
            HTTPMessageHeader[] httpResponseMessage1Headers1 = httpResponseMessage1.getHTTPMessageHeaders();
            HTTPMessageHeader httpResponseMessage1Header2 = httpResponseMessage1Headers1[0];
            String httpResponseMessage1Header2Key1 = httpResponseMessage1Header2.getKey();
            String httpResponseMessage1Header2Value1 = httpResponseMessage1Header2.getValue();
            inputSocketOutputStream.write((httpResponseMessage1Header2Value1 + "\r\n").getBytes());
            for (int i = 1; i < httpResponseMessage1Headers1.length; i = i + 1) {
                httpResponseMessage1Header2 = httpResponseMessage1Headers1[i];
                httpResponseMessage1Header2Key1 = httpResponseMessage1Header2.getKey();
                httpResponseMessage1Header2Value1 = httpResponseMessage1Header2.getValue();
                inputSocketOutputStream.write((httpResponseMessage1Header2Key1 + ": " + httpResponseMessage1Header2Value1 + "\r\n").getBytes());
            }
            inputSocketOutputStream.write(("\r\n").getBytes());
            HTTPMessageHeader httpResponseMessage1Header3 = httpResponseMessage1.getHTTPMessageHeader("Content-Length");
            int httpResponseMessage1Header3Value1 = 0;
            if (httpResponseMessage1Header3 != null) {
                try {
                    httpResponseMessage1Header3Value1 = new Integer(httpResponseMessage1Header3.getValue());
                } catch (Exception e2) {
                }
            }
            httpRequestMessage1Header1Values1[0] = "GET";
            httpRequestMessage1Header1Value1 = httpRequestMessage1Header1Values1[0];
            for (int i = 1; i < httpRequestMessage1Header1Values1.length; i = i + 1) {
                httpRequestMessage1Header1Value1 = httpRequestMessage1Header1Value1 + " " + httpRequestMessage1Header1Values1[i];
            }
            httpRequestMessage1Header1.setValue(httpRequestMessage1Header1Value1);
            long i = 0;
            long j = 1048576;
            if (j > httpResponseMessage1Header3Value1 - 1) {
                j = httpResponseMessage1Header3Value1 - 1;
            }
            while (i < httpResponseMessage1Header3Value1 - 1) {
                HTTPMessageHeader httpRequestMessage1Header4 = httpRequestMessage1.getHTTPMessageHeader("Range");
                if (httpRequestMessage1Header4 != null) {
                    httpRequestMessage1.removeHTTPMessageHeader(httpRequestMessage1Header4);
                }
                httpRequestMessage1.addHTTPMessageHeader(new HTTPMessageHeader("Range", "bytes=" + i + "-" + j));
                HTTPResponseMessage httpResponseMessage2 = null;
                int k = 1;
                while (k <= 5) {
                    try {
                        HTTPRequest httpRequest2 = httpRequests.createHTTPRequest(httpRequestMessage1);
                        httpRequest2.open();
                        try {
                            httpResponseMessage2 = httpRequest2.getHTTPResponseMessage();
                            HTTPMessageHeader httpResponseMessage2Header1 = httpResponseMessage2.getHTTPMessageHeader("Content-Range");
                            if (httpResponseMessage2Header1 == null) {
                                throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS: RESPONSE/CONTENT_RANGE != \"bytes " + i + "-" + j + "/" + httpResponseMessage1Header3Value1 + "\", RESPONSE/CONTENT_RANGE == \"\"");
                            }
                            String httpResponseMessage2Header1Value1 = httpResponseMessage2Header1.getValue();
                            if (!httpResponseMessage2Header1Value1.equalsIgnoreCase("bytes " + i + "-" + j + "/" + httpResponseMessage1Header3Value1)) {
                                throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS: RESPONSE/CONTENT_RANGE != \"bytes " + i + "-" + j + "/" + httpResponseMessage1Header3Value1 + "\", RESPONSE/CONTENT_RANGE == \"" + httpResponseMessage2Header1Value1 + "\"");
                            }
                            httpResponseMessage2.read(inputSocketOutputStream);
                        } catch (Exception e2) {
                            throw e;
                        } finally {
                            try {
                                httpRequest2.close();
                            } catch (Exception e2) {
                            }
                        }
                        k = 5;
                    } catch (Exception e2) {
                        logger.log(2, "HTTP_SERVER_WORKER/PROCESS: EXCEPTION", e2);
                        if (k == 5) {
                            throw new HTTPServerException("HTTP_SERVER_WORKER/PROCESS");
                        }
                    }
                    k = k + 1;
                }
                i = j + 1;
                j = j + 1 + 1048576;
                if (j > httpResponseMessage1Header3Value1 - 1) {
                    j = httpResponseMessage1Header3Value1 - 1;
                }
            }
        }
    }
}
Also used : HTTPRequestMessage(APJP.ANDROID.HTTP11.HTTPRequestMessage) HTTPRequest(APJP.ANDROID.HTTP11.HTTPRequest) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) HTTPRequests(APJP.ANDROID.HTTP11.HTTPRequests) HTTPMessageHeader(APJP.ANDROID.HTTP11.HTTPMessageHeader) HTTPResponseMessage(APJP.ANDROID.HTTP11.HTTPResponseMessage)

Aggregations

HTTPMessageHeader (APJP.HTTP11.HTTPMessageHeader)9 HTTPMessageHeader (APJP.ANDROID.HTTP11.HTTPMessageHeader)7 InputStream (java.io.InputStream)6 OutputStream (java.io.OutputStream)6 HTTPRequestMessage (APJP.HTTP11.HTTPRequestMessage)5 HTTPResponseMessage (APJP.HTTP11.HTTPResponseMessage)4 HTTPRequestMessage (APJP.ANDROID.HTTP11.HTTPRequestMessage)3 HTTPResponseMessage (APJP.ANDROID.HTTP11.HTTPResponseMessage)2 HTTPRequest (APJP.HTTP11.HTTPRequest)2 HTTPSRequest (APJP.HTTP11.HTTPSRequest)2 IOException (java.io.IOException)2 InetSocketAddress (java.net.InetSocketAddress)2 Socket (java.net.Socket)2 Cipher (javax.crypto.Cipher)2 CipherInputStream (javax.crypto.CipherInputStream)2 CipherOutputStream (javax.crypto.CipherOutputStream)2 SecretKeySpec (javax.crypto.spec.SecretKeySpec)2 ServletException (javax.servlet.ServletException)2 HTTPRequest (APJP.ANDROID.HTTP11.HTTPRequest)1 HTTPRequests (APJP.ANDROID.HTTP11.HTTPRequests)1