forked from splitio/java-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2299e38
commit fa2b6a7
Showing
9 changed files
with
163 additions
and
105 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
43 changes: 43 additions & 0 deletions
43
client/src/main/java/io/split/client/utils/ApacheRequestDecorator.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,43 @@ | ||
package io.split.client.utils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.hc.core5.http.Header; | ||
import org.apache.hc.core5.http.HttpRequest; | ||
|
||
import io.split.client.RequestDecorator; | ||
import io.split.client.dtos.RequestContext; | ||
|
||
public class ApacheRequestDecorator { | ||
|
||
public static HttpRequest decorate(HttpRequest request, RequestDecorator decorator) { | ||
|
||
RequestContext ctx = new RequestContext(convertToMap(request.getHeaders())); | ||
for (Map.Entry<String, List<String>> entry : decorator.decorateHeaders(ctx).headers().entrySet()) { | ||
List<String> values = entry.getValue(); | ||
for (int i = 0; i < values.size(); i++) { | ||
if (i == 0) { | ||
request.setHeader(entry.getKey(), values.get(i)); | ||
} else { | ||
request.addHeader(entry.getKey(), values.get(i)); | ||
} | ||
} | ||
} | ||
|
||
return request; | ||
} | ||
|
||
private static Map<String, List<String>> convertToMap(Header[] to_convert) { | ||
Map<String, List<String>> to_return = new HashMap<String, List<String>>(); | ||
for (Integer i = 0; i < to_convert.length; i++) { | ||
if (!to_return.containsKey(to_convert[i].getName())) { | ||
to_return.put(to_convert[i].getName(), new ArrayList<String>()); | ||
} | ||
to_return.get(to_convert[i].getName()).add(to_convert[i].getValue()); | ||
} | ||
return to_return; | ||
} | ||
} |
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
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.