-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Interceptor into Function and introduce RequestEntity (#58)
* Refactor Interceptor into Function and introduce RequestEntity This changes changes `RequestInterceptor` from a `Consumer` to a `Function`, to simplify Request Specification management during method execution, specifically during Asynchronous or Reactive execution. Modifying the `RequestSpecification` through side-effects is difficult to reason over and is one of the areas that existing Feign struggles with. Additionally, `RequestEncoder` has been modified to return a `RequestEntity` to more closely match current Feign and to make updating a Request body, content type, content length, and charset more explicit. Additional Changes * Correcting Circle CI Codecov Orb Version * Add StringRequestEntity and refactor Test Cases for coverage
- Loading branch information
Showing
13 changed files
with
302 additions
and
71 deletions.
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
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
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,54 @@ | ||
/* | ||
* Copyright 2019-2020 OpenFeign Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package feign; | ||
|
||
import java.nio.charset.Charset; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Represents the content of a {@link Request}. | ||
*/ | ||
public interface RequestEntity { | ||
|
||
/** | ||
* Character Set this entity is encoded in. | ||
* | ||
* @return the entity {@link Charset}. | ||
*/ | ||
Optional<Charset> getCharset(); | ||
|
||
/** | ||
* Length of the entity data. | ||
* | ||
* @return entity data length. | ||
*/ | ||
int getContentLength(); | ||
|
||
/** | ||
* Content Type of the entity. | ||
* | ||
* @return String representation of a MIME-Type or any other acceptable Content Type. | ||
*/ | ||
String getContentType(); | ||
|
||
/** | ||
* Entity Data. | ||
* | ||
* @return entity data. | ||
*/ | ||
byte[] getData(); | ||
} |
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
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
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,59 @@ | ||
/* | ||
* Copyright 2019-2020 OpenFeign Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package feign.encoder; | ||
|
||
import feign.RequestEntity; | ||
import java.nio.charset.Charset; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Arrays; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Simple Request Entity backed by a String. | ||
*/ | ||
public class StringRequestEntity implements RequestEntity { | ||
|
||
public static final String TEXT_PLAIN = "text/plain"; | ||
private final byte[] data; | ||
private final int length; | ||
private final Charset charset = StandardCharsets.UTF_8; | ||
|
||
public StringRequestEntity(String content) { | ||
this.data = content.getBytes(StandardCharsets.UTF_8); | ||
this.length = data.length; | ||
} | ||
|
||
@Override | ||
public Optional<Charset> getCharset() { | ||
return Optional.of(this.charset); | ||
} | ||
|
||
@Override | ||
public int getContentLength() { | ||
return this.length; | ||
} | ||
|
||
@Override | ||
public String getContentType() { | ||
return TEXT_PLAIN; | ||
} | ||
|
||
@Override | ||
public byte[] getData() { | ||
return Arrays.copyOf(this.data, this.data.length); | ||
} | ||
} |
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
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
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
Oops, something went wrong.