-
-
Notifications
You must be signed in to change notification settings - Fork 184
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
5c2149f
commit 6ba0bbd
Showing
5 changed files
with
85 additions
and
60 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
7 changes: 7 additions & 0 deletions
7
core/src/main/java/lucee/commons/net/header/HeadersCollection.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,7 @@ | ||
package lucee.commons.net.header; | ||
|
||
import org.apache.http.Header; | ||
|
||
public interface HeadersCollection { | ||
public Header[] getHeaders(String name); | ||
} |
29 changes: 29 additions & 0 deletions
29
core/src/main/java/lucee/commons/net/header/HeadersHTTPResponse.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,29 @@ | ||
package lucee.commons.net.header; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.apache.http.Header; | ||
import org.apache.http.message.BasicHeader; | ||
|
||
import lucee.commons.net.http.HTTPResponse; | ||
|
||
public class HeadersHTTPResponse implements HeadersCollection { | ||
|
||
private HTTPResponse response; | ||
|
||
public HeadersHTTPResponse(HTTPResponse response) { | ||
this.response = response; | ||
} | ||
|
||
@Override | ||
public Header[] getHeaders(String name) { | ||
List<Header> list = new ArrayList<>(); | ||
for (lucee.commons.net.http.Header header: response.getAllHeaders()) { | ||
if (name.equals(header.getName())) { | ||
list.add(new BasicHeader(header.getName(), header.getValue())); | ||
} | ||
} | ||
return list.toArray(new Header[list.size()]); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
core/src/main/java/lucee/commons/net/header/HeadersHttpResponseApache.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,18 @@ | ||
package lucee.commons.net.header; | ||
|
||
import org.apache.http.Header; | ||
import org.apache.http.HttpResponse; | ||
|
||
public class HeadersHttpResponseApache implements HeadersCollection { | ||
|
||
private HttpResponse response; | ||
|
||
public HeadersHttpResponseApache(HttpResponse response) { | ||
this.response = response; | ||
} | ||
|
||
@Override | ||
public Header[] getHeaders(String name) { | ||
return response.getHeaders(name); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
core/src/main/java/lucee/commons/net/header/HeadersHttpURLConnection.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,26 @@ | ||
package lucee.commons.net.header; | ||
|
||
import java.net.HttpURLConnection; | ||
|
||
import org.apache.http.Header; | ||
import org.apache.http.message.BasicHeader; | ||
|
||
import lucee.commons.lang.StringUtil; | ||
|
||
public class HeadersHttpURLConnection implements HeadersCollection { | ||
|
||
private HttpURLConnection conn; | ||
|
||
public HeadersHttpURLConnection(HttpURLConnection conn) { | ||
this.conn = conn; | ||
} | ||
|
||
@Override | ||
public Header[] getHeaders(String name) { | ||
String val = conn.getHeaderField(name); | ||
if (!StringUtil.isEmpty(val, true)) { | ||
return new Header[] { new BasicHeader(name, val) }; | ||
} | ||
return null; | ||
} | ||
} |