Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
De-coupling from jetty HttpTester, introducing InProcRequest
- Loading branch information
Showing
11 changed files
with
308 additions
and
121 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
...-htmlunit/src/main/java/com/thoughtworks/inproctester/htmlunit/HtmlUnitInprocRequest.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,57 @@ | ||
package com.thoughtworks.inproctester.htmlunit; | ||
|
||
import com.gargoylesoftware.htmlunit.WebRequest; | ||
import com.thoughtworks.inproctester.jetty.InProcRequest; | ||
import com.thoughtworks.inproctester.jetty.UrlHelper; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
class HtmlUnitInProcRequest implements InProcRequest { | ||
private WebRequest request; | ||
private Map<String, String> headers = new HashMap<String, String>(); | ||
|
||
public HtmlUnitInProcRequest(WebRequest request) { | ||
this.request = request; | ||
headers.put("Host", UrlHelper.getRequestHost(request.getUrl())); | ||
headers.put("Content-Type", request.getEncodingType().getName() + ";" + request.getCharset()); | ||
headers.putAll(request.getAdditionalHeaders()); | ||
} | ||
|
||
@Override | ||
public String getHttpMethod() { | ||
return request.getHttpMethod().name(); | ||
} | ||
|
||
@Override | ||
public URI getUri() { | ||
try { | ||
return request.getUrl().toURI(); | ||
} catch (URISyntaxException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public String getFormData() { | ||
return new UrlEncodedContent(request.getRequestParameters()).generateFormDataAsString(); | ||
} | ||
|
||
@Override | ||
public String getHeader(String headerName) { | ||
return headers.get(headerName); | ||
} | ||
|
||
@Override | ||
public Set<String> getHeaderNames() { | ||
return headers.keySet(); | ||
} | ||
|
||
@Override | ||
public void addHeader(String headerName, String header) { | ||
headers.put(headerName, header); | ||
} | ||
} |
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
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
18 changes: 18 additions & 0 deletions
18
inproctester-jetty/src/main/java/com/thoughtworks/inproctester/jetty/InProcRequest.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 com.thoughtworks.inproctester.jetty; | ||
|
||
import java.net.URI; | ||
import java.util.Set; | ||
|
||
public interface InProcRequest { | ||
String getHttpMethod(); | ||
|
||
URI getUri(); | ||
|
||
String getFormData(); | ||
|
||
String getHeader(String headerName); | ||
|
||
Set<String> getHeaderNames(); | ||
|
||
void addHeader(String headerName, String header); | ||
} |
Oops, something went wrong.