Skip to content

Commit

Permalink
added noindex headers
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltester committed Mar 28, 2024
1 parent ee01c1c commit e6057f8
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ private void createThingifier(){
this.challengeThingifier.apiConfig().setApiToShowPrimaryKeyHeaderInResponse(true);
this.challengeThingifier.apiConfig().forParams().willEnforceFilteringThroughUrlParams();
this.challengeThingifier.apiConfig().forParams().willAllowFilteringThroughUrlParams();
this.challengeThingifier.apiConfig().setApiToAllowRobotsIndexingResponses(false);

this.challengeDefn = this.challengeThingifier.defineThing(
"challenge", "challenges");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void configure(final ThingifierApiDefn apiDefn) {

options(endpoint + "/*", (request, result) -> {
result.status(204);
result.header("X-Robots-Tag", "noindex");
result.header("x-robots-tag", "noindex");
result.header("Allow", "GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, TRACE");
return "";
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ public void setup(final Challengers challengers,

response.body(html.toString());
response.type("text/html");
if(response.raw().containsHeader("x-robots-tag")){
// we want it indexed because it is content
response.raw().setHeader("x-robots-tag", "all");
}
response.status(200);
}

Expand Down
6 changes: 3 additions & 3 deletions challenger/src/main/resources/content/practice-sites.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ There are many API simulators so we have only listed a few of the best here.

#### JSON Placeholder

[{JSON} Placeholder]https://jsonplaceholder.typicode.com/
[{JSON} Placeholder](https://jsonplaceholder.typicode.com/)

- An API For `GET` requests.
- Acts as a simulator for Update and Delete requests
Expand Down Expand Up @@ -116,7 +116,7 @@ These are full APIs online, which means you don't have to install anything and c

---

## Toolshop API
#### Toolshop API

[Toolshop API](https://api.practicesoftwaretesting.com/api/documentation)

Expand Down Expand Up @@ -218,7 +218,7 @@ I found Reqres a little hard to understand from the documentation. It seems as t
- [reqres](https://reqres.in)
- Supports `JSON` only
- Has hard coded data.
- Provides a Swagger [API interface and docmentation](https://reqres.in/api-docs/) this can be useful to get started but doesn't cover the generic endpoints so you'll need to use a REST Client for that.
- Provides a Swagger [API interface and documentation](https://reqres.in/api-docs/) this can be useful to get started but doesn't cover the generic endpoints so you'll need to use a REST Client for that.
- There is also a hard coded set of 12 'things' which will respond to any endpoint e.g. `GET https://reqres/in/api/books/1` will return the hardcoded 'thing' with ID 1 (it won't be a 'book' but the API responds as though the `/api/books/` end point exists)
- Simulates `DELETE, PUT, POST, PATCH` operations.

Expand Down
9 changes: 5 additions & 4 deletions challenger/src/main/resources/public/robots.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ Disallow: /mirror/request
Disallow: /mirror/raw/*
Disallow: /mirror/request/*
Disallow: /sim/*
Disallow: /todos/*
Disallow: /todos
Disallow: /challenges
Disallow: /challenger
Disallow: /challenger/*
Disallow: /secret/*
Disallow: /heartbeat
# use noindex http header instead
# Disallow: /todos/*
# Disallow: /todos
# Disallow: /challenges
# Disallow: /heartbeat
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ private void configureFrom(final HttpHeadersBlock requestHeaders, final HttpHead
apiResponseHeaders.putAll(originalApiResponseHeaders);
apiResponseHeaders.put("Content-Type", type);

// todo: put this behind a config

if(apiConfig.willPreventRobotsFromIndexingResponse()) {
apiResponseHeaders.put("X-Robots-Tag", "noindex");
apiResponseHeaders.put("x-robots-tag", "noindex");
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public ThingifierApiConfig(){
willApiEnforceContentTypeHeaderForRequests = true;
acceptXmlContent = true;
acceptJsonContent = true;
robotsCanIndexApiResponses=false;
robotsCanIndexApiResponses=true;

paramsConfig = new ParamConfig();

Expand All @@ -100,7 +100,7 @@ public void setFrom(final ThingifierApiConfig apiConfig) {
robotsCanIndexApiResponses = apiConfig.willAllowRobotsToIndexResponses();
willApiAllowXmlResponses = apiConfig.willApiAllowXmlForResponses();
willApiAllowJsonResponses = apiConfig.willApiAllowJsonForResponses();
willApiEnforceAcceptHeaderForResponses = willApiEnforceAcceptHeaderForResponses();
willApiEnforceAcceptHeaderForResponses = apiConfig.willApiEnforceAcceptHeaderForResponses();

paramsConfig.setFrom(apiConfig.forParams());
statusCodeConfig.setFrom(apiConfig.statusCodes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void routeStatus(final int statuscode, final String endpoint, fina
preferred="application/json"; // hard coded default
}
result.header("Content-Type", preferred);
result.header("X-Robots-Tag", "noindex");
result.header("x-robots-tag", "noindex");
result.status(statuscode);
return "";
};
Expand Down

0 comments on commit e6057f8

Please sign in to comment.