Skip to content
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

Merged
merged 2 commits into from Jan 2, 2019

Conversation

Projects
None yet
2 participants
@tcnh
Copy link
Contributor

commented Dec 27, 2018

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.

Show resolved Hide resolved src/fitnesse/http/Request.java Outdated
String cookies = headers.get("cookie");
if(null != cookies) {
String[] rawCookies = cookies.split(";");
for(String cookie : rawCookies) {

This comment has been minimized.

Copy link
@fhoeben

fhoeben Dec 27, 2018

Collaborator
Suggested change
for(String cookie : rawCookies) {
for (String cookie : rawCookies) {
String[] rawCookies = cookies.split(";");
for(String cookie : rawCookies) {
String[] pair = cookie.split("=");
if(pair[0].trim().equalsIgnoreCase(name) && pair.length == 2) {

This comment has been minimized.

Copy link
@fhoeben

fhoeben Dec 27, 2018

Collaborator
Suggested change
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;

This comment has been minimized.

Copy link
@fhoeben

fhoeben Dec 27, 2018

Collaborator
Suggested change
requestData= request;
requestData = request;
@@ -67,6 +67,20 @@ public void parse() throws HttpException {
hasBeenParsed = true;
}

public String getCookie(String name) {
String cookies = headers.get("cookie");

This comment has been minimized.

Copy link
@fhoeben

fhoeben Dec 27, 2018

Collaborator

Use getHeader()

@@ -25,9 +25,11 @@
private String qualifiedPageName;
private WikiPagePath path;
private FitNesseContext context;
private Request requestData;

This comment has been minimized.

Copy link
@fhoeben

fhoeben Dec 27, 2018

Collaborator

Why requestData?

@@ -14,11 +14,12 @@
public class StopTestResponder implements SecureResponder {

String testId = null;
private Request requestData;

This comment has been minimized.

Copy link
@fhoeben

fhoeben Dec 27, 2018

Collaborator

Why requestData?

@@ -30,11 +30,13 @@
public class VersionResponder implements SecureResponder {
private String version;
private String resource;
private Request requestData;

This comment has been minimized.

Copy link
@fhoeben

fhoeben Dec 27, 2018

Collaborator

Why requestData?

@@ -16,11 +16,12 @@
import fitnesse.wiki.WikiPagePath;

public abstract class BasicResponder implements SecureResponder {
protected Request requestData;

This comment has been minimized.

Copy link
@fhoeben

fhoeben Dec 27, 2018

Collaborator

Why did you call this requestData (and not just request)?

This comment has been minimized.

Copy link
@fhoeben

fhoeben Dec 27, 2018

Collaborator

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);

This comment has been minimized.

Copy link
@fhoeben

fhoeben Dec 27, 2018

Collaborator

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.

Refactor to pass request as parameter of html/render and not as an ex…
…tra field on responders

Use existing methods to determine if a cookie header exists, eliminating the extra nullcheck
@fhoeben

fhoeben approved these changes Jan 2, 2019

@fhoeben fhoeben merged commit b20aaaf into unclebob:master Jan 2, 2019

fhoeben added a commit that referenced this pull request Jan 2, 2019

@tcnh tcnh deleted the tcnh:requestDataInResponders branch Jan 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.