-
Notifications
You must be signed in to change notification settings - Fork 88
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
Add support for fixed ContentLength #32
base: main
Are you sure you want to change the base?
Add support for fixed ContentLength #32
Conversation
Some servers do not support chunked message. Sending whole *part* in a single message would help to interact with such servers.
Can you elaborate more about what the problem is and how this PR fixes it? |
For what I understood, the previous implementation of tus-java-client is based on chunked transfer encoding and the server I tried to use seems to not support this encoding. Effect: the server considers the client sent an empty message. The fix consists in adding an I tested it yesterday and it gives full satisfaction. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation. That makes sense.
The Java HTTP client library is able to automatically set the Content-Length.
I'd also like to know on plans for merging this @Acconut |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the delay on my side, this PR slipped under my radar. This is a sensitive area of tus-java-client so I might be very picky about changes here :)
@@ -115,6 +116,39 @@ public boolean removeFingerprintOnSuccessEnabled() { | |||
return removeFingerprintOnSuccessEnabled; | |||
} | |||
|
|||
/** | |||
* Enable chunked transfer encoding. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you expand the comment a bit to explain what the advantages/disadvantages/impacts of enabling/disabling chunked transfer encoding has?
bytesToRead = Math.min(getChunkSize(), bytesRemainingForRequest); | ||
else { | ||
// No chunked tranfer encoding, so we upload a single chunk. | ||
bytesToRead = getChunkSize(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is still some confusion about the chunk size vs payload size. Traditionally the payload size determines how big the body of a HTTP can get. The chunk size on the other hand says, how much data is read from the input stream and written to the TCP connection in one iteration. Usually, you write multiple chunks per HTTP request, so the payload size is bigger than the chunk size.
However, if I understand this correctly, the chunk size now determines how big a HTTP request gets and the payload size is not used anymore. This would be contrary to how tus-java-client behaves when chunked transfer is enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did the opposite reasoning:
chunk size exists because something in the chain does not support more than that. So, when chunk transfer is not supported, it seems better to use TUS protocol in place of chunk transfer and then, send many complete HTTP+TUS messages based on chunk size.
Furthermore, as a dumb user, I only wish things work without having to fine tune chunk size or payload size, depending on the server's capabilities. I like automagical approach. :-)
But I'm completly new to all of this. So I don't know what sort of logic is expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chunk size exists because something in the chain does not support more than that.
That's not entirely true. The reason for chunk size is that the user can control how much data is read from the input source in one go. This is important to control how big the in-memory buffer of tus-java-client is, in order to avoid excess memory usage.
You are referring to the payload size when you say "something [e.g. a proxy] in the chain does not support more than that". Does that make sense?
Furthermore, as a dumb user, I only wish things work without having to fine tune chunk size or payload size, depending on the server's capabilities. I like automagical approach. :-)
Yes, I would like that as well and it will likely come in the next major release but not right now :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is important to control how big the in-memory buffer of tus-java-client is, in order to avoid excess memory usage.
OK, so you state that client (memory) is "something in the chain does not support more than that", first part of the chain.
@EverydayPineapple @foxware00 Thanks for reminding me about this. There are no plans for merging it but I got some more feedback we need to look into. |
@Acconut thank you. This is critical for me, for the usage of Tus. A present we're running this branch internally until it's upstreamed. Many thanks |
Let's see if @gbonnefille is still interested in this PR. Otherwise someone else would have to pick it up since I don't have time to work on it directly. If you are interested in doing so, let me know :) |
Sure if @gbonnefille isn't happy to do it. I would be happy to apply your changes |
I'm still interested on it, but spare time is lacking now. I hope to do something on this during the week. |
Perfect, let me know if you need help. |
Hey guys |
I think there are still some open comments from me that would need to be addressed before we can merge. If there is still some interest in getting this merged, I am happy to review the work! In the future I hope to replace the HTTPUrlConnection with a more flexible HTTP Client (maybe OkHttp or something), which would make this code not necessary anymore. |
@Acconut I was picking this back up as I've noticed an issue in this logic around chunking/payload size. If I understand your open question correctly. Is it that payload size == chunk size when chunked transfer is disabled? This seems to make sense to me, I'm interested in a way to solve it, but one way is removing the extra code to close the connection and force chunk/payload to be the smaller of the two when chunkedTransferEncoding is disabled. In doing so, you negate the need for the additional code closing the connection and the logic within My question to you is how this fits in the the library, I'm happy to make the change. I feel we just need to document logic around chunk/payload being only valid in chunkedEncodingMode. Such as below
Another option is to ignore the chunkSize when chunkedEncoding is disabled and fallback to payload size. Then,
|
See #32 (review) |
Some servers do not support chunked message.
Sending whole part in a single message
would help to interact with such servers.