-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #516 from Cognifide/bugfix/header-modifier-doesn't…
…-work-for-User-Agent-property Bugfix/header modifier doesn't work for user agent property
- Loading branch information
Showing
14 changed files
with
302 additions
and
28 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
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
41 changes: 41 additions & 0 deletions
41
integration-tests/sample-site/src/main/webapp/sanity/modifiers/header/show_headers.jsp
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,41 @@ | ||
<%-- | ||
AET | ||
Copyright (C) 2013 Cognifide Limited | ||
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. | ||
--%> | ||
<%@ page import="java.util.*" %> | ||
<html> | ||
|
||
<head> | ||
<title>Headers test</title> | ||
</head> | ||
|
||
<body> | ||
<h2>HTTP Request Headers Received</h2> | ||
<table> | ||
<% Enumeration enumeration = request.getHeaderNames(); while (enumeration.hasMoreElements()) | ||
{ | ||
String name=(String) enumeration.nextElement(); | ||
String value = request.getHeader(name); %> | ||
<tr> | ||
<td><%=name %></td> | ||
<td id="<%=name %>"><%=value %></td> | ||
</tr> | ||
<% } %> | ||
</table> | ||
</body> | ||
</html> |
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
53 changes: 53 additions & 0 deletions
53
osgi-dependencies/proxy/src/main/java/com/cognifide/aet/proxy/headers/AddHeader.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,53 @@ | ||
/** | ||
* AET | ||
* | ||
* Copyright (C) 2013 Cognifide Limited | ||
* | ||
* 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 com.cognifide.aet.proxy.headers; | ||
|
||
import org.apache.http.client.methods.HttpPost; | ||
import org.apache.http.client.utils.URIBuilder; | ||
import org.apache.http.entity.StringEntity; | ||
import org.json.JSONObject; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.net.URISyntaxException; | ||
|
||
public class AddHeader implements HeaderRequestStrategy { | ||
|
||
private final String apiHost; | ||
|
||
private final int apiPort; | ||
|
||
private final int proxyPort; | ||
|
||
public AddHeader(String apiHost, int apiPort, int proxyPort) { | ||
this.apiHost = apiHost; | ||
this.apiPort = apiPort; | ||
this.proxyPort = proxyPort; | ||
} | ||
|
||
@Override | ||
public HttpPost createRequest(String name, String value) | ||
throws URISyntaxException, UnsupportedEncodingException { | ||
URIBuilder uriBuilder = new URIBuilder().setScheme("http") | ||
.setHost(apiHost).setPort(apiPort); | ||
HttpPost request = new HttpPost(uriBuilder.setPath( | ||
String.format("/proxy/%d/headers", proxyPort)).build()); | ||
request.setHeader("Content-Type", "application/json"); | ||
JSONObject json = new JSONObject(); | ||
json.put(name, value); | ||
request.setEntity(new StringEntity(json.toString())); | ||
return request; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...ependencies/proxy/src/main/java/com/cognifide/aet/proxy/headers/HeaderRequestFactory.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 @@ | ||
/** | ||
* AET | ||
* | ||
* Copyright (C) 2013 Cognifide Limited | ||
* | ||
* 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 com.cognifide.aet.proxy.headers; | ||
|
||
import com.github.detro.browsermobproxyclient.BMPCProxy; | ||
import org.apache.http.client.methods.HttpPost; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.net.URISyntaxException; | ||
|
||
public class HeaderRequestFactory { | ||
|
||
private final BMPCProxy server; | ||
|
||
public HeaderRequestFactory(BMPCProxy server) { | ||
this.server = server; | ||
} | ||
|
||
public HttpPost create(String name, String value, Boolean override) throws UnsupportedEncodingException, URISyntaxException { | ||
HeaderRequestStrategy headerRequestStrategy; | ||
if (override) { | ||
headerRequestStrategy = new OverrideHeader(server.getAPIHost(), server.getAPIPort(), | ||
server.getProxyPort()); | ||
} else { | ||
headerRequestStrategy = new AddHeader(server.getAPIHost(), server.getAPIPort(), | ||
server.getProxyPort()); | ||
} | ||
return headerRequestStrategy.createRequest(name, value); | ||
} | ||
} |
Oops, something went wrong.