Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2014 Red Hat, Inc., and individual contributors
   * as indicated by the @author tags.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  *  Unless required by applicable law or agreed to in writing, software
  *  distributed under the License is distributed on an "AS IS" BASIS,
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
 
 package io.undertow.server.protocol.http;
 
 import org.xnio.Pool;
 
A server-side HTTP connection.

Note that the lifecycle of the server connection is tied to the underlying TCP connection. Even if the channel is upgraded the connection is not considered closed until the upgraded channel is closed.

Author(s):
David M. Lloyd
 
 public final class HttpServerConnection extends AbstractServerConnection {
 
     private SSLSessionInfo sslSessionInfo;
     private HttpReadListener readListener;
 
 
     public HttpServerConnection(StreamConnection channelfinal Pool<ByteBufferbufferPoolfinal HttpHandler rootHandlerfinal OptionMap undertowOptionsfinal int bufferSize) {
         super(channelbufferPoolrootHandlerundertowOptionsbufferSize);
         if (channel instanceof SslChannel) {
              = new ConnectionSSLSessionInfo(((SslChannelchannel), this);
         }
         this. = new HttpResponseConduit(channel.getSinkChannel().getConduit(), bufferPool);
 
         //todo: do this without an allocation
         addCloseListener(new CloseListener() {
             @Override
             public void closed(ServerConnection connection) {
                 if(getExtraBytes() != null) {
                     getExtraBytes().free();
                 }
                 .freeBuffers();
             }
         });
 
     }
 
     @Override
         if (exchange == null || !HttpContinue.requiresContinueResponse(exchange)) {
         }
         final ConduitState state = resetChannel();
         HttpServerExchange newExchange = new HttpServerExchange(this);
         for (HttpString header : exchange.getRequestHeaders().getHeaderNames()) {
             newExchange.getRequestHeaders().putAll(headerexchange.getRequestHeaders().get(header));
         }
         newExchange.setProtocol(exchange.getProtocol());
         newExchange.setRequestMethod(exchange.getRequestMethod());
        exchange.setRequestURI(exchange.getRequestURI(), exchange.isHostIncludedInRequestURI());
        exchange.setRequestPath(exchange.getRequestPath());
        exchange.setRelativePath(exchange.getRelativePath());
        newExchange.getRequestHeaders().put(., 0);
        newExchange.setPersistent(true);
        Connectors.terminateRequest(newExchange);
        newExchange.addResponseWrapper(new ConduitWrapper<StreamSinkConduit>() {
            @Override
            public StreamSinkConduit wrap(ConduitFactory<StreamSinkConduitfactoryHttpServerExchange exchange) {
                ServerFixedLengthStreamSinkConduit fixed = new ServerFixedLengthStreamSinkConduit(new HttpResponseConduit(getSinkChannel().getConduit(), getBufferPool(), exchange), falsefalse);
                fixed.reset(0, exchange);
                return fixed;
            }
        });
        //we restore the read channel immediately, as this out of band response has no read side
        .getSourceChannel().setConduit(source(state));
        newExchange.addExchangeCompleteListener(new ExchangeCompletionListener() {
            @Override
            public void exchangeEvent(HttpServerExchange exchangeNextListener nextListener) {
                restoreChannel(state);
            }
        });
        return newExchange;
    }
    @Override
    public void terminateRequestChannel(HttpServerExchange exchange) {
    }

    
Pushes back the given data. This should only be used by transfer coding handlers that have read past the end of the request when handling pipelined requests

Parameters:
unget The buffer to push back
    public void ungetRequestBytes(final Pooled<ByteBufferunget) {
        if (getExtraBytes() == null) {
            setExtraBytes(unget);
        } else {
            Pooled<ByteBuffereb = getExtraBytes();
            ByteBuffer buf = eb.getResource();
            final ByteBuffer ugBuffer = unget.getResource();
            if (ugBuffer.limit() - ugBuffer.remaining() > buf.remaining()) {
                //stuff the existing data after the data we are ungetting
                ugBuffer.compact();
                ugBuffer.put(buf);
                ugBuffer.flip();
                eb.free();
                setExtraBytes(unget);
            } else {
                //TODO: this is horrible, but should not happen often
                final byte[] data = new byte[ugBuffer.remaining() + buf.remaining()];
                int first = ugBuffer.remaining();
                ugBuffer.get(data, 0, ugBuffer.remaining());
                buf.get(datafirstbuf.remaining());
                eb.free();
                unget.free();
                final ByteBuffer newBuffer = ByteBuffer.wrap(data);
                setExtraBytes(new ImmediatePooled<>(newBuffer));
            }
        }
    }
    @Override
    public SSLSessionInfo getSslSessionInfo() {
        return ;
    }
    @Override
    public void setSslSessionInfo(SSLSessionInfo sessionInfo) {
        this. = sessionInfo;
    }
    public SSLSession getSslSession() {
        if ( instanceof SslChannel) {
            return ((SslChannel).getSslSession();
        }
        return null;
    }
    @Override
    protected StreamConnection upgradeChannel() {
        clearChannel();
        if ( != null) {
        }
        return ;
    }
    @Override
    protected StreamSinkConduit getSinkConduit(HttpServerExchange exchangeStreamSinkConduit conduit) {
        return HttpTransferEncoding.createSinkConduit(exchange);
    }
    @Override
    protected boolean isUpgradeSupported() {
        return true;
    }
    void setReadListener(HttpReadListener readListener) {
        this. = readListener;
    }
    @Override
    protected void exchangeComplete(HttpServerExchange exchange) {
        if ( == null) {
            .exchangeComplete(exchange);
        } else {
            .exchangeComplete(exchange);
        }
    }
        return ;
    }
        return ;
    }
        return ;
    }
        return ;
    }
        return ;
    }
        return ;
    }
    @Override
    protected void setUpgradeListener(HttpUpgradeListener upgradeListener) {
        this. = upgradeListener;
    }
    void setCurrentExchange(HttpServerExchange exchange) {
        this. = exchange;
    }
    public void setPipelineBuffer(PipeliningBufferingStreamSinkConduit pipelineBuffer) {
        this. = pipelineBuffer;
        this. = new HttpResponseConduit(pipelineBuffer);
    }
New to GrepCode? Check out our FAQ X