segmentio/analytics-python — pull request #13 by alanjds (2013-05-01 04:51:44+00:00)
Title: WSGI middleware to inject analytics.js in <head/>

Hi.

I implemented a WSGI middleware to inject analytics.js snippet. It is implemented in a non-buffered fashion, so will not delay/swallow the stream, if yielded as chunks.

Before adding a new script, it searches `

` for existing script. If found, it does not inject again. If not found, injects the snippet to `

`. If `

` is on same chunk of `

` (or the response is not chunked), it injects right after the start of `

`.

If closing `

` is not on the same chunk as `

`, it injects right before `

`. Is this recommended/acceptable?

I could buffer `

` to `

` to be sure, but it delays the stream.
I could simple inject right after `

` start, but than I need to keep searching the next chunks for existing snippet, and then chop it if found.

Can I expect it to be merged? Have the original authors some consideration?