Skip to content

Commit

Permalink
set Content-Type header to text/plain for http syslog drains
Browse files Browse the repository at this point in the history
[#168768308]

Signed-off-by: Tom Chen <[email protected]>
  • Loading branch information
Max Eshleman authored and chentom88 committed Sep 26, 2019
1 parent d504f01 commit b9f2108
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/pkg/egress/syslog/https.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (w *HTTPSWriter) Write(env *loggregator_v2.Envelope) error {
req := fasthttp.AcquireRequest()
req.SetRequestURI(w.url.String())
req.Header.SetMethod("POST")
req.Header.SetContentType("text/plain")
req.SetBody(msg)

resp := fasthttp.AcquireResponse()
Expand Down
26 changes: 26 additions & 0 deletions src/pkg/egress/syslog/https_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,30 @@ var _ = Describe("HTTPWriter", func() {
Expect(drain.messages[2].ProcessID).To(Equal("[CELL]"))
})

It("writes syslog formatted messages to http drain", func() {
drain := newMockOKDrain()

b := buildURLBinding(
drain.URL,
"test-app-id",
"test-hostname",
)

writer := syslog.NewHTTPSWriter(
b,
netConf,
true,
&testhelper.SpyMetric{},
)

env1 := buildLogEnvelope("APP", "1", "just a test", loggregator_v2.Log_OUT)
Expect(writer.Write(env1)).To(Succeed())

Expect(drain.messages).To(HaveLen(1))
Expect(drain.headers).To(HaveLen(1))
Expect(drain.headers[0]).To(HaveKeyWithValue("Content-Type", []string{"text/plain"}))
})

It("writes gauge metrics to the http drain", func() {
drain := newMockOKDrain()

Expand Down Expand Up @@ -280,6 +304,7 @@ var _ = Describe("HTTPWriter", func() {
type SpyDrain struct {
*httptest.Server
messages []*rfc5424.Message
headers []http.Header
}

func newMockOKDrain() *SpyDrain {
Expand All @@ -303,6 +328,7 @@ func newMockDrain(status int) *SpyDrain {
Expect(err).ToNot(HaveOccurred())

drain.messages = append(drain.messages, message)
drain.headers = append(drain.headers, r.Header)
w.WriteHeader(status)
})
server := httptest.NewTLSServer(handler)
Expand Down

0 comments on commit b9f2108

Please sign in to comment.