Examples of IHttpRequest


Examples of org.xlightweb.IHttpRequest

        server.start();
       
        HttpClient httpClient = new HttpClient();
       
       
        IHttpRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/test/12345");
        IHttpResponse resp = httpClient.call(request);
        Assert.assertEquals(302, resp.getStatus());
        Assert.assertEquals("123456", resp.getBlockingBody().readString());
       
       
View Full Code Here

Examples of org.xlightweb.IHttpRequest

       
        HttpClient httpClient = new HttpClient();
        httpClient.setCacheMaxSizeKB(100);
       
       
        IHttpRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/test/12345");
        IHttpResponse resp = httpClient.call(request);
        Assert.assertEquals(302, resp.getStatus());
        Assert.assertEquals("123456", resp.getBlockingBody().readString());
       
       
View Full Code Here

Examples of org.xlightweb.IHttpRequest

    }
   

    public void onRequest(IHttpExchange exchange) throws IOException {

      IHttpRequest req = exchange.getRequest();

      if (isAuthRequired) {
        String s = req.getHeader("Proxy-Authorization");
        if (s != null) {
          int idx = s.indexOf(" ");
          String algorithm = s.substring(0, idx);
          if (algorithm.equalsIgnoreCase("Basic")) {
            String decoded = new String(Base64.decodeBase64(s.substring(idx + 1, s.length()).getBytes()));
            String[] upp = decoded.split(":");
            if (!upp[0].equals(upp[1])) {
              exchange.sendError(401);
              return;
            }
          }
        }
      }
     
     
     
      if (req.getMethod().equalsIgnoreCase("CONNECT")) {
        establishTunnel(exchange);
        return;
      }
     
     
      String path = req.getRequestUrl().getFile();
      URL target = new URL(path);
     
      req.setRequestUrl(target);
     
     
      // add via header
      req.addHeader("Via", "myProxy");
   
     
       
      // .. and forward the request
      try {
View Full Code Here

Examples of org.xlightweb.IHttpRequest

      }
    }
   

    private void establishTunnel(IHttpExchange exchange) {
      IHttpRequest req = exchange.getRequest();
     
      String forwardHost = null;
      int forwardPort = 443;
     
      String uri = req.getRequestURI();
      int idx = uri.lastIndexOf(":");
      if (idx == -1) {
        forwardHost = uri;
      } else {
        forwardHost = uri.substring(0, idx);
View Full Code Here

Examples of org.xlightweb.IHttpRequest

  /**
   * {@inheritDoc}
   */
  public void onRequest(final IHttpExchange exchange) throws IOException {

      final IHttpRequest request = exchange.getRequest();

     
      // skip cache handling?
      if ((request.getAttribute(SKIP_CACHE_HANDLING) != null) && (request.getAttribute(SKIP_CACHE_HANDLING).equals("true"))) {
         exchange.forward(request);
         return;
      }

      // is request not cacheable?
      if (!HttpCache.isCacheable(request)) {
          exchange.forward(request);
          return;
      }

     
      Date minFresh = new Date();
        Date maxOld = null;
        boolean isOnlyIfCached = false;
     
      // handle requests cache control directive
      String cacheControl = request.getHeader("Cache-Control");
     
      if (cacheControl != null) {
          for (String directive : cacheControl.split(",")) {
                directive = directive.trim();
                String directiveLower = directive.toLowerCase();
View Full Code Here

Examples of org.xlightweb.IHttpRequest

 
 
 
  private void forwardForCache(final IHttpExchange exchange) throws IOException {
 
      IHttpRequest request = exchange.getRequest();
      final IHttpRequestHeader headerCopy = request.getRequestHeader().copy();           
           
      final Interaction interaction = new Interaction();
     
     
        if (request.hasBody()) {

            final List<ByteBuffer> bodyCopy = new ArrayList<ByteBuffer>();
           
            NonBlockingBodyDataSource dataSource = request.getNonBlockingBody();
           
           
            ForwarderResponseHandler forwardResponseHandler = new ForwarderResponseHandler(interaction, exchange);
            BodyDataSink dataSink = exchange.forward(request.getRequestHeader(), forwardResponseHandler);

            BodyForwarder bodyForwarder = new BodyForwarder(dataSource, dataSink) {
               
                int currentSize = 0;
               
View Full Code Here

Examples of org.xlightweb.IHttpRequest

     
     
      public void onRequest(IHttpExchange exchange) throws IOException, BadMessageException {

         
          IHttpRequest req = exchange.getRequest();
         
          int port;
          if (req.isSecure()) {
              port = sslServer.getLocalPort();
          } else {
              port = server.getLocalPort();
          }
         
          URL url = req.getRequestUrl();
         
          req.setRequestUrl(new URL(url.getProtocol(), url.getHost(), port, url.getFile()));
         
          try {
              httpClient.send(req, new ResponseHandler(exchange));
          }catch (ConnectException ce) {
              exchange.sendError(502, ce.getMessage());
View Full Code Here

Examples of org.xlightweb.IHttpRequest

 
  private BodyDataSink sendInternal(IHttpRequestHeader requestHeader, IHttpResponseHandler responseHandler) throws IOException, ConnectException {
    lastTimeRequestSentMillis = System.currentTimeMillis();
   
    BodyDataSink dataSink = HttpClientConnection.newInMemoryBodyDataSink(requestHeader.getCharacterEncoding(), pool.getWorkerpool());
    IHttpRequest request = new HttpRequest(requestHeader, HttpClientConnection.getDataSourceOfInMemoryBodyDataSink(dataSink));

    send(request, responseHandler);   
    return dataSink;
  }
View Full Code Here

Examples of org.xlightweb.IHttpRequest

   * {@inheritDoc}
   */
  @InvokeOn(InvokeOn.MESSAGE_RECEIVED)
  public void onRequest(IHttpExchange exchange) throws IOException {
 
    IHttpRequest request = exchange.getRequest();
    exchange.forward(request, new RedirectedHandler(HttpUtils.copy(request), exchange));
  }
View Full Code Here

Examples of org.xlightweb.IHttpRequest

          return null;
      }

   
    public IMessageHandler onMessageHeaderReceived(IHttpMessage message) throws IOException {
      final IHttpRequest request = (IHttpRequest) message;
   
     
      if (transactionMonitor != null) {
          transactionMonitor.registerMessageHeaderReceived(HttpServerConnection.this, request.getRequestHeader());
      }
     
   
      // handle Connection header
      handleLifeCycleHeaders(request);
     
     
      if (LOG.isLoggable(Level.FINE)) {
       
        if (request.hasBody()) {
                    String body = "";
                   
                    String contentType = request.getContentType();
                    if ((contentType != null) && (contentType.startsWith("application/x-www-form-urlencode"))) {
                        body = request.getNonBlockingBody().toString() + "\n";                     
                    }
                   
                    LOG.fine("[" + getId() + "] request received  from " + getRemoteAddress() +
                             ":" + getRemotePort() +
                             " (" + getCountMessagesReceived() + ". request) " + request.getRequestHeader().toString() + body);
       
        } else {
                    LOG.fine("[" + getId() + "] bodyless request received from " + getRemoteAddress() +
                            ":" + getRemotePort() +
                            " (" + getCountMessagesReceived() + ". request) " + request.getRequestHeader().toString());
        }
      }
     
     
     
   
       
      // handle upgrade header
      if (isAutohandleUpgadeHeader) {
        String upgrade = request.getRequestHeader().getUpgrade();
        if ((upgrade != null) && upgrade.equalsIgnoreCase("TLS/1.0")) {

          if (getUnderlyingTcpConnection().isSecuredModeActivateable()) {
            suspendReceiving();
           
            HttpResponse response = new HttpResponse(101);
            response.setHeader("Connection", "Upgrade");
            response.setHeader("Upgrade", "TLS/1.0, HTTP/1.1");
            writeMessage(response);
           
            getUnderlyingTcpConnection().activateSecuredMode();
         
            resumeReceiving();
           
          } else {
            sendResponseMessage(new HttpResponse(400, "text/html", generateErrorMessageHtml(400, "upgrade TLS is not supported", getId())));
            return this;
          }
         
          return this;
        }
      }


      // handle 100 continue header
      if (isAutconfirmExpect100ContinueHeader) {
        String expectHeader = request.getHeader("Expect");
        if ((expectHeader != null) && expectHeader.equalsIgnoreCase("100-Continue")) {
          writeMessageSilence(new HttpResponse(100));
        }
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.