Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Long to represent Content-Length #357

Merged
merged 5 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import static com.hotels.styx.api.RequestCookie.decode;
import static com.hotels.styx.api.RequestCookie.encode;
import static io.netty.buffer.Unpooled.copiedBuffer;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.util.Arrays.asList;
import static java.util.Objects.requireNonNull;
import static java.util.UUID.randomUUID;
Expand Down Expand Up @@ -730,7 +730,7 @@ private Optional<String> requireNotDuplicatedHeader(CharSequence headerName) {

private static boolean isInteger(String contentLength) {
try {
parseInt(contentLength);
parseLong(contentLength);
return true;
} catch (NumberFormatException e) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import static com.hotels.styx.api.ResponseCookie.decode;
import static com.hotels.styx.api.ResponseCookie.encode;
import static io.netty.buffer.Unpooled.copiedBuffer;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.util.Arrays.asList;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -571,7 +571,7 @@ Builder ensureContentLengthIsValid() {

private static boolean isInteger(String contentLength) {
try {
parseInt(contentLength);
parseLong(contentLength);
return true;
} catch (NumberFormatException e) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ default List<String> headers(CharSequence name) {
*
* @return the content-length if present
*/
default Optional<Integer> contentLength() {
return header(CONTENT_LENGTH).map(Integer::valueOf);
default Optional<Long> contentLength() {
return header(CONTENT_LENGTH).map(Long::valueOf);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import static com.hotels.styx.api.RequestCookie.encode;
import static io.netty.buffer.ByteBufUtil.getBytes;
import static io.netty.buffer.Unpooled.copiedBuffer;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.util.Arrays.asList;
import static java.util.Objects.requireNonNull;
import static java.util.UUID.randomUUID;
Expand Down Expand Up @@ -1017,7 +1017,7 @@ private Optional<String> requireNotDuplicatedHeader(CharSequence headerName) {

private static boolean isInteger(String contentLength) {
try {
parseInt(contentLength);
parseLong(contentLength);
return true;
} catch (NumberFormatException e) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import static com.hotels.styx.api.ResponseCookie.decode;
import static com.hotels.styx.api.ResponseCookie.encode;
import static io.netty.buffer.ByteBufUtil.getBytes;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.util.Arrays.asList;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -871,7 +871,7 @@ Builder ensureContentLengthIsValid() {

private static boolean isInteger(String contentLength) {
try {
parseInt(contentLength);
parseLong(contentLength);
return true;
} catch (NumberFormatException e) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
*/
package com.hotels.styx.proxy.interceptors;

import com.hotels.styx.api.Eventual;
import com.hotels.styx.api.HttpInterceptor;
import com.hotels.styx.api.LiveHttpRequest;
import com.hotels.styx.api.LiveHttpResponse;
import com.hotels.styx.api.Eventual;

import java.util.Optional;

import static com.hotels.styx.api.HttpHeaderNames.CONTENT_LENGTH;
import com.hotels.styx.api.LiveHttpRequest;

/**
* Fixes bad content length headers.
Expand All @@ -34,7 +34,7 @@ public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain chain
}

private static LiveHttpRequest removeBadContentLength(LiveHttpRequest request) {
Optional<Integer> contentLength = request.contentLength();
Optional<Long> contentLength = request.contentLength();
if (contentLength.isPresent() && request.chunked()) {
return request.newBuilder()
.removeHeader(CONTENT_LENGTH)
Expand Down