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
fix: handle http response code 307 - temporary redirect #571
Conversation
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.
LGTM
I would like get 307 is handled to redirect to received location or error out. Till then 👎 |
// Handle 307 (temporary redirect) specially. | ||
String location = response.headers().get("Location"); | ||
if (location == null || location.isEmpty()) { | ||
throw new InternalException("unexpected empty value in location header"); |
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.
IMO, this is a server issue, not internal to the SDK. Is InternalException
justified here?
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.
IMO, this is a server issue, not internal to the SDK. Is InternalException justified here?
@balamurugana your views on this?
Response response = null; | ||
|
||
// Loop to retry with new location of 307. | ||
for (int i = 0; i < TEMP_REDIRECT_TRY_COUNT; i++) { |
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.
Instead of doing all the process in the loop, may be it is better to get in the loop only when 307 is received? IMO that will be more readable.
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.
The loop is continued only for 307. What is all the process in the loop?
My suggestion to 307 is that SDK should error out instead of retrying its own. Auto-retry doesn't solve real problem ie put object doesn't work (not only for minio-java).
Minio server returns 307 only for http
to https
. https
would invite other problems like ignoring self signed certificate.
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 agree, I assumed request could be made outside the for loop but that is not right. This is fine.
@nitisht anything pending here for you review? |
@harshavardhana just one comment, other than that LGTM |
@harshavardhana there are issues handling 307 for all the cases (in all the libraries). Amazon AWS S3 sends 307 and new location for temporary resource change, however in minio server, it is used as Assume the case of This needs to be discussed and taken forward accordingly. |
Here is how the redirection happens
Are you saying something else? |
You are right // cc @vadmeste can you comment? |
Yes, right. But this bug is already fixed in go1.8. I already compiled mc with go1.8 and it works fine. @balamurugana, did you test enabling automatic redirect in the http library ? |
Do you mean golang http library or okhttp? |
okhttp. I mean I wonder what's the default behavior of okhttp when it receives 307 redirect. |
307 is not handled in OkHttp. Its consumer's responsibility. |
@balamurugana this requires a rebase.. |
// Handle 307 (temporary redirect) specially. | ||
String location = response.headers().get("Location"); | ||
if (location == null || location.isEmpty()) { | ||
throw new InternalException("unexpected empty value in location header"); |
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.
IMO, this is a server issue, not internal to the SDK. Is InternalException justified here?
@balamurugana your views on this?
@balamurugana can you rebase the PR? |
Previously the SDK throws below exception ``` java.io.EOFException: input contained no data at org.xmlpull.mxp1.MXParser.fillBuf(MXParser.java:3003) at org.xmlpull.mxp1.MXParser.more(MXParser.java:3046) at org.xmlpull.mxp1.MXParser.parseProlog(MXParser.java:1410) at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1395) at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093) at com.google.api.client.xml.Xml.parseElementInternal(Xml.java:245) at com.google.api.client.xml.Xml.parseElement(Xml.java:222) at io.minio.messages.XmlEntity.parseXml(XmlEntity.java:75) at io.minio.messages.ErrorResponse.parseXml(ErrorResponse.java:159) at io.minio.messages.ErrorResponse.<init>(ErrorResponse.java:64) at io.minio.MinioClient.execute(MinioClient.java:970) at io.minio.MinioClient.executePut(MinioClient.java:1197) at io.minio.MinioClient.makeBucket(MinioClient.java:2597) at io.minio.MinioClient.makeBucket(MinioClient.java:2554) at FunctionalTest.makeBucket_test1(FunctionalTest.java:86) at FunctionalTest.runTests(FunctionalTest.java:1264) at FunctionalTest.main(FunctionalTest.java:1380) ``` when it gets response code 307. This patch handles followup location provided in server response upto 21 times like Firefox, Chrome and OkHttp.
Previously the SDK throws below exception when it gets response code 307. ``` java.io.EOFException: input contained no data at org.xmlpull.mxp1.MXParser.fillBuf(MXParser.java:3003) at org.xmlpull.mxp1.MXParser.more(MXParser.java:3046) at org.xmlpull.mxp1.MXParser.parseProlog(MXParser.java:1410) at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1395) at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093) at com.google.api.client.xml.Xml.parseElementInternal(Xml.java:245) at com.google.api.client.xml.Xml.parseElement(Xml.java:222) at io.minio.messages.XmlEntity.parseXml(XmlEntity.java:75) at io.minio.messages.ErrorResponse.parseXml(ErrorResponse.java:159) at io.minio.messages.ErrorResponse.<init>(ErrorResponse.java:64) at io.minio.MinioClient.execute(MinioClient.java:970) at io.minio.MinioClient.executePut(MinioClient.java:1197) at io.minio.MinioClient.makeBucket(MinioClient.java:2597) at io.minio.MinioClient.makeBucket(MinioClient.java:2554) at FunctionalTest.makeBucket_test1(FunctionalTest.java:86) at FunctionalTest.runTests(FunctionalTest.java:1264) at FunctionalTest.main(FunctionalTest.java:1380) ``` This patch handles response code and returns Amazon S3 error.
c7204fb
to
7a74518
Compare
Please note that this PR returns "Redirect" amazon S3 error, not following new location automatically. |
What is going on with this PR? @nitisht @balamurugana @vadmeste ? |
@harshavardhana waiting on @nitisht's review |
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 understand it was decided to just respond with ErrorCode.REDIRECT
instead of actually redirecting. LGTM in that case
Previously the SDK throws below exception when it gets response code 307.
This patch handles response code and returns Amazon S3 error.