io.netty.handler.codec.http.HttpConstants Java Examples

The following examples show how to use io.netty.handler.codec.http.HttpConstants. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpPostMultipartRequestDecoder.java    From dorado with Apache License 2.0 6 votes vote down vote up
/**
 * Clean the String from any unallowed character
 *
 * @return the cleaned String
 */
private static String cleanString(String field) {
	int size = field.length();
	StringBuilder sb = new StringBuilder(size);
	for (int i = 0; i < size; i++) {
		char nextChar = field.charAt(i);
		switch (nextChar) {
		case HttpConstants.COLON:
		case HttpConstants.COMMA:
		case HttpConstants.EQUALS:
		case HttpConstants.SEMICOLON:
		case HttpConstants.HT:
			sb.append(HttpConstants.SP_CHAR);
			break;
		case HttpConstants.DOUBLE_QUOTE:
			// nothing added, just removes it
			break;
		default:
			sb.append(nextChar);
			break;
		}
	}
	return sb.toString().trim();
}
 
Example #2
Source File: HttpPostMultipartRequestDecoder.java    From dorado with Apache License 2.0 6 votes vote down vote up
/**
 * Skip one empty line
 *
 * @return True if one empty line was skipped
 */
private boolean skipOneLine() {
	if (!undecodedChunk.isReadable()) {
		return false;
	}
	byte nextByte = undecodedChunk.readByte();
	if (nextByte == HttpConstants.CR) {
		if (!undecodedChunk.isReadable()) {
			undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 1);
			return false;
		}
		nextByte = undecodedChunk.readByte();
		if (nextByte == HttpConstants.LF) {
			return true;
		}
		undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 2);
		return false;
	}
	if (nextByte == HttpConstants.LF) {
		return true;
	}
	undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 1);
	return false;
}
 
Example #3
Source File: HttpPostMultipartRequestDecoder.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
/**
 * Skip one empty line
 *
 * @return True if one empty line was skipped
 */
private boolean skipOneLine() {
    if (!undecodedChunk.isReadable()) {
        return false;
    }
    byte nextByte = undecodedChunk.readByte();
    if (nextByte == HttpConstants.CR) {
        if (!undecodedChunk.isReadable()) {
            undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 1);
            return false;
        }
        nextByte = undecodedChunk.readByte();
        if (nextByte == HttpConstants.LF) {
            return true;
        }
        undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 2);
        return false;
    }
    if (nextByte == HttpConstants.LF) {
        return true;
    }
    undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 1);
    return false;
}
 
Example #4
Source File: HttpPostMultipartRequestDecoder.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
/**
 * Skip one empty line
 *
 * @return True if one empty line was skipped
 */
private boolean skipOneLine() {
    if (!undecodedChunk.isReadable()) {
        return false;
    }
    byte nextByte = undecodedChunk.readByte();
    if (nextByte == HttpConstants.CR) {
        if (!undecodedChunk.isReadable()) {
            undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 1);
            return false;
        }
        nextByte = undecodedChunk.readByte();
        if (nextByte == HttpConstants.LF) {
            return true;
        }
        undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 2);
        return false;
    }
    if (nextByte == HttpConstants.LF) {
        return true;
    }
    undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 1);
    return false;
}
 
Example #5
Source File: HttpPostMultipartRequestDecoder.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
/**
 * Clean the String from any unallowed character
 *
 * @return the cleaned String
 */
@SuppressWarnings("IfStatementWithIdenticalBranches")
private static String cleanString(String field) {
    StringBuilder sb = new StringBuilder(field.length());
    for (int i = 0; i < field.length(); i++) {
        char nextChar = field.charAt(i);
        if (nextChar == HttpConstants.COLON) {
            sb.append(HttpConstants.SP);
        } else if (nextChar == HttpConstants.COMMA) {
            sb.append(HttpConstants.SP);
        } else if (nextChar == HttpConstants.EQUALS) {
            sb.append(HttpConstants.SP);
        } else if (nextChar == HttpConstants.SEMICOLON) {
            sb.append(HttpConstants.SP);
        } else if (nextChar == HttpConstants.HT) {
            sb.append(HttpConstants.SP);
        } else if (nextChar == HttpConstants.DOUBLE_QUOTE) {
            // nothing added, just removes it
        } else {
            sb.append(nextChar);
        }
    }
    return sb.toString().trim();
}
 
Example #6
Source File: HttpPostMultipartRequestDecoder.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
/**
 * Clean the String from any unallowed character 清除字符串中任何不允许的字符
 *
 * @return the cleaned String
 */
private static String cleanString(String field) {
    int size = field.length();
    StringBuilder sb = new StringBuilder(size);
    for (int i = 0; i < size; i++) {
        char nextChar = field.charAt(i);
        switch (nextChar) {
        case HttpConstants.COLON:
        case HttpConstants.COMMA:
        case HttpConstants.EQUALS:
        case HttpConstants.SEMICOLON:
        case HttpConstants.HT:
            sb.append(HttpConstants.SP_CHAR);
            break;
        case HttpConstants.DOUBLE_QUOTE:
            // nothing added, just removes it
            break;
        default:
            sb.append(nextChar);
            break;
        }
    }
    return sb.toString().trim();
}
 
Example #7
Source File: LineParser.java    From NioImapClient with Apache License 2.0 6 votes vote down vote up
@Override
public boolean process(byte value) throws Exception {
  char nextByte = (char) value;
  if (nextByte == HttpConstants.CR) {
    return true;
  } else if (nextByte == HttpConstants.LF) {
    return false;
  } else {
    if (size >= maxLineLength) {
      throw new TooLongFrameException(
          "Line is larger than " + maxLineLength +
              " bytes.");
    }
    size++;
    seq.append(nextByte);
    return true;
  }
}
 
Example #8
Source File: MqttOverWebsocketProtocol.java    From joyqueue with Apache License 2.0 6 votes vote down vote up
@Override
public boolean process(byte value) throws Exception {
    char nextByte = (char) (value & 0xFF);
    if (nextByte == HttpConstants.CR) {
        return true;
    }
    if (nextByte == HttpConstants.LF) {
        return false;
    }

    if (++ size > maxLength) {
        // TODO: Respond with Bad Request and discard the traffic
        //    or close the connection.
        //       No need to notify the upstream handlers - just log.
        //       If decoding a response, just throw an exception.
        throw newException(maxLength);
    }

    seq.append(nextByte);
    return true;
}
 
Example #9
Source File: HttpPostMultipartRequestDecoder.java    From dorado with Apache License 2.0 5 votes vote down vote up
/**
 * Read one line up to the CRLF or LF
 *
 * @return the String from one line
 * @throws NotEnoughDataDecoderException Need more chunks and reset the
 *                                       {@code readerIndex} to the previous
 *                                       value
 */
private static String readLine(ByteBuf undecodedChunk, Charset charset) {
	if (!undecodedChunk.hasArray()) {
		return readLineStandard(undecodedChunk, charset);
	}
	SeekAheadOptimize sao = new SeekAheadOptimize(undecodedChunk);
	int readerIndex = undecodedChunk.readerIndex();
	try {
		ByteBuf line = buffer(64);

		while (sao.pos < sao.limit) {
			byte nextByte = sao.bytes[sao.pos++];
			if (nextByte == HttpConstants.CR) {
				if (sao.pos < sao.limit) {
					nextByte = sao.bytes[sao.pos++];
					if (nextByte == HttpConstants.LF) {
						sao.setReadPosition(0);
						return line.toString(charset);
					} else {
						// Write CR (not followed by LF)
						sao.pos--;
						line.writeByte(HttpConstants.CR);
					}
				} else {
					line.writeByte(nextByte);
				}
			} else if (nextByte == HttpConstants.LF) {
				sao.setReadPosition(0);
				return line.toString(charset);
			} else {
				line.writeByte(nextByte);
			}
		}
	} catch (IndexOutOfBoundsException e) {
		undecodedChunk.readerIndex(readerIndex);
		throw new NotEnoughDataDecoderException(e);
	}
	undecodedChunk.readerIndex(readerIndex);
	throw new NotEnoughDataDecoderException();
}
 
Example #10
Source File: CookieUtil.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
static void add(StringBuilder sb, String name, String val) {
    sb.append(name);
    sb.append((char) HttpConstants.EQUALS);
    sb.append(val);
    sb.append((char) HttpConstants.SEMICOLON);
    sb.append((char) HttpConstants.SP);
}
 
Example #11
Source File: CookieUtil.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
static void add(StringBuilder sb, String name, long val) {
    sb.append(name);
    sb.append((char) HttpConstants.EQUALS);
    sb.append(val);
    sb.append((char) HttpConstants.SEMICOLON);
    sb.append((char) HttpConstants.SP);
}
 
Example #12
Source File: RtspProtocol.java    From spring-boot-protocol with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canSupport(ByteBuf msg) {
    int protocolEndIndex = IOUtil.indexOf(msg, HttpConstants.LF);
    if(protocolEndIndex < 9){
        return false;
    }

    if(msg.getByte(protocolEndIndex - 9) == 'R'
            && msg.getByte(protocolEndIndex - 8) == 'T'
            && msg.getByte(protocolEndIndex - 7) == 'S'
            &&  msg.getByte(protocolEndIndex - 6) == 'P'){
        return true;
    }
    return false;
}
 
Example #13
Source File: HttpPostRequestEncoderTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Test
public void testDataIsMultipleOfChunkSize1() throws Exception {
    DefaultHttpDataFactory factory = new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE);
    DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
            HttpMethod.POST, "http://localhost");
    HttpPostRequestEncoder encoder = new HttpPostRequestEncoder(factory, request, true,
            HttpConstants.DEFAULT_CHARSET, HttpPostRequestEncoder.EncoderMode.RFC1738);

    MemoryFileUpload first = new MemoryFileUpload("resources", "", "application/json", null,
            CharsetUtil.UTF_8, -1);
    first.setMaxSize(-1);
    first.setContent(new ByteArrayInputStream(new byte[7955]));
    encoder.addBodyHttpData(first);

    MemoryFileUpload second = new MemoryFileUpload("resources2", "", "application/json", null,
            CharsetUtil.UTF_8, -1);
    second.setMaxSize(-1);
    second.setContent(new ByteArrayInputStream(new byte[7928]));
    encoder.addBodyHttpData(second);

    assertNotNull(encoder.finalizeRequest());

    checkNextChunkSize(encoder, 8080);
    checkNextChunkSize(encoder, 8080);

    HttpContent httpContent = encoder.readChunk((ByteBufAllocator) null);
    assertTrue("Expected LastHttpContent is not received", httpContent instanceof LastHttpContent);
    httpContent.release();

       assertTrue("Expected end of input is not receive", encoder.isEndOfInput());
}
 
Example #14
Source File: AbstractMemoryHttpData.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public String getString(Charset encoding) {
    if (byteBuf == null) {
        return "";
    }
    if (encoding == null) {
        encoding = HttpConstants.DEFAULT_CHARSET;
    }
    return byteBuf.toString(encoding);
}
 
Example #15
Source File: CookieUtil.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
static void addQuoted(StringBuilder sb, String name, String val) {
    if (val == null) {
        val = "";
    }

    sb.append(name);
    sb.append((char) HttpConstants.EQUALS);
    sb.append((char) HttpConstants.DOUBLE_QUOTE);
    sb.append(val);
    sb.append((char) HttpConstants.DOUBLE_QUOTE);
    sb.append((char) HttpConstants.SEMICOLON);
    sb.append((char) HttpConstants.SP);
}
 
Example #16
Source File: HttpPostMultipartRequestDecoder.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
/**
 * Load the field value or file data from a Multipart request 从多部分请求加载字段值或文件数据
 *
 * @return {@code true} if the last chunk is loaded (boundary delimiter found), {@code false} if need more chunks
 * @throws ErrorDataDecoderException
 */
private static boolean loadDataMultipartStandard(ByteBuf undecodedChunk, String delimiter, HttpData httpData) {
    final int startReaderIndex = undecodedChunk.readerIndex();
    final int delimeterLength = delimiter.length();
    int index = 0;
    int lastPosition = startReaderIndex;
    byte prevByte = HttpConstants.LF;
    boolean delimiterFound = false;
    while (undecodedChunk.isReadable()) {
        final byte nextByte = undecodedChunk.readByte();
        // Check the delimiter
        if (prevByte == HttpConstants.LF && nextByte == delimiter.codePointAt(index)) {
            index++;
            if (delimeterLength == index) {
                delimiterFound = true;
                break;
            }
            continue;
        }
        lastPosition = undecodedChunk.readerIndex();
        if (nextByte == HttpConstants.LF) {
            index = 0;
            lastPosition -= (prevByte == HttpConstants.CR)? 2 : 1;
        }
        prevByte = nextByte;
    }
    if (prevByte == HttpConstants.CR) {
        lastPosition--;
    }
    ByteBuf content = undecodedChunk.copy(startReaderIndex, lastPosition - startReaderIndex);
    try {
        httpData.addContent(content, delimiterFound);
    } catch (IOException e) {
        throw new ErrorDataDecoderException(e);
    }
    undecodedChunk.readerIndex(lastPosition);
    return delimiterFound;
}
 
Example #17
Source File: HttpPostMultipartRequestDecoder.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
/**
 * Read one line up to the CRLF or LF
 *
 * @return the String from one line
 * @throws NotEnoughDataDecoderException
 *             Need more chunks and reset the {@code readerIndex} to the previous
 *             value
 */
private static String readLine(ByteBuf undecodedChunk, Charset charset) {
    if (!undecodedChunk.hasArray()) {
        return readLineStandard(undecodedChunk, charset);
    }
    SeekAheadOptimize sao = new SeekAheadOptimize(undecodedChunk);
    int readerIndex = undecodedChunk.readerIndex();
    try {
        ByteBuf line = buffer(64);

        while (sao.pos < sao.limit) {
            byte nextByte = sao.bytes[sao.pos++];
            if (nextByte == HttpConstants.CR) {
                if (sao.pos < sao.limit) {
                    nextByte = sao.bytes[sao.pos++];
                    if (nextByte == HttpConstants.LF) {
                        sao.setReadPosition(0);
                        return line.toString(charset);
                    } else {
                        // Write CR (not followed by LF)
                        sao.pos--;
                        line.writeByte(HttpConstants.CR);
                    }
                } else {
                    line.writeByte(nextByte);
                }
            } else if (nextByte == HttpConstants.LF) {
                sao.setReadPosition(0);
                return line.toString(charset);
            } else {
                line.writeByte(nextByte);
            }
        }
    } catch (IndexOutOfBoundsException e) {
        undecodedChunk.readerIndex(readerIndex);
        throw new NotEnoughDataDecoderException(e);
    }
    undecodedChunk.readerIndex(readerIndex);
    throw new NotEnoughDataDecoderException();
}
 
Example #18
Source File: HttpPostMultipartRequestDecoder.java    From dorado with Apache License 2.0 5 votes vote down vote up
/**
 * Read one line up to the CRLF or LF
 *
 * @return the String from one line
 * @throws NotEnoughDataDecoderException Need more chunks and reset the
 *                                       {@code readerIndex} to the previous
 *                                       value
 */
private static String readLineStandard(ByteBuf undecodedChunk, Charset charset) {
	int readerIndex = undecodedChunk.readerIndex();
	try {
		ByteBuf line = buffer(64);

		while (undecodedChunk.isReadable()) {
			byte nextByte = undecodedChunk.readByte();
			if (nextByte == HttpConstants.CR) {
				// check but do not changed readerIndex
				nextByte = undecodedChunk.getByte(undecodedChunk.readerIndex());
				if (nextByte == HttpConstants.LF) {
					// force read
					undecodedChunk.readByte();
					return line.toString(charset);
				} else {
					// Write CR (not followed by LF)
					line.writeByte(HttpConstants.CR);
				}
			} else if (nextByte == HttpConstants.LF) {
				return line.toString(charset);
			} else {
				line.writeByte(nextByte);
			}
		}
	} catch (IndexOutOfBoundsException e) {
		undecodedChunk.readerIndex(readerIndex);
		throw new NotEnoughDataDecoderException(e);
	}
	undecodedChunk.readerIndex(readerIndex);
	throw new NotEnoughDataDecoderException();
}
 
Example #19
Source File: HttpPostMultipartRequestDecoder.java    From dorado with Apache License 2.0 5 votes vote down vote up
/**
 * Load the field value or file data from a Multipart request
 *
 * @return {@code true} if the last chunk is loaded (boundary delimiter found),
 *         {@code false} if need more chunks
 * @throws ErrorDataDecoderException
 */
private static boolean loadDataMultipartStandard(ByteBuf undecodedChunk, String delimiter, HttpData httpData) {
	final int startReaderIndex = undecodedChunk.readerIndex();
	final int delimeterLength = delimiter.length();
	int index = 0;
	int lastPosition = startReaderIndex;
	byte prevByte = HttpConstants.LF;
	boolean delimiterFound = false;
	while (undecodedChunk.isReadable()) {
		final byte nextByte = undecodedChunk.readByte();
		// Check the delimiter
		if (prevByte == HttpConstants.LF && nextByte == delimiter.codePointAt(index)) {
			index++;
			if (delimeterLength == index) {
				delimiterFound = true;
				break;
			}
			continue;
		}
		lastPosition = undecodedChunk.readerIndex();
		if (nextByte == HttpConstants.LF) {
			index = 0;
			lastPosition -= (prevByte == HttpConstants.CR) ? 2 : 1;
		}
		prevByte = nextByte;
	}
	if (prevByte == HttpConstants.CR) {
		lastPosition--;
	}
	ByteBuf content = undecodedChunk.copy(startReaderIndex, lastPosition - startReaderIndex);
	try {
		httpData.addContent(content, delimiterFound);
	} catch (IOException e) {
		throw new ErrorDataDecoderException(e);
	}
	undecodedChunk.readerIndex(lastPosition);
	return delimiterFound;
}
 
Example #20
Source File: CookieUtil.java    From styx with Apache License 2.0 5 votes vote down vote up
static void add(StringBuilder sb, String name, long val) {
    sb.append(name);
    sb.append((char) HttpConstants.EQUALS);
    sb.append(val);
    sb.append((char) HttpConstants.SEMICOLON);
    sb.append((char) HttpConstants.SP);
}
 
Example #21
Source File: CookieUtil.java    From styx with Apache License 2.0 5 votes vote down vote up
static void add(StringBuilder sb, String name, String val) {
    sb.append(name);
    sb.append((char) HttpConstants.EQUALS);
    sb.append(val);
    sb.append((char) HttpConstants.SEMICOLON);
    sb.append((char) HttpConstants.SP);
}
 
Example #22
Source File: CookieUtil.java    From styx with Apache License 2.0 5 votes vote down vote up
static void addQuoted(StringBuilder sb, String name, String val) {
    if (val == null) {
        val = "";
    }

    sb.append(name);
    sb.append((char) HttpConstants.EQUALS);
    sb.append((char) HttpConstants.DOUBLE_QUOTE);
    sb.append(val);
    sb.append((char) HttpConstants.DOUBLE_QUOTE);
    sb.append((char) HttpConstants.SEMICOLON);
    sb.append((char) HttpConstants.SP);
}
 
Example #23
Source File: ResponseDecoder.java    From NioImapClient with Apache License 2.0 5 votes vote down vote up
private UntaggedSearchResponse parseSearch(ByteBuf in) {
  List<Long> ids = new ArrayList<>();
  for (; ; ) {
    char c = ((char) in.readUnsignedByte());
    in.readerIndex(in.readerIndex() - 1);
    if (c == HttpConstants.CR || c == HttpConstants.LF) {
      lineParser.parse(in);
      break;
    }

    ids.add(Long.parseLong(atomOrStringParser.parse(in)));
  }

  return new UntaggedSearchResponse(ids);
}
 
Example #24
Source File: ResponseDecoder.java    From NioImapClient with Apache License 2.0 5 votes vote down vote up
/**
 * Reset checks to see if we are at the end of this response line. If not it fast forwards the buffer to the end of this line to prepare for the next response.
 *
 * @param in
 */
private void reset(ByteBuf in) {
  char c = (char) in.readUnsignedByte();
  if (c == UNTAGGED_PREFIX || c == CONTINUATION_PREFIX || c == TAGGED_PREFIX) { // We are already at the end of the line
    in.readerIndex(in.readerIndex() - 1);
  } else if (!(c == HttpConstants.CR || c == HttpConstants.LF)) {
    lineParser.parse(in);
  }

  discardSomeReadBytes();
  responseBuilder = new TaggedResponse.Builder();
  checkpoint(State.START_RESPONSE);
}
 
Example #25
Source File: HttpPostMultipartRequestDecoder.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
/**
 * Read one line up to the CRLF or LF
 *
 * @return the String from one line
 * @throws NotEnoughDataDecoderException
 *             Need more chunks and reset the readerInder to the previous
 *             value
 */
private String readLineStandard() {
    int readerIndex = undecodedChunk.readerIndex();
    try {
        ByteBuf line = buffer(64);

        while (undecodedChunk.isReadable()) {
            byte nextByte = undecodedChunk.readByte();
            if (nextByte == HttpConstants.CR) {
                // check but do not changed readerIndex
                nextByte = undecodedChunk.getByte(undecodedChunk.readerIndex());
                if (nextByte == HttpConstants.LF) {
                    // force read
                    undecodedChunk.readByte();
                    return line.toString(charset);
                } else {
                    // Write CR (not followed by LF)
                    line.writeByte(HttpConstants.CR);
                }
            } else if (nextByte == HttpConstants.LF) {
                return line.toString(charset);
            } else {
                line.writeByte(nextByte);
            }
        }
    } catch (IndexOutOfBoundsException e) {
        undecodedChunk.readerIndex(readerIndex);
        throw new NotEnoughDataDecoderException(e);
    }
    undecodedChunk.readerIndex(readerIndex);
    throw new NotEnoughDataDecoderException();
}
 
Example #26
Source File: AbstractMemoryHttpData.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
public String getString(Charset encoding) {
    if (byteBuf == null) {
        return "";
    }
    if (encoding == null) {
        encoding = HttpConstants.DEFAULT_CHARSET;
    }
    return byteBuf.toString(encoding);
}
 
Example #27
Source File: CookieUtil.java    From armeria with Apache License 2.0 5 votes vote down vote up
static void add(StringBuilder sb, String name, long val) {
    sb.append(name);
    sb.append('=');
    sb.append(val);
    sb.append(';');
    sb.append(HttpConstants.SP_CHAR);
}
 
Example #28
Source File: CookieUtil.java    From armeria with Apache License 2.0 5 votes vote down vote up
static void add(StringBuilder sb, String name, String val) {
    sb.append(name);
    sb.append('=');
    sb.append(val);
    sb.append(';');
    sb.append(HttpConstants.SP_CHAR);
}
 
Example #29
Source File: CookieUtil.java    From armeria with Apache License 2.0 5 votes vote down vote up
static void addQuoted(StringBuilder sb, String name, @Nullable String val) {
    if (val == null) {
        val = "";
    }

    sb.append(name);
    sb.append('=');
    sb.append('"');
    sb.append(val);
    sb.append('"');
    sb.append(';');
    sb.append(HttpConstants.SP_CHAR);
}
 
Example #30
Source File: MultipartFormUpload.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
public MultipartFormUpload(Context context,
                           MultipartForm parts,
                           boolean multipart,
                           HttpPostRequestEncoder.EncoderMode encoderMode) throws Exception {
  this.context = context;
  this.pending = new InboundBuffer<>(context)
    .handler(this::handleChunk)
    .drainHandler(v -> run()).pause();
  this.request = new DefaultFullHttpRequest(
    HttpVersion.HTTP_1_1,
    io.netty.handler.codec.http.HttpMethod.POST,
    "/");
  this.encoder = new HttpPostRequestEncoder(
    new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE),
    request,
    multipart,
    HttpConstants.DEFAULT_CHARSET,
    encoderMode);
  for (FormDataPart formDataPart : parts) {
    if (formDataPart.isAttribute()) {
      encoder.addBodyAttribute(formDataPart.name(), formDataPart.value());
    } else {
      encoder.addBodyFileUpload(formDataPart.name(),
        formDataPart.filename(), new File(formDataPart.pathname()),
        formDataPart.mediaType(), formDataPart.isText());
    }
  }
  encoder.finalizeRequest();
}