Skip to content

Set HTTP user-agent to 'Skosmos' when performing requests#1711

Merged
osma merged 1 commit intomainfrom
issue1691-set-http-user-agent
Dec 12, 2024
Merged

Set HTTP user-agent to 'Skosmos' when performing requests#1711
osma merged 1 commit intomainfrom
issue1691-set-http-user-agent

Conversation

@osma
Copy link
Member

@osma osma commented Dec 10, 2024

Reasons for creating this PR

See #1691. It's good practice to use a custom HTTP user agent instead of relying on library defaults. This code sets the user-agent to Skosmos every time EasyRdf is used to perform HTTP requests (including SPARQL). There is one more place in the code (LOCResolver) that performs HTTP requests directly using stream operations, but in that code the user-agent was already set to Skosmos.

I decided not to include the Skosmos version number in the user-agent string based on discussion with other Skosmos developers.

Link to relevant issue(s), if any

Description of the changes in this PR

  • set the HTTP user agent (via EasyRdf config setting) in all places where the Skosmos backend code performs HTTP requests

Known problems or uncertainties in this PR

No unit tests, but I don't think it's easy to test this with PHPUnit. However, I tested manually that the changes do have an effect by looking at HTTP server logs.

Checklist

  • phpUnit tests pass locally with my changes
  • I have added tests that show that the new code works, or tests are not relevant for this PR (e.g. only HTML/CSS changes)
  • The PR doesn't reduce accessibility of the front-end code (e.g. tab focus, scaling to different resolutions, use of .sr-only class, color contrast)
  • The PR doesn't introduce unintended code changes (e.g. empty lines or useless reindentation)

@osma osma added this to the 3.0 milestone Dec 10, 2024
@osma osma self-assigned this Dec 10, 2024
@sonarqubecloud
Copy link

@osma osma requested a review from miguelvaara December 10, 2024 09:10
Copy link
Contributor

@miguelvaara miguelvaara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How I tested

In the command line:

sudo ngrep -q -W byline 'User-Agent' tcp port 80

In the browser's address bar:
http://localhost/skosmos/yso/en/page/p26179 (A-clinics)

Result:

interface: wlp0s20f3 (192.168.XXX.XXX/255.255.255.0)
filter: ( tcp port 80 ) and ((ip || ip6) || (vlan && (ip || ip6)))
match (JIT): User-Agent

T 192.168.XXX.XXX:53316 -> 128.214.XXX.XXX:80 [AP] #6
Host: api.dev.finto.fi.
Connection: close.
User-Agent: Skosmos.
Accept: application/sparql-results+json,application/sparql-results+xml;q=0.8.
.


T 192.168.XXX.XXX:53320 -> 128.214.XXX.XXX:80 [AP] #17
Host: api.dev.finto.fi.
Connection: close.
User-Agent: Skosmos.
Accept: application/sparql-results+json,application/sparql-results+xml;q=0.8.
.


T 192.168.XXX.XXX:53322 -> 128.214.XXX.XXX:80 [AP] #28
Host: api.dev.finto.fi.
Connection: close.
User-Agent: Skosmos.
Accept: application/sparql-results+json,application/sparql-results+xml;q=0.8.
.


T 192.168.XXX.XXX:53326 -> 128.214.XXX.XXX:80 [AP] #39
Host: api.dev.finto.fi.
Connection: close.
User-Agent: Skosmos.
Accept: application/sparql-results+json,application/sparql-results+xml;q=0.8.

...etc (a longer list is not meaningful because it works in all cases)

The code also looks meaningful.

Well done! 👍 In my opinion, it can be merged.

@osma osma merged commit bddba45 into main Dec 12, 2024
@osma osma deleted the issue1691-set-http-user-agent branch December 12, 2024 13:01
@osma osma modified the milestones: 3.x, 3.0 Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set user agent when performing HTTP requests

2 participants