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

Fix issues with HTTP redirects and file upload #514

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

z3ntu
Copy link

@z3ntu z3ntu commented Oct 3, 2020

Firstly the test setup:

  • Nextcloud running behind a reverse proxy (e.g. Traefik) configured for HTTP only
  • Configure Nextcloud app to connect to that server
  • Configure https on reverse proxy, enable http -> https redirects on the reverse proxy
    • Traefik uses the HTTP 308 status code to redirect clients
  • Try to upload some pictures via the Auto upload feature

Previously this resulted in the following notification being sent to the user:
Screenshot_20201003-185029_2

With these patches I can successfully upload pictures to my server.

See commit messages for more details.

z3ntu added 3 commits October 3, 2020 18:56
The status code 308 (Permanent Redirect) is defined in RFC 7538 and used
e.g. by Traefik for redirection.

The used version of commons-httpclient doesn't yet include a constant
for that status code so use the integer directly.

Signed-off-by: Luca Weiss <luca@z3ntu.xyz>
In certain cases when we try to upload a file the server can respond
back with a redirect and close the connection before we're done writing
content to the server which results in a 'java.net.SocketException:
Broken pipe' exception. We can solve that by asking the server first
whether we can actually write data (the rest is handled by the
httpclient library).

See also:
http://httpcomponents.10934.n7.nabble.com/Broken-pipe-Write-failed-when-making-Unauthorized-request-tp34235p34245.html

Signed-off-by: Luca Weiss <luca@z3ntu.xyz>
Previously redirects with new webdav paths resulted in an
IndexOutOfBoundsException as String.substring() was called with a -1
index.

Signed-off-by: Luca Weiss <luca@z3ntu.xyz>
@nextcloud-android-bot
Copy link
Collaborator

Lint

TypemasterPR
Warnings11
Errors00

SpotBugs (new)

Warning TypeNumber
Bad practice Warnings14
Correctness Warnings38
Internationalization Warnings6
Malicious code vulnerability Warnings7
Multithreaded correctness Warnings3
Performance Warnings17
Security Warnings1
Dodgy code Warnings40
Total126

SpotBugs (master)

Warning TypeNumber
Bad practice Warnings14
Correctness Warnings38
Internationalization Warnings6
Malicious code vulnerability Warnings7
Multithreaded correctness Warnings3
Performance Warnings17
Security Warnings1
Dodgy code Warnings40
Total126

@codecov
Copy link

codecov bot commented Oct 3, 2020

Codecov Report

Merging #514 into master will increase coverage by 0.06%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master     #514      +/-   ##
==========================================
+ Coverage   39.76%   39.82%   +0.06%     
==========================================
  Files         137      137              
  Lines        5970     5978       +8     
  Branches      784      789       +5     
==========================================
+ Hits         2374     2381       +7     
- Misses       3235     3238       +3     
+ Partials      361      359       -2     
Impacted Files Coverage Δ
.../main/java/com/nextcloud/common/NextcloudClient.kt 50.76% <0.00%> (-2.46%) ⬇️
...om/owncloud/android/lib/common/OwnCloudClient.java 38.95% <0.00%> (-0.93%) ⬇️
...ources/files/ChunkedFileUploadRemoteOperation.java 22.76% <0.00%> (-0.19%) ⬇️
...d/lib/common/operations/RemoteOperationResult.java 43.29% <0.00%> (+1.21%) ⬆️
...lib/resources/files/RemoveFileRemoteOperation.java 84.21% <0.00%> (+15.78%) ⬆️

@tobiasKaminsky
Copy link
Member

Sorry for coming back this late…
Permanent redirects should already be handled via login, so that the real redirected url is stored.
This way we do not have to do multiple hops per each request.

Have you changed your system after installing the app?

@z3ntu
Copy link
Author

z3ntu commented Nov 4, 2020

Yes, as mentioned in the original message, the permanent redirect was added after the initial login leading to the issues I was seeing.

@tobiasKaminsky
Copy link
Member

Hm. But this then means, that every request is done to times: first against old, get redirect, then to new url.
As the library does not store the base url, this should be handled on app side, to update it, once it sees a permanet redirect.

Do you have an idea how to inform the client?

@z3ntu
Copy link
Author

z3ntu commented Nov 8, 2020

Right.. But as non-HTTP 308 redirect statuses already redirect properly I don't think solving this is in the scope of this - and this PR is just adjusting existing redirect code (for the most part).

Also I'm too unfamiliar with the Nextcloud App codebase with regard to updating the base url.

@tobiasKaminsky
Copy link
Member

I will have a deeper look into this soon.
Currently I am a bit too busy, but I will not forget your PR.

@z3ntu
Copy link
Author

z3ntu commented Apr 26, 2023

but I will not forget your PR.

Safe to say this was forgotten.

I'll leave this open but my setup has changed in the meantime so I'm not directly interested in this anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants