當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpHeaders.set方法代碼示例

本文整理匯總了Java中io.netty.handler.codec.http.HttpHeaders.set方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpHeaders.set方法的具體用法?Java HttpHeaders.set怎麽用?Java HttpHeaders.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.handler.codec.http.HttpHeaders的用法示例。


在下文中一共展示了HttpHeaders.set方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getNettyResponse

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
/**
 * Get a Netty {@link HttpResponse}, committing the {@link HttpServletResponse}.
 */
public HttpResponse getNettyResponse() {
    if (committed) {
        return response;
    }
    committed = true;
    HttpHeaders headers = response.headers();
    if (null != contentType) {
        String value = null == characterEncoding ? contentType : contentType + "; charset=" + characterEncoding;
        headers.set(HttpHeaders.Names.CONTENT_TYPE, value);
    }
    CharSequence date = getFormattedDate();
    headers.set(HttpHeaders.Names.DATE, date);
    headers.set(HttpHeaders.Names.SERVER, servletContext.getServerInfoAscii());
    // TODO cookies
    return response;
}
 
開發者ID:geeker-lait,項目名稱:tasfe-framework,代碼行數:20,代碼來源:NettyHttpServletResponse.java

示例2: createErrorMessage

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
/**
 * Create new HTTP carbon message.
 *
 * @param payload
 * @param statusCode
 * @return
 */
private static HTTPCarbonMessage createErrorMessage(String payload, int statusCode) {

    HTTPCarbonMessage response = createHttpCarbonMessage(false);
    StringDataSource stringDataSource = new StringDataSource(payload
            , new HttpMessageDataStreamer(response).getOutputStream());
    response.setMessageDataSource(stringDataSource);
    byte[] errorMessageBytes = payload.getBytes(Charset.defaultCharset());

    HttpHeaders httpHeaders = response.getHeaders();
    httpHeaders.set(org.wso2.transport.http.netty.common.Constants.HTTP_CONNECTION,
            org.wso2.transport.http.netty.common.Constants.CONNECTION_KEEP_ALIVE);
    httpHeaders.set(org.wso2.transport.http.netty.common.Constants.HTTP_CONTENT_TYPE,
            org.wso2.transport.http.netty.common.Constants.TEXT_PLAIN);
    httpHeaders.set(org.wso2.transport.http.netty.common.Constants.HTTP_CONTENT_LENGTH,
            (String.valueOf(errorMessageBytes.length)));

    response.setProperty(org.wso2.transport.http.netty.common.Constants.HTTP_STATUS_CODE, statusCode);
    response.setProperty(org.wso2.carbon.messaging.Constants.DIRECTION,
            org.wso2.carbon.messaging.Constants.DIRECTION_RESPONSE);
    return response;
}
 
開發者ID:wso2-extensions,項目名稱:siddhi-io-http,代碼行數:29,代碼來源:HttpIoUtil.java

示例3: startDownTask

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
public static void startDownTask(TaskInfo taskInfo, HttpRequest httpRequest,
    HttpResponse httpResponse, Channel clientChannel) {
  HttpHeaders httpHeaders = httpResponse.headers();
  HttpDownInfo httpDownInfo = new HttpDownInfo(taskInfo, httpRequest);
  HttpDownServer.DOWN_CONTENT.put(taskInfo.getId(), httpDownInfo);
  httpHeaders.clear();
  httpResponse.setStatus(HttpResponseStatus.OK);
  httpHeaders.set(HttpHeaderNames.CONTENT_TYPE, "text/html");
  String host = HttpDownServer.isDev() ? "localhost"
      : ((InetSocketAddress) clientChannel.localAddress()).getHostString();
  String js =
      "<script>window.top.location.href='http://" + host + ":" + HttpDownServer.VIEW_SERVER_PORT
          + "/#/tasks/new/" + httpDownInfo
          .getTaskInfo().getId()
          + "';</script>";
  HttpContent content = new DefaultLastHttpContent();
  content.content().writeBytes(js.getBytes());
  httpHeaders.set(HttpHeaderNames.CONTENT_LENGTH, js.getBytes().length);
  clientChannel.writeAndFlush(httpResponse);
  clientChannel.writeAndFlush(content);
  clientChannel.close();
}
 
開發者ID:monkeyWie,項目名稱:proxyee-down,代碼行數:23,代碼來源:HttpDownUtil.java

示例4: writeResponseHead

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
@Override
public void writeResponseHead(Response restletResponse) throws IOException {
    setNettyResponse(new DefaultHttpResponse(HTTP_1_1, new HttpResponseStatus(getStatusCode(), getReasonPhrase())));
    HttpHeaders headers = getNettyResponse().headers();

    // this.response.clear();
    for (Header header : getResponseHeaders()) {
        headers.add(header.getName(), header.getValue());
    }

    // Decide whether to close the connection or not.
    if (isKeepAlive()) {
        headers.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
        getNettyChannel().write(getNettyResponse());
    } else {
        getNettyChannel().writeAndFlush(getNettyResponse()).addListener(ChannelFutureListener.CLOSE);
    }
}
 
開發者ID:restlet,項目名稱:restlet-framework,代碼行數:19,代碼來源:NettyServerCall.java

示例5: getNettyResponse

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
/**
     * Get a Netty {@link io.netty.handler.codec.http.HttpResponse}, committing the {@link javax.servlet.http.HttpServletResponse}.
     */
    public HttpResponse getNettyResponse() {
        if (committed) {
            return response;
        }
        committed = true;
        HttpHeaders headers = response.headers();
        if (null != contentType) {
            String value = null == characterEncoding ? contentType : contentType + "; charset=" + characterEncoding;
            headers.set(HttpHeaders.Names.CONTENT_TYPE, value);
        }else {
            headers.set(HttpHeaders.Names.CONTENT_TYPE,
                    DEFAULT_CONTENT_TYPE);
        }

        headers.set(HttpHeaders.Names.DATE, new Date());
        headers.set(HttpHeaders.Names.SERVER, servletContext.getServerInfoAscii());

        for(Cookie ck : cookies) {
            io.netty.handler.codec.http.cookie.Cookie  nettyCookie = new DefaultCookie(ck.getName(),ck.getValue());
            nettyCookie.setDomain(ck.getDomain());
            nettyCookie.setPath(ck.getPath());
            if( ck.getMaxAge()  > 0) {
                nettyCookie.setMaxAge(ck.getMaxAge());
            }
//            response.headers().add("Set-Cookie", nettyCookie);
           response.headers().add("Set-Cookie", ServerCookieEncoder.STRICT.encode(nettyCookie));
        }
        return response;
    }
 
開發者ID:paullyphang,項目名稱:nebo,代碼行數:33,代碼來源:NettyHttpServletResponse.java

示例6: directHandleMethod

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
private boolean directHandleMethod(ChannelHandlerContext ctx, FullHttpRequest request, HttpMethod method) {
	if (method.equals(HttpMethod.GET) || method.equals(HttpMethod.POST)) {
		return false;
	}
	// 處理 OPTIONS 請求
	HttpResponseStatus status = HttpResponseStatus.OK;
	boolean invalid = false;
	if (!method.equals(HttpMethod.OPTIONS)) {
		invalid = true;
		status = HttpResponseStatus.METHOD_NOT_ALLOWED;
	}
	DefaultFullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, status, Unpooled.EMPTY_BUFFER);
	HttpHeaders headers = response.headers();
	// headers.set(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS,
	// "X-Requested-With, accept, origin, content-type");
	headers.set(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS, "X-Requested-With, content-type");
	headers.set(HttpHeaderNames.ACCESS_CONTROL_ALLOW_METHODS, "GET,POST,OPTIONS");
	headers.set(HttpHeaderNames.SERVER, "Netty5");
	if (invalid) {
		headers.set("Client-Warning", "Invalid Method");
	}
	boolean keepAlive = HttpHeaderUtil.isKeepAlive(request);
	if (keepAlive) {
		response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
	}
	ctx.write(response);
	ChannelFuture future = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
	if (!keepAlive) {
		future.addListener(ChannelFutureListener.CLOSE);
	}
	return true;
}
 
開發者ID:houkx,項目名稱:nettythrift,代碼行數:33,代碼來源:HttpThriftBufDecoder.java

示例7: wrapMessage

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
@Override
public Object wrapMessage(ChannelHandlerContext ctx, ThriftMessage msg) {
	HttpResponseStatus status = HttpResponseStatus.OK;
	DefaultFullHttpResponse httpResp = new DefaultFullHttpResponse(HTTP_1_1, status, msg.getContent());
	HttpHeaders headers = httpResp.headers();
	headers.set(HttpHeaderNames.CONTENT_TYPE, "application/json");
	headers.set(HttpHeaderNames.SERVER, "Netty5");
	filterResponse(httpResp, msg);
	return httpResp;
}
 
開發者ID:houkx,項目名稱:nettythrift,代碼行數:11,代碼來源:HttpThriftBufDecoder.java

示例8: kerberosProxyChallenge

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
private void kerberosProxyChallenge(Channel channel,//
        List<String> proxyAuth,//
        Request request,//
        ProxyServer proxyServer,//
        Realm proxyRealm,//
        HttpHeaders headers,//
        NettyResponseFuture<?> future) throws SpnegoEngineException {

    String challengeHeader = SpnegoEngine.instance().generateToken(proxyServer.getHost());
    headers.set(HttpHeaders.Names.PROXY_AUTHORIZATION, NEGOTIATE + " " + challengeHeader);
}
 
開發者ID:amaralDaniel,項目名稱:megaphone,代碼行數:12,代碼來源:ProxyUnauthorized407Interceptor.java

示例9: kerberosChallenge

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
private void kerberosChallenge(Channel channel,//
        List<String> authHeaders,//
        Request request,//
        HttpHeaders headers,//
        Realm realm,//
        NettyResponseFuture<?> future) throws SpnegoEngineException {

    Uri uri = request.getUri();
    String host = withDefault(request.getVirtualHost(), uri.getHost());
    String challengeHeader = SpnegoEngine.instance().generateToken(host);
    headers.set(HttpHeaders.Names.AUTHORIZATION, NEGOTIATE + " " + challengeHeader);
}
 
開發者ID:amaralDaniel,項目名稱:megaphone,代碼行數:13,代碼來源:Unauthorized401Interceptor.java

示例10: buildStartMessage

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
@Override
public HttpRequest buildStartMessage(TransportRequest request, AttributeMap channelAttrs) {
  DefaultHttpRequest httpRequest =
      new DefaultHttpRequest(HttpTransport.HTTP_VERSION, HttpMethod.POST, url.getPath());
  HttpHeaders httpHeaders = httpRequest.headers();
  setCommonHeaders(httpHeaders, request, channelAttrs);
  httpHeaders.set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
  return httpRequest;
}
 
開發者ID:yarpc,項目名稱:yarpc-java,代碼行數:10,代碼來源:TransportRequestEncoderConfiguration.java

示例11: setCommonHeaders

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
private void setCommonHeaders(
    HttpHeaders httpHeaders, TransportRequest request, AttributeMap channelAttrs) {
  HeaderMapper.toHttpHeaders(request.getHeaders(), httpHeaders);
  httpHeaders.set(HeaderMapper.SERVICE, request.getService());
  httpHeaders.set(HeaderMapper.PROCEDURE, request.getProcedure());
  httpHeaders.set(HeaderMapper.CALLER, request.getCaller());
  httpHeaders.set(HeaderMapper.ENCODING, request.getEncoding());
  // Required headers for HTTP
  httpHeaders.set(HttpHeaderNames.HOST, hostString);
  if (request.getDeadline() != null) {
    Instant now = Instant.now();
    long timeRemaining = ChronoUnit.MILLIS.between(now, request.getDeadline());
    if (timeRemaining <= 0) {
      throw new DeadlineExceededException();
    }
    httpHeaders.set(HeaderMapper.TIMEOUT, String.valueOf(timeRemaining));
  }
  if (request.getShardKey() != null) {
    httpHeaders.set(HeaderMapper.SHARD_KEY, request.getShardKey());
  }
  if (request.getRoutingKey() != null) {
    httpHeaders.set(HeaderMapper.ROUTING_KEY, request.getRoutingKey());
  }
  if (request.getRoutingDelegate() != null) {
    httpHeaders.set(HeaderMapper.ROUTING_DELEGATE, request.getRoutingDelegate());
  }
  if (request.getSpan() != null) {
    channelAttrs.attr(ChannelAttributes.SPAN).set(request.getSpan());
    tracer.inject(
        request.getSpan().context(), Builtin.HTTP_HEADERS, new TextMapInjectAdapter(httpHeaders));
  }
}
 
開發者ID:yarpc,項目名稱:yarpc-java,代碼行數:33,代碼來源:TransportRequestEncoderConfiguration.java

示例12: removeSDCHEncoding

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
/**
 * Remove sdch from encodings we accept since we can't decode it.
 * 
 * @param headers
 *            The headers to modify
 */
private void removeSDCHEncoding(HttpHeaders headers) {
    String ae = headers.get(HttpHeaders.Names.ACCEPT_ENCODING);
    if (StringUtils.isNotBlank(ae)) {
        //
        String noSdch = ae.replace(",sdch", "").replace("sdch", "");
        headers.set(HttpHeaders.Names.ACCEPT_ENCODING, noSdch);
        LOG.debug("Removed sdch and inserted: {}", noSdch);
    }
}
 
開發者ID:wxyzZ,項目名稱:little_mitm,代碼行數:16,代碼來源:ClientToProxyConnection.java

示例13: switchProxyConnectionHeader

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
/**
 * Switch the de-facto standard "Proxy-Connection" header to "Connection"
 * when we pass it along to the remote host. This is largely undocumented
 * but seems to be what most browsers and servers expect.
 * 
 * @param headers
 *            The headers to modify
 */
private void switchProxyConnectionHeader(HttpHeaders headers) {
    String proxyConnectionKey = "Proxy-Connection";
    if (headers.contains(proxyConnectionKey)) {
        String header = headers.get(proxyConnectionKey);
        headers.remove(proxyConnectionKey);
        headers.set(HttpHeaders.Names.CONNECTION, header);
    }
}
 
開發者ID:wxyzZ,項目名稱:little_mitm,代碼行數:17,代碼來源:ClientToProxyConnection.java

示例14: generateCarbonMessage

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
/**
 * The method is responsible of generating carbon message to send.
 *
 * @param headers     the headers set.
 * @param contentType the content type. Value is if user has to given it as a header or if not it is map type.
 * @param httpMethod  http method type.
 * @param cMessage    carbon message to be send to the endpoint.
 * @return generated carbon message.
 */
private HTTPCarbonMessage generateCarbonMessage(List<Header> headers, String contentType,
                                                String httpMethod, HTTPCarbonMessage cMessage) {
    /*
     * set carbon message properties which is to be used in carbon transport.
     */
    // Set protocol type http or https
    cMessage.setProperty(Constants.PROTOCOL, httpURLProperties.get(HttpConstants.SCHEME));
    // Set uri
    cMessage.setProperty(Constants.TO, httpURLProperties.get(HttpConstants.TO));
    // set Host
    cMessage.setProperty(Constants.HOST, httpURLProperties.get(HttpConstants.HOST));
    //set port
    cMessage.setProperty(Constants.PORT, Integer.valueOf(httpURLProperties.get(HttpConstants.PORT)));
    // Set method
    cMessage.setProperty(HttpConstants.HTTP_METHOD, httpMethod);
    HttpHeaders httpHeaders = cMessage.getHeaders();
    //if Authentication enabled
    if (!(userName.equals(HttpConstants.EMPTY_STRING)) && !(userPassword.equals
            (HttpConstants.EMPTY_STRING))) {
        httpHeaders.set(HttpConstants.AUTHORIZATION_HEADER, authorizationHeader);
    } else if (!(userName.equals(HttpConstants.EMPTY_STRING)) || !(userPassword.equals
            (HttpConstants.EMPTY_STRING))) {
        log.error("One of the basic authentication username or password missing. Hence basic authentication not " +
                "supported.");
    }

    /*
     *set request headers.
     */
    // Set user given Headers
    if (headers != null) {
        for (Header header : headers) {
            httpHeaders.set(header.getName(), header.getValue());
        }
    }
    // Set content type if content type s not included in headers
    if (contentType.contains(mapType)) {
        httpHeaders.set(HttpConstants.HTTP_CONTENT_TYPE, contentType);
    }
    //set method-type header
    httpHeaders.set(HttpConstants.HTTP_METHOD, httpMethod);
    return cMessage;
}
 
開發者ID:wso2-extensions,項目名稱:siddhi-io-http,代碼行數:53,代碼來源:HttpSink.java

示例15: getHttpRequest

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
protected HttpRequest getHttpRequest(final O ioTask, final String nodeAddr)
throws URISyntaxException {

	final I item = ioTask.getItem();
	final IoType ioType = ioTask.getIoType();
	final String srcPath = ioTask.getSrcPath();

	final HttpMethod httpMethod;
	final String uriPath;
	if(item instanceof DataItem) {
		httpMethod = getDataHttpMethod(ioType);
		uriPath = getDataUriPath(item, srcPath, ioTask.getDstPath(), ioType);
	} else if(item instanceof TokenItem) {
		httpMethod = getTokenHttpMethod(ioType);
		uriPath = getTokenUriPath(item, srcPath, ioTask.getDstPath(), ioType);
	} else if(item instanceof PathItem) {
		httpMethod = getPathHttpMethod(ioType);
		uriPath = getPathUriPath(item, srcPath, ioTask.getDstPath(), ioType);
	} else {
		throw new AssertionError("Unsupported item class: " + item.getClass().getName());
	}

	final HttpHeaders httpHeaders = new DefaultHttpHeaders();
	if(nodeAddr != null) {
		httpHeaders.set(HttpHeaderNames.HOST, nodeAddr);
	}
	httpHeaders.set(HttpHeaderNames.DATE, DATE_SUPPLIER.get());
	final HttpRequest httpRequest = new DefaultHttpRequest(
		HTTP_1_1, httpMethod, uriPath, httpHeaders
	);

	switch(ioType) {
		case CREATE:
			if(srcPath == null || srcPath.isEmpty()) {
				if(item instanceof DataItem) {
					try {
						httpHeaders.set(
							HttpHeaderNames.CONTENT_LENGTH, ((DataItem) item).size()
						);
					} catch(final IOException ignored) {
					}
				} else {
					httpHeaders.set(HttpHeaderNames.CONTENT_LENGTH, 0);
				}
			} else {
				applyCopyHeaders(httpHeaders, getDataUriPath(item, srcPath, null, ioType));
				httpHeaders.set(HttpHeaderNames.CONTENT_LENGTH, 0);
			}
			break;
		case READ:
			httpHeaders.set(HttpHeaderNames.CONTENT_LENGTH, 0);
			if(ioTask instanceof DataIoTask) {
				applyRangesHeaders(httpHeaders, (DataIoTask) ioTask);
			}
			break;
		case UPDATE:
			final DataIoTask dataIoTask = (DataIoTask) ioTask;
			httpHeaders.set(HttpHeaderNames.CONTENT_LENGTH, dataIoTask.getMarkedRangesSize());
			applyRangesHeaders(httpHeaders, dataIoTask);
			break;
		case DELETE:
			httpHeaders.set(HttpHeaderNames.CONTENT_LENGTH, 0);
			break;
	}

	applyMetaDataHeaders(httpHeaders);
	applyDynamicHeaders(httpHeaders);
	applySharedHeaders(httpHeaders);
	applyAuthHeaders(httpHeaders, httpMethod, uriPath, ioTask.getCredential());

	return httpRequest;
}
 
開發者ID:emc-mongoose,項目名稱:mongoose-base,代碼行數:73,代碼來源:HttpStorageDriverBase.java


注:本文中的io.netty.handler.codec.http.HttpHeaders.set方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。