@Override public NettyMutableHttpResponse<B> body(B body) { this.body = body; if (body instanceof ByteBuf) { replace((ByteBuf) body); } return this; }
private NettyHttpParameters decodeParameters(String uri) { QueryStringDecoder queryStringDecoder = createDecoder(uri); return new NettyHttpParameters(queryStringDecoder.parameters(), conversionService); } }
@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 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); }
@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 Optional<NettyMutableHttpResponse> convert(FullNettyClientHttpResponse object, Class<NettyMutableHttpResponse> targetType, ConversionContext context) { return Optional.of(new NettyMutableHttpResponse(object.getNativeResponse(), conversionService).body(object.getBody())); } }
@Override public <T> MutableHttpResponse<T> ok(T body) { MutableHttpResponse<T> ok = new NettyMutableHttpResponse<>(ConversionService.SHARED); return body != null ? ok.body(body) : ok; }
private NettyHttpParameters decodeParameters(String uri) { QueryStringDecoder queryStringDecoder = createDecoder(uri); return new NettyHttpParameters(queryStringDecoder.parameters(), ConversionService.SHARED); }
/** * @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; }
@SuppressWarnings("unchecked") @Override public <T1> Optional<T1> getBody(Class<T1> type) { return getBody(Argument.of(type)); }
private String decodePath(String uri) { QueryStringDecoder queryStringDecoder = createDecoder(uri); return queryStringDecoder.rawPath(); }
@Override public Charset getCharacterEncoding() { Charset charset = this.charset; if (charset == null) { synchronized (this) { // double check charset = this.charset; if (charset == null) { charset = initCharset(HttpRequest.super.getCharacterEncoding()); this.charset = charset; } } } return charset; }
@Override public String getPath() { String path = this.path; if (path == null) { synchronized (this) { // double check path = this.path; if (path == null) { path = decodePath(nettyRequest.uri()); this.path = path; } } } return path; }
@Override public HttpParameters getParameters() { NettyHttpParameters httpParameters = this.httpParameters; if (httpParameters == null) { synchronized (this) { // double check httpParameters = this.httpParameters; if (httpParameters == null) { httpParameters = decodeParameters(nettyRequest.uri()); this.httpParameters = httpParameters; } } } return httpParameters; }
@Override public String toString() { HttpStatus status = getStatus(); return status.getCode() + " " + status.getReason(); }
/** * @param uri The URI * @return The query string decoder */ protected QueryStringDecoder createDecoder(String uri) { Charset charset = getCharacterEncoding(); return charset != null ? new QueryStringDecoder(uri, charset) : new QueryStringDecoder(uri); }
private FullHttpResponse notModified() { NettyMutableHttpResponse response = (NettyMutableHttpResponse) HttpResponse.notModified(); setDateHeader(response); return response.getNativeResponse(); }
@Override public <T> MutableHttpResponse<T> status(HttpStatus status, T body) { MutableHttpResponse<T> ok = new NettyMutableHttpResponse<>(ConversionService.SHARED); ok.status(status); return body != null ? ok.body(body) : ok; }
@Override public MutableHttpResponse status(HttpStatus status, String reason) { HttpResponseStatus nettyStatus; if (reason == null) { nettyStatus = HttpResponseStatus.valueOf(status.getCode()); } else { nettyStatus = new HttpResponseStatus(status.getCode(), reason); } DefaultFullHttpResponse fullHttpResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, nettyStatus); return new NettyMutableHttpResponse(fullHttpResponse, ConversionService.SHARED); }