String code; try { code = encoding.getValue().toLowerCase(); } catch (IOException e) { throw new ErrorDataDecoderException(e); throw new ErrorDataDecoderException("TransferEncoding Unknown: " + code); long size; try { size = lengthAttribute != null ? Long.parseLong(lengthAttribute.getValue()) : 0L; } catch (IOException e) { throw new ErrorDataDecoderException(e); contentType = HttpPostBodyUtil.DEFAULT_BINARY_CONTENT_TYPE; currentFileUpload = factory.createFileUpload(request, cleanString(nameAttribute.getValue()), cleanString(filenameAttribute.getValue()), contentType, mechanism.value(), localCharset, if (currentFileUpload.isCompleted()) {
switch (state) { case NOTSTARTED: throw new ErrorDataDecoderException("Should not be called with the current getStatus"); case PREAMBLE: throw new ErrorDataDecoderException("Should not be called with the current getStatus"); case HEADERDELIMITER: { if (charsetAttribute != null) { try { localCharset = Charset.forName(charsetAttribute.getValue()); } catch (IOException e) { throw new ErrorDataDecoderException(e); } catch (UnsupportedCharsetException e) { throw new ErrorDataDecoderException(e); try { size = lengthAttribute != null? Long.parseLong(lengthAttribute .getValue()) : 0L; } catch (IOException e) { throw new ErrorDataDecoderException(e); currentAttribute = factory.createAttribute(request, cleanString(nameAttribute.getValue()), size); } else { currentAttribute = factory.createAttribute(request, cleanString(nameAttribute.getValue()));
/** * Clean all HttpDatas (on Disk) for the current request. */ public void cleanFiles() { factory.cleanRequestHttpData(request); }
private Attribute getContentDispositionAttribute(String... values) { String name = cleanString(values[0]); String value = values[1]; // Filename can be token, quoted or encoded. See https://tools.ietf.org/html/rfc5987 if (HttpHeaderValues.FILENAME.contentEquals(name)) { // Value is quoted or token. Strip if quoted: int last = value.length() - 1; if (last > 0 && value.charAt(0) == HttpConstants.DOUBLE_QUOTE && value.charAt(last) == HttpConstants.DOUBLE_QUOTE) { value = value.substring(1, last); } } else if (FILENAME_ENCODED.equals(name)) { try { name = HttpHeaderValues.FILENAME.toString(); String[] split = value.split("'", 3); value = QueryStringDecoder.decodeComponent(split[2], Charset.forName(split[0])); } catch (ArrayIndexOutOfBoundsException e) { throw new ErrorDataDecoderException(e); } catch (UnsupportedCharsetException e) { throw new ErrorDataDecoderException(e); } } else { // otherwise we need to clean the value value = cleanString(value); } return factory.createAttribute(request, name, value); }
if (fileUpload != null) { fileUpload.addContent(content.retain(), true); ((LazyResourceState) request.state()).fileUpload(fileUpload); } else { fileUpload.delete(); } else if (content.readableBytes() > 0) { log.debug("on LastHttpContent: " + content.readableBytes() + " bytes discarded!"); fileUpload.addContent(content.retain(), false); } else if (content.readableBytes() > 0) { log.debug("on HttpContent: " + content.readableBytes() + " bytes discarded!"); factory.createAttribute(original, "filename", filename); factory.createAttribute(original, CONTENT_LENGTH, contentLength); try { clen = Long.parseLong(contentLength); factory.createAttribute(original, CONTENT_TYPE, contentType); fileUpload = factory.createFileUpload(original, request.resourcePath().toString(), filename, contentType, "binary", Charset.forName("utf-8"), clen);
try { String key = encodeAttribute(attribute.getName(), charset); String value = encodeAttribute(attribute.getValue(), charset); Attribute newattribute = factory.createAttribute(request, key, value); multipartHttpDatas.add(newattribute); globalBodySize += newattribute.getName().length() + 1 + newattribute.length() + 1; } catch (IOException e) { throw new ErrorDataEncoderException(e); String key = encodeAttribute(fileUpload.getName(), charset); String value = encodeAttribute(fileUpload.getFilename(), charset); Attribute newattribute = factory.createAttribute(request, key, value); multipartHttpDatas.add(newattribute); globalBodySize += newattribute.getName().length() + 1 + newattribute.length() + 1; HttpPostBodyUtil.DEFAULT_TEXT_CONTENT_TYPE + "; " + HttpHeaderValues.CHARSET + '=' + localcharset.name() + "\r\n"); if (currentFileUpload != null && currentFileUpload.getName().equals(fileUpload.getName())) { + HttpPostBodyUtil.TransferEncodingMechanism.BINARY.value() + "\r\n\r\n"); } else if (fileUpload.getCharset() != null) { internal.addValue("; " + HttpHeaderValues.CHARSET + '=' + fileUpload.getCharset().name() + "\r\n\r\n"); } else { internal.addValue("\r\n\r\n");
int firstpos = undecodedChunk.readerIndex(); int currentpos = firstpos; int equalpos; String key = decodeAttribute(undecodedChunk.toString(firstpos, equalpos - firstpos, charset), charset); currentAttribute = factory.createAttribute(request, key); firstpos = currentpos; } else if (read == '&') { // special empty FIELD String key = decodeAttribute( undecodedChunk.toString(firstpos, ampersandpos - firstpos, charset), charset); currentAttribute = factory.createAttribute(request, key); currentAttribute.setValue(""); // empty addHttpData(currentAttribute); currentAttribute = null; } else { throw new ErrorDataDecoderException("Bad end of line"); } else if (contRead && currentAttribute != null && currentStatus == MultiPartStatus.FIELD) { undecodedChunk.readerIndex(firstpos); throw new ErrorDataDecoderException(e);
if (!undecodedChunk.hasArray()) { parseBodyAttributesStandard(); return; currentStatus = MultiPartStatus.FIELD; equalpos = currentpos - 1; String key = decodeAttribute(undecodedChunk.toString(firstpos, equalpos - firstpos, charset), charset); currentAttribute = factory.createAttribute(request, key); firstpos = currentpos; } else if (read == '&') { // special empty FIELD currentAttribute = factory.createAttribute(request, key); currentAttribute.setValue(""); // empty addHttpData(currentAttribute); currentAttribute = null; throw new ErrorDataDecoderException("Bad end of line"); } else if (!currentAttribute.isCompleted()) { setFinalBuffer(EMPTY_BUFFER); } else if (contRead && currentAttribute != null && currentStatus == MultiPartStatus.FIELD) { throw new ErrorDataDecoderException(e); } catch (IllegalArgumentException e) { throw new ErrorDataDecoderException(e);
currentFieldAttributes.put(attribute.getName(), attribute); Attribute attribute; try { attribute = factory.createAttribute(request, HttpHeaderNames.CONTENT_TRANSFER_ENCODING.toString(), cleanString(contents[1])); } catch (NullPointerException e) { throw new ErrorDataDecoderException(e); Attribute attribute; try { attribute = factory.createAttribute(request, HttpHeaderNames.CONTENT_LENGTH.toString(), cleanString(contents[1])); } catch (NullPointerException e) { Attribute attribute; try { attribute = factory.createAttribute(request, charsetHeader, cleanString(values)); Attribute attribute; try { attribute = factory.createAttribute(request, cleanString(contents[0]), contents[i]); } catch (NullPointerException e) { currentFieldAttributes.put(attribute.getName(), attribute);
contentTransferEncoding = HttpPostBodyUtil.TransferEncodingMechanism.BINARY.value(); FileUpload fileUpload = factory.createFileUpload(request, name, filename, scontentType, contentTransferEncoding, null, file.length()); try { fileUpload.setContent(file); } catch (IOException e) { throw new ErrorDataEncoderException(e);
/** * Create an object of {@link InterfaceHttpData} to build Netty multipart request body. * * @see Part#getData(HttpRequest, HttpDataFactory) */ @Override InterfaceHttpData getData(HttpRequest request, HttpDataFactory factory) { return factory.createAttribute(request, name, value); } }
/** * Create an object of {@link InterfaceHttpData} to build Netty multipart request. * * @see Part#getData(HttpRequest, HttpDataFactory) */ @Override InterfaceHttpData getData(HttpRequest request, HttpDataFactory factory) { MediaType mediaType = contentType; String contentType = mediaType.toString(); String encoding = mediaType.isTextBased() ? null : "binary"; FileUpload fileUpload = factory.createFileUpload(request, name, filename, contentType, encoding, null, getLength()); try { setContent(fileUpload); } catch (IOException e) { throw new IllegalArgumentException(e); } return fileUpload; } }
/** * Remove the given FileUpload from the list of FileUploads to clean */ @Override public void removeHttpDataFromClean(InterfaceHttpData data) { checkDestroyed(); factory.removeHttpDataFromClean(request, data); } }
private Attribute getContentDispositionAttribute(String... values) { String name = cleanString(values[0]); String value = values[1]; // Filename can be token, quoted or encoded. See https://tools.ietf.org/html/rfc5987 if (HttpHeaderValues.FILENAME.contentEquals(name)) { // Value is quoted or token. Strip if quoted: int last = value.length() - 1; if (last > 0 && value.charAt(0) == HttpConstants.DOUBLE_QUOTE && value.charAt(last) == HttpConstants.DOUBLE_QUOTE) { value = value.substring(1, last); } } else if (FILENAME_ENCODED.equals(name)) { try { name = HttpHeaderValues.FILENAME.toString(); String[] split = value.split("'", 3); value = QueryStringDecoder.decodeComponent(split[2], Charset.forName(split[0])); } catch (ArrayIndexOutOfBoundsException e) { throw new ErrorDataDecoderException(e); } catch (UnsupportedCharsetException e) { throw new ErrorDataDecoderException(e); } } else { // otherwise we need to clean the value value = cleanString(value); } return factory.createAttribute(request, name, value); }
try { String key = encodeAttribute(attribute.getName(), charset); String value = encodeAttribute(attribute.getValue(), charset); Attribute newattribute = factory.createAttribute(request, key, value); multipartHttpDatas.add(newattribute); globalBodySize += newattribute.getName().length() + 1 + newattribute.length() + 1; } catch (IOException e) { throw new ErrorDataEncoderException(e); String key = encodeAttribute(fileUpload.getName(), charset); String value = encodeAttribute(fileUpload.getFilename(), charset); Attribute newattribute = factory.createAttribute(request, key, value); multipartHttpDatas.add(newattribute); globalBodySize += newattribute.getName().length() + 1 + newattribute.length() + 1; HttpPostBodyUtil.DEFAULT_TEXT_CONTENT_TYPE + "; " + HttpHeaderValues.CHARSET + '=' + localcharset.name() + "\r\n"); if (currentFileUpload != null && currentFileUpload.getName().equals(fileUpload.getName())) { + HttpPostBodyUtil.TransferEncodingMechanism.BINARY.value() + "\r\n\r\n"); } else if (fileUpload.getCharset() != null) { internal.addValue("; " + HttpHeaderValues.CHARSET + '=' + fileUpload.getCharset().name() + "\r\n\r\n"); } else { internal.addValue("\r\n\r\n");
int firstpos = undecodedChunk.readerIndex(); int currentpos = firstpos; int equalpos; String key = decodeAttribute(undecodedChunk.toString(firstpos, equalpos - firstpos, charset), charset); currentAttribute = factory.createAttribute(request, key); firstpos = currentpos; } else if (read == '&') { // special empty FIELD String key = decodeAttribute( undecodedChunk.toString(firstpos, ampersandpos - firstpos, charset), charset); currentAttribute = factory.createAttribute(request, key); currentAttribute.setValue(""); // empty addHttpData(currentAttribute); currentAttribute = null; } else { throw new ErrorDataDecoderException("Bad end of line"); } else if (contRead && currentAttribute != null && currentStatus == MultiPartStatus.FIELD) { undecodedChunk.readerIndex(firstpos); throw new ErrorDataDecoderException(e);
if (!undecodedChunk.hasArray()) { parseBodyAttributesStandard(); return; currentStatus = MultiPartStatus.FIELD; equalpos = currentpos - 1; String key = decodeAttribute(undecodedChunk.toString(firstpos, equalpos - firstpos, charset), charset); currentAttribute = factory.createAttribute(request, key); firstpos = currentpos; } else if (read == '&') { // special empty FIELD currentAttribute = factory.createAttribute(request, key); currentAttribute.setValue(""); // empty addHttpData(currentAttribute); currentAttribute = null; throw new ErrorDataDecoderException("Bad end of line"); } else if (!currentAttribute.isCompleted()) { setFinalBuffer(EMPTY_BUFFER); } else if (contRead && currentAttribute != null && currentStatus == MultiPartStatus.FIELD) { throw new ErrorDataDecoderException(e); } catch (IllegalArgumentException e) { throw new ErrorDataDecoderException(e);
currentFieldAttributes.put(attribute.getName(), attribute); Attribute attribute; try { attribute = factory.createAttribute(request, HttpHeaderNames.CONTENT_TRANSFER_ENCODING.toString(), cleanString(contents[1])); } catch (NullPointerException e) { throw new ErrorDataDecoderException(e); Attribute attribute; try { attribute = factory.createAttribute(request, HttpHeaderNames.CONTENT_LENGTH.toString(), cleanString(contents[1])); } catch (NullPointerException e) { Attribute attribute; try { attribute = factory.createAttribute(request, charsetHeader, cleanString(values)); Attribute attribute; try { attribute = factory.createAttribute(request, cleanString(contents[0]), contents[i]); } catch (NullPointerException e) { currentFieldAttributes.put(attribute.getName(), attribute);
scontentType = DEFAULT_BINARY_CONTENT_TYPE; FileUpload fileUpload = newFactory.createFileUpload(request, name, filename, file.length()); try { fileUpload.setContent(file); addBodyHttpData(fileUpload);
/** * Add a simple attribute in the body as Name=Value * * @param name * name of the parameter * @param value * the value of the parameter * @throws NullPointerException * for name * @throws ErrorDataEncoderException * if the encoding is in error or if the finalize were already done */ public void addBodyAttribute(String name, String value) throws ErrorDataEncoderException { String svalue = value != null? value : StringUtil.EMPTY_STRING; Attribute data = factory.createAttribute(request, checkNotNull(name, "name"), svalue); addBodyHttpData(data); }