Currently, eventgate-wikimedia has [[ https://gerrit.wikimedia.org/r/plugins/gitiles/eventgate-wikimedia/+/refs/heads/master/eventgate-wikimedia.js#361 | custom code ]] to set a few defaults in event data from HTTP request headers. Instead of manually specifying the headers to set, we could add properties explicitly to the schema that should be set by eventgate if they are not already in the event data. Example:
```lang=yaml
http:
type: object
description: Information about the HTTP request that generated an event.
properties:
request_headers:
type: object
description: Request headers sent by the client.
additionalProperties:
type: string
properties:
user-agent:
type: string
referer:
type: string
x-client-ip:
type: string
```
Here, `request_headers` is still a '[[ https://wikitech.wikimedia.org/wiki/Event_Platform/Schemas/Guidelines#map_types | map type ]]', as it has `additionalProperties` with a specific type. However, some specific keys are defined. eventgate-wikimedia could use this fact to automatically set the values to the corresponding HTTP header. Something like
```lang=javascript
for property in req.headers.keys() {
if (schema.properties.http.request_headers.properties[property.toLower()] && !event.http.request_headers[property.toLower()]) {
event.http.request_headers[property.toLower()] = req.headers[property]
}
}
```
This would allow us to get rid of header specific custom code in eventgate-wikimedia, while giving control over what headers are automatically set to schema owners, without forcing them to have their producer code set the header in the event data (and ultimately send the same data twice over the same HTTP request)).
We'd need to make sure any [[ https://github.com/wikimedia/analytics-refinery-source/blob/master/refinery-spark/src/main/scala/org/wikimedia/analytics/refinery/spark/sql/JsonSchemaConverter.scala#L95-L100 | JSONSchema converter code ]] knows to still interpret objects with `additionalProperties` and type: string as a map even if `properties` are also defined.