/** * @param nettyResponse The {@link FullHttpResponse} * @param conversionService The conversion service */ @SuppressWarnings("MagicNumber") public NettyMutableHttpResponse(FullHttpResponse nettyResponse, ConversionService conversionService) { this.nettyResponse = nettyResponse; this.headers = new NettyHttpHeaders(nettyResponse.headers(), conversionService); this.attributes = new MutableConvertibleValuesMap<>(new ConcurrentHashMap<>(4), conversionService); this.conversionService = conversionService; }
@Override public MutableHttpRequest<B> cookie(Cookie cookie) { if (cookie instanceof NettyCookie) { NettyCookie nettyCookie = (NettyCookie) cookie; String value = ClientCookieEncoder.LAX.encode(nettyCookie.getNettyCookie()); headers.add(HttpHeaderNames.COOKIE, value); } else { throw new IllegalArgumentException("Argument is not a Netty compatible Cookie"); } return this; }
@Override public Cookies getCookies() { NettyCookies cookies = this.nettyCookies; if (cookies == null) { synchronized (this) { // double check cookies = this.nettyCookies; if (cookies == null) { cookies = new NettyCookies(getPath(), headers.getNettyHeaders(), conversionService); this.nettyCookies = cookies; } } } return cookies; }
/** * @param body The body to replace * @return The current instance */ public NettyMutableHttpResponse replace(ByteBuf body) { this.nettyResponse = this.nettyResponse.replace(body); this.headers.setNettyHeaders(this.nettyResponse.headers()); return this; }
/** * @param conversionService The conversion service */ @SuppressWarnings("MagicNumber") public NettyMutableHttpResponse(ConversionService conversionService) { this.nettyResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); this.headers = new NettyHttpHeaders(nettyResponse.headers(), conversionService); this.attributes = new MutableConvertibleValuesMap<>(new ConcurrentHashMap<>(4), conversionService); this.conversionService = conversionService; }
/** * @param publisher A publisher for the Http content * @return The Http request */ HttpRequest getStreamedRequest(Publisher<HttpContent> publisher) { String uriStr = resolveUriPath(); io.netty.handler.codec.http.HttpMethod method = io.netty.handler.codec.http.HttpMethod.valueOf(httpMethod.name()); HttpRequest req = publisher != null ? new DefaultStreamedHttpRequest(HttpVersion.HTTP_1_1, method, uriStr, publisher) : new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, method, uriStr); req.headers().setAll(headers.getNettyHeaders()); return req; }
@Override public MutableHttpResponse<B> cookie(Cookie cookie) { if (cookie instanceof NettyCookie) { NettyCookie nettyCookie = (NettyCookie) cookie; String value = ServerCookieEncoder.LAX.encode(nettyCookie.getNettyCookie()); headers.add(HttpHeaderNames.SET_COOKIE, value); } else { throw new IllegalArgumentException("Argument is not a Netty compatible Cookie"); } return this; }
/** * @param nettyRequest The {@link io.netty.handler.codec.http.HttpRequest} * @param ctx The {@link ChannelHandlerContext} * @param environment The Environment * @param serverConfiguration The {@link HttpServerConfiguration} */ @SuppressWarnings("MagicNumber") public NettyHttpRequest(io.netty.handler.codec.http.HttpRequest nettyRequest, ChannelHandlerContext ctx, ConversionService environment, HttpServerConfiguration serverConfiguration) { super(nettyRequest, environment); Objects.requireNonNull(nettyRequest, "Netty request cannot be null"); Objects.requireNonNull(ctx, "ChannelHandlerContext cannot be null"); Objects.requireNonNull(environment, "Environment cannot be null"); Channel channel = ctx.channel(); if (channel != null) { channel.attr(KEY).set(this); } this.serverConfiguration = serverConfiguration; this.attributes = new MutableConvertibleValuesMap<>(new ConcurrentHashMap<>(4), conversionService); this.channelHandlerContext = ctx; this.headers = new NettyHttpHeaders(nettyRequest.headers(), conversionService); this.body = SupplierUtil.memoizedNonEmpty(() -> Optional.ofNullable((T) buildBody())); }
io.netty.handler.codec.http.HttpHeaders nettyHeaders; if (headers instanceof NettyHttpHeaders) { nettyHeaders = ((NettyHttpHeaders) headers).getNettyHeaders(); } else { nettyHeaders = new DefaultHttpHeaders();
@Override public MutableHttpRequest<B> cookie(Cookie cookie) { if (cookie instanceof NettyCookie) { NettyCookie nettyCookie = (NettyCookie) cookie; String value = ClientCookieEncoder.LAX.encode(nettyCookie.getNettyCookie()); headers.add(HttpHeaderNames.COOKIE, value); } else { throw new IllegalArgumentException("Argument is not a Netty compatible Cookie"); } return this; }
/** * @param response The streamed Http response */ NettyStreamedHttpResponse(StreamedHttpResponse response) { this.nettyResponse = response; this.status = HttpStatus.valueOf(response.status().code()); this.headers = new NettyHttpHeaders(response.headers(), ConversionService.SHARED); }
/** * @param content The {@link ByteBuf} * @return The http request */ HttpRequest getFullRequest(ByteBuf content) { String uriStr = resolveUriPath(); io.netty.handler.codec.http.HttpMethod method = io.netty.handler.codec.http.HttpMethod.valueOf(httpMethod.name()); DefaultFullHttpRequest req = content != null ? new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, method, uriStr, content) : new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, method, uriStr); req.headers().setAll(headers.getNettyHeaders()); return req; }
@Override public MutableHttpRequest<B> cookie(Cookie cookie) { if (cookie instanceof NettyCookie) { NettyCookie nettyCookie = (NettyCookie) cookie; String value = ClientCookieEncoder.LAX.encode(nettyCookie.getNettyCookie()); headers.add(HttpHeaderNames.COOKIE, value); } else { throw new IllegalArgumentException("Argument is not a Netty compatible Cookie"); } return this; }
this.headers = new NettyHttpHeaders(fullHttpResponse.headers(), ConversionService.SHARED); this.attributes = new MutableConvertibleValuesMap<>(); this.nettyHttpResponse = fullHttpResponse;
/** * @param publisher A publisher for the Http content * @return The Http request */ HttpRequest getStreamedRequest(Publisher<HttpContent> publisher) { String uriStr = resolveUriPath(); io.netty.handler.codec.http.HttpMethod method = io.netty.handler.codec.http.HttpMethod.valueOf(httpMethod.name()); HttpRequest req = publisher != null ? new DefaultStreamedHttpRequest(HttpVersion.HTTP_1_1, method, uriStr, publisher) : new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, method, uriStr); req.headers().setAll(headers.getNettyHeaders()); return req; }
/** * @param response The streamed Http response */ NettyStreamedHttpResponse(StreamedHttpResponse response) { this.nettyResponse = response; this.status = HttpStatus.valueOf(response.status().code()); this.headers = new NettyHttpHeaders(response.headers(), ConversionService.SHARED); }
/** * @param publisher A publisher for the Http content * @return The Http request */ HttpRequest getStreamedRequest(Publisher<HttpContent> publisher) { String uriStr = resolveUriPath(); io.netty.handler.codec.http.HttpMethod method = io.netty.handler.codec.http.HttpMethod.valueOf(httpMethod.name()); HttpRequest req = publisher != null ? new DefaultStreamedHttpRequest(HttpVersion.HTTP_1_1, method, uriStr, publisher) : new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, method, uriStr); req.headers().setAll(headers.getNettyHeaders()); return req; }
/** * @param response The streamed Http response */ NettyStreamedHttpResponse(StreamedHttpResponse response) { this.nettyResponse = response; this.status = HttpStatus.valueOf(response.status().code()); this.headers = new NettyHttpHeaders(response.headers(), ConversionService.SHARED); }
/** * @param content The {@link ByteBuf} * @return The http request */ HttpRequest getFullRequest(ByteBuf content) { String uriStr = resolveUriPath(); io.netty.handler.codec.http.HttpMethod method = io.netty.handler.codec.http.HttpMethod.valueOf(httpMethod.name()); DefaultFullHttpRequest req = content != null ? new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, method, uriStr, content) : new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, method, uriStr); req.headers().setAll(headers.getNettyHeaders()); return req; }