/** * Initializes a response with 200 status and sets the connection header to whatever the client * requested. If no connection header is found in the client request then it is set to CLOSE * * @param message */ public HttpResponse(final HttpRequest message) { this(message == null ? HttpVersion.HTTP_1_1 : message.getProtocolVersion(), HttpStatus.OK); if (message != null) { String conn = message.headers().get(HttpHeaders.Names.CONNECTION); if (conn == null) { conn = HttpHeaders.Values.CLOSE; } headers().set(HttpHeaders.Names.CONNECTION, conn); } }
protected Object extractHeaderParam(MethodParam param, HttpRequest request) { //header param can be a list or string, if neither set to null if (List.class.isAssignableFrom(param.getParameterType())) { return request.headers().getAll(param.getName()); } else { if (String.class.isAssignableFrom(param.getParameterType())) { return request.headers().get(param.getName()); } else { if (ReflectionUtil.isNumeric(param.getParameterType())) { //if param is a number then try to handle with NumberType.parseType return extractNumberParam(param, request.headers().get(param.getName())); } else { return null; } } } }
public HttpRequest(FullHttpRequest msg, HttpProtocolConfiguration config) { this(msg.getProtocolVersion(), msg.getMethod(), msg.getUri(), config); headers().add(msg.headers()); content = Unpooled.copiedBuffer(msg.content()); setDecoderResult(msg.getDecoderResult()); }
/** * Because some custom fields depend on headers not set on construction this method * must be invoked after Netty populates the headers. * * @param ctx */ public void init(ChannelHandlerContext ctx) { String contentTypeStr = headers().get(HttpHeaders.Names.CONTENT_TYPE); this.contentType = MediaType.valueOf(contentTypeStr); String accept = headers().get(HttpHeaders.Names.ACCEPT); acceptedMediaTypes = MediaType.valueOf(accept); String cookiesStr = headers().get(HttpHeaders.Names.COOKIE); if (cookiesStr != null) { Set<Cookie> cookie = CookieDecoder.decode(cookiesStr); for (Cookie c : cookie) { cookies.put(c.getName(), new HttpCookie(c)); } } QueryStringDecoder decoderQuery = new QueryStringDecoder(getUri()); queryParams.putAll(decoderQuery.parameters()); if (config.isEnableSessions()) { initSession(ctx); } }
boolean close = HttpHeaders.Values.CLOSE.equalsIgnoreCase(request.headers().get(CONNECTION)) || request.getProtocolVersion().equals(HttpVersion.HTTP_1_0) && !HttpHeaders.Values.KEEP_ALIVE.equalsIgnoreCase(request.headers().get(CONNECTION)); if (!close && res.getManagedWriter() == null) { setContentLength(res, res.content().readableBytes());
try { webContext.setLocale(Locale.forLanguageTag( request.headers().get(HttpHeaders.Names.ACCEPT_LANGUAGE))); } catch (Throwable t) { log.warn("Unable to set locale from accept header");