-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 custom PatchMethod class to use http PATCH requests with the Nextcloud SSO api #8818
Merged
AndyScherzinger
merged 4 commits into
nextcloud:master
from
binsky08:add-sso-patch-method
Sep 27, 2021
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
55bdbc1
add custom PatchMethod class to use http PATCH requests with the Next…
binsky08 238c7d6
add license header, clear comments in PatchMethod class
binsky08 f25d85a
increase SpotBugs to 464 to accept the new PatchMethod class for the …
binsky08 5e6e3d4
Merge branch 'master' into add-sso-patch-method
binsky08 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
460 | ||
462 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
src/main/java/com/nextcloud/android/sso/PatchMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* Nextcloud SingleSignOn | ||
* | ||
* @author Timo Triebensky | ||
* Copyright (C) 2021 Timo Triebensky | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* More information here: https://github.com/abeluck/android-streams-ipc | ||
* | ||
* ==================================================================== | ||
* | ||
* The required methods of this class are copied and customized from PostMethod. | ||
*/ | ||
|
||
package com.nextcloud.android.sso; | ||
|
||
import org.apache.commons.httpclient.methods.ByteArrayRequestEntity; | ||
import org.apache.commons.httpclient.methods.EntityEnclosingMethod; | ||
import org.apache.commons.httpclient.methods.PostMethod; | ||
import org.apache.commons.httpclient.methods.RequestEntity; | ||
import org.apache.commons.httpclient.util.EncodingUtil; | ||
|
||
import java.util.Vector; | ||
|
||
public class PatchMethod extends PostMethod { | ||
|
||
/** | ||
* The buffered request body consisting of <code>NameValuePair</code>s. | ||
*/ | ||
private Vector params = new Vector(); | ||
|
||
/** | ||
* No-arg constructor. | ||
*/ | ||
public PatchMethod() { | ||
super(); | ||
} | ||
|
||
/** | ||
* Constructor specifying a URI. | ||
* | ||
* @param uri either an absolute or relative URI | ||
*/ | ||
public PatchMethod(String uri) { | ||
super(uri); | ||
} | ||
|
||
/** | ||
* Returns <tt>"PATCH"</tt>. | ||
* | ||
* @return <tt>"PATCH"</tt> | ||
* @since 2.0 | ||
*/ | ||
@Override | ||
public String getName() { | ||
return "PATCH"; | ||
} | ||
|
||
/** | ||
* Returns <tt>true</tt> if there is a request body to be sent. | ||
* | ||
* @return boolean | ||
* @since 2.0beta1 | ||
*/ | ||
protected boolean hasRequestContent() { | ||
if (!this.params.isEmpty()) { | ||
return true; | ||
} else { | ||
return super.hasRequestContent(); | ||
} | ||
} | ||
|
||
/** | ||
* Clears request body. | ||
* | ||
* @since 2.0beta1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is from c&p I assume, so please remove. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed it |
||
*/ | ||
protected void clearRequestBody() { | ||
this.params.clear(); | ||
super.clearRequestBody(); | ||
} | ||
|
||
/** | ||
* Generates a request entity from the patch parameters, if present. Calls {@link | ||
* EntityEnclosingMethod#generateRequestBody()} if parameters have not been set. | ||
* | ||
* @since 3.0 | ||
*/ | ||
protected RequestEntity generateRequestEntity() { | ||
if (!this.params.isEmpty()) { | ||
// Use a ByteArrayRequestEntity instead of a StringRequestEntity. | ||
// This is to avoid potential encoding issues. Form url encoded strings | ||
// are ASCII by definition but the content type may not be. Treating the content | ||
// as bytes allows us to keep the current charset without worrying about how | ||
// this charset will effect the encoding of the form url encoded string. | ||
String content = EncodingUtil.formUrlEncode(getParameters(), getRequestCharSet()); | ||
ByteArrayRequestEntity entity = new ByteArrayRequestEntity( | ||
EncodingUtil.getAsciiBytes(content), | ||
FORM_URL_ENCODED_CONTENT_TYPE | ||
); | ||
return entity; | ||
} else { | ||
return super.generateRequestEntity(); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Please add license header.
If this is a copy from PostMethod please also note this somewhere.
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 haven't had to do a lot with licenses yet. @tobiasKaminsky Do you think that's okay?
Do I need that author and copyright part?