Repository: hyperledger/quilt
Pull request #439 (2020-03-16 21:28:18)

Cleanup SPSP Headers
Minor changes to improve SPSP content-negotiation, especially for outside software like the Connector.


Patch:
diff --git a/spsp-parent/spsp-client/src/main/java/org/interledger/spsp/client/SimpleSpspClient.java b/spsp-parent/spsp-client/src/main/java/org/interledger/spsp/client/SimpleSpspClient.java
index e85e497..b56a2ce 100644
--- a/spsp-parent/spsp-client/src/main/java/org/interledger/spsp/client/SimpleSpspClient.java
+++ b/spsp-parent/spsp-client/src/main/java/org/interledger/spsp/client/SimpleSpspClient.java
@@ -51,7 +51,7 @@ public class SimpleSpspClient implements SpspClient {
 
     return execute(new Request.Builder()
         .url(spspUrl)
-        .header("Accept", ACCEPT_SPSP_JSON)
+        .header("Accept", APPLICATION_SPSP4_JSON_VALUE)
         .get()
         .build(), StreamConnectionDetails.class);
   }
diff --git a/spsp-parent/spsp-client/src/main/java/org/interledger/spsp/client/SpspClient.java b/spsp-parent/spsp-client/src/main/java/org/interledger/spsp/client/SpspClient.java
index 6d4e1ed..fbeaa6a 100644
--- a/spsp-parent/spsp-client/src/main/java/org/interledger/spsp/client/SpspClient.java
+++ b/spsp-parent/spsp-client/src/main/java/org/interledger/spsp/client/SpspClient.java
@@ -12,26 +12,35 @@ import okhttp3.HttpUrl;
  */
 public interface SpspClient {
 
-  String ACCEPT_SPSP_JSON = "application/spsp4+json, application/spsp+json";
+  /**
+   * The Java, JS, Rafiki, and Rust SPSP servers all respond properly to this header.
+   */
+  String APPLICATION_SPSP4_JSON_VALUE = "application/spsp4+json";
 
   /**
-   * Calls SPSP endpoint to obtain address and secret needed to setup a payment (for the given pointer).
-   * Typically used for setting up a STREAM connection.
-   * @see "https://github.com/interledger/rfcs/blob/master/0009-simple-payment-setup-protocol/0009-simple-payment-setup-protocol.md#query-get-spsp-endpoint"
+   * Calls SPSP endpoint to obtain address and secret needed to setup a payment (for the given pointer). Typically used
+   * for setting up a STREAM connection.
+   *
    * @param paymentPointer payment pointer to query on
+   *
    * @return stream connection details
+   *
    * @throws InvalidReceiverClientException thrown if the payment pointer does not point to a valid account
+   * @see "https://github.com/interledger/rfcs/blob/master/0009-simple-payment-setup-protocol/0009-simple-payment-setup-protocol.md#query-get-spsp-endpoint"
    */
   StreamConnectionDetails getStreamConnectionDetails(PaymentPointer paymentPointer)
       throws InvalidReceiverClientException;
 
   /**
-   * Calls SPSP endpoint to obtain address and secret needed to setup a payment (for the given SPSP url).
-   * Typically used for setting up a STREAM connection.
-   * @see "https://github.com/interledger/rfcs/blob/master/0009-simple-payment-setup-protocol/0009-simple-payment-setup-protocol.md#query-get-spsp-endpoint"
+   * Calls SPSP endpoint to obtain address and secret needed to setup a payment (for the given SPSP url). Typically used
+   * for setting up a STREAM connection.
+   *
    * @param spspUrl url for the SPSP account endpoint
+   *
    * @return stream connection details
+   *
    * @throws InvalidReceiverClientException thrown if the payment pointer does not point to a valid account
+   * @see "https://github.com/interledger/rfcs/blob/master/0009-simple-payment-setup-protocol/0009-simple-payment-setup-protocol.md#query-get-spsp-endpoint"
    */
   StreamConnectionDetails getStreamConnectionDetails(HttpUrl spspUrl)
       throws InvalidReceiverClientException;


Test patch:
diff --git a/spsp-parent/spsp-client/src/test/java/org/interledger/spsp/client/SimpleSpspClientTest.java b/spsp-parent/spsp-client/src/test/java/org/interledger/spsp/client/SimpleSpspClientTest.java
index ec4c0db..ec7a7ec 100644
--- a/spsp-parent/spsp-client/src/test/java/org/interledger/spsp/client/SimpleSpspClientTest.java
+++ b/spsp-parent/spsp-client/src/test/java/org/interledger/spsp/client/SimpleSpspClientTest.java
@@ -39,7 +39,7 @@ public class SimpleSpspClientTest {
 
     String wiremockIlpAddress = "test.wiremock";
     stubFor(get(urlEqualTo("/" + testClient))
-        .withHeader("Accept", equalTo(SpspClient.ACCEPT_SPSP_JSON))
+        .withHeader("Accept", equalTo(SpspClient.APPLICATION_SPSP4_JSON_VALUE))
         .willReturn(aResponse()
             .withStatus(200)
             .withBody("{\"destination_account\":\"" + wiremockIlpAddress + "." + testClient + "\","
@@ -63,7 +63,7 @@ public class SimpleSpspClientTest {
 
     String wiremockIlpAddress = "test.wiremock";
     stubFor(get(urlEqualTo("/" + testClient))
-        .withHeader("Accept", equalTo(SpspClient.ACCEPT_SPSP_JSON))
+        .withHeader("Accept", equalTo(SpspClient.APPLICATION_SPSP4_JSON_VALUE))
         .willReturn(aResponse()
             .withStatus(200)
             .withBody("{\"destination_account\":\"" + wiremockIlpAddress + "." + testClient + "\","
@@ -85,7 +85,7 @@ public class SimpleSpspClientTest {
     String testClient = "testClient";
 
     stubFor(get(urlEqualTo("/" + testClient))
-        .withHeader("Accept", equalTo(SpspClient.ACCEPT_SPSP_JSON))
+        .withHeader("Accept", equalTo(SpspClient.APPLICATION_SPSP4_JSON_VALUE))
         .willReturn(aResponse()
             .withStatus(404)
         ));
@@ -98,7 +98,7 @@ public class SimpleSpspClientTest {
     String testClient = "testClient";
 
     stubFor(get(urlEqualTo("/" + testClient))
-        .withHeader("Accept", equalTo(SpspClient.ACCEPT_SPSP_JSON))
+        .withHeader("Accept", equalTo(SpspClient.APPLICATION_SPSP4_JSON_VALUE))
         .willReturn(aResponse()
             .withStatus(503)
         ));
@@ -106,6 +106,11 @@ public class SimpleSpspClientTest {
     client.getStreamConnectionDetails(paymentPointer(testClient));
   }
 
+  @Test
+  public void testHeaders() {
+    assertThat(SpspClient.APPLICATION_SPSP4_JSON_VALUE).isEqualTo("application/spsp4+json");
+  }
+
   private PaymentPointer paymentPointer(String testClient) {
     return PaymentPointer.of("$test.wiremock/" + testClient);
   }