mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-29 15:43:56 +00:00
Remove implementation specific Java hack and allow POST verb for keyring set command
This commit is contained in:
parent
4f5567e2c1
commit
65d0e3a47c
@ -286,28 +286,4 @@ public class ServalDClient implements ServalDHttpConnectionFactory {
|
||||
return conn;
|
||||
}
|
||||
|
||||
/* A hack to force java.net.HttpURLConnection to accept the non-standard "PATCH" request method.
|
||||
* Taken from https://stackoverflow.com/a/46323891
|
||||
*/
|
||||
|
||||
private static class HttpURLConnectionHack {
|
||||
public HttpURLConnectionHack() {
|
||||
try {
|
||||
Field methodsField = HttpURLConnection.class.getDeclaredField("methods");
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
modifiersField.setInt(methodsField, methodsField.getModifiers() & ~Modifier.FINAL);
|
||||
methodsField.setAccessible(true);
|
||||
String[] oldMethods = (String[]) methodsField.get(null);
|
||||
Set<String> methodsSet = new LinkedHashSet<>(Arrays.asList(oldMethods));
|
||||
methodsSet.add("PATCH");
|
||||
String[] newMethods = methodsSet.toArray(new String[0]);
|
||||
methodsField.set(null, newMethods);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final HttpURLConnectionHack dummy = new HttpURLConnectionHack();
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ public class KeyringCommon
|
||||
query_params.add(new ServalDHttpConnectionFactory.QueryParam("name", name));
|
||||
if (pin != null)
|
||||
query_params.add(new ServalDHttpConnectionFactory.QueryParam("pin", pin));
|
||||
HttpURLConnection conn = connector.newServalDHttpConnection("PATCH", "/restful/keyring/" + sid.toHex(), query_params);
|
||||
HttpURLConnection conn = connector.newServalDHttpConnection("POST", "/restful/keyring/" + sid.toHex(), query_params);
|
||||
conn.connect();
|
||||
Status status = receiveRestfulResponse(conn, HttpURLConnection.HTTP_OK);
|
||||
try {
|
||||
|
@ -53,7 +53,7 @@ static int restful_keyring_(httpd_request *r, const char *remainder)
|
||||
if (strcmp(end, "") == 0) {
|
||||
if (r->http.verb == HTTP_VERB_GET)
|
||||
return restful_keyring_get(r, "");
|
||||
if (r->http.verb == HTTP_VERB_PATCH)
|
||||
if (r->http.verb == HTTP_VERB_PATCH || r->http.verb == HTTP_VERB_POST)
|
||||
return restful_keyring_set(r, "");
|
||||
if (r->http.verb == HTTP_VERB_DELETE)
|
||||
return restful_keyring_remove(r, "");
|
||||
|
Loading…
x
Reference in New Issue
Block a user