New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make request data available to responders #1174
Conversation
src/fitnesse/http/Request.java
Outdated
String cookies = headers.get("cookie"); | ||
if(null != cookies) { | ||
String[] rawCookies = cookies.split(";"); | ||
for(String cookie : rawCookies) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for(String cookie : rawCookies) { | |
for (String cookie : rawCookies) { |
src/fitnesse/http/Request.java
Outdated
String[] rawCookies = cookies.split(";"); | ||
for(String cookie : rawCookies) { | ||
String[] pair = cookie.split("="); | ||
if(pair[0].trim().equalsIgnoreCase(name) && pair.length == 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(pair[0].trim().equalsIgnoreCase(name) && pair.length == 2) { | |
if (pair.length == 2 && pair[0].trim().equalsIgnoreCase(name)) { |
return responseWith(contentFrom(context, request, null)); | ||
} | ||
|
||
@Override | ||
protected String contentFrom(FitNesseContext context, Request request, WikiPage requestedPage) { | ||
requestData= request; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requestData= request; | |
requestData = request; |
src/fitnesse/http/Request.java
Outdated
@@ -67,6 +67,20 @@ public void parse() throws HttpException { | |||
hasBeenParsed = true; | |||
} | |||
|
|||
public String getCookie(String name) { | |||
String cookies = headers.get("cookie"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use getHeader()
@@ -25,9 +25,11 @@ | |||
private String qualifiedPageName; | |||
private WikiPagePath path; | |||
private FitNesseContext context; | |||
private Request requestData; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why requestData
?
@@ -14,11 +14,12 @@ | |||
public class StopTestResponder implements SecureResponder { | |||
|
|||
String testId = null; | |||
private Request requestData; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why requestData
?
@@ -30,11 +30,13 @@ | |||
public class VersionResponder implements SecureResponder { | |||
private String version; | |||
private String resource; | |||
private Request requestData; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why requestData
?
@@ -16,11 +16,12 @@ | |||
import fitnesse.wiki.WikiPagePath; | |||
|
|||
public abstract class BasicResponder implements SecureResponder { | |||
protected Request requestData; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you call this requestData (and not just request)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you choose to put this in a field? I think it would be better if subclasses got the request as method parameter only.
velocityContext.put("theme", theme); | ||
velocityContext.put("contextRoot", contextRoot); | ||
velocityContext.put("request", request); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you consider only adding the request to velocityContext on 'render()', and adding the request as parameter to html()
and render()
?
I think that would be nicer design-wise, as a single page could be rendered multiple times (for different requests). I think this might also make the impact on the Renders smaller, as only the methods that call html()
would need the request and they seem to have this request as a parameter already.
…tra field on responders Use existing methods to determine if a cookie header exists, eliminating the extra nullcheck
This PR makes request data available to velocity in all available responders, so that we have access to the request data from our velocity templates. This enables the use of cookies in templates to store user preferences/settings.
To make the latter easier, a getCookie method is added to the request class, allowing to get cookie data bty its key.