Skip to content

Commit a8facfe

Browse files
authored
Merge pull request revel#1166 from notzippy/server-engine
Changed SetHeader to SetHttpHeader, HeaderHttpValue to GetHttpHeader
2 parents a74d392 + fb942f9 commit a8facfe

File tree

5 files changed

+23
-24
lines changed

5 files changed

+23
-24
lines changed

compress.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (c *CompressResponseWriter) Write(b []byte) (int, error) {
169169
// from header "Accept-Encoding"
170170
func detectCompressionType(req *Request, resp *Response) (found bool, compressionType string, compressionKind WriteFlusher) {
171171
if Config.BoolDefault("results.compressed", false) {
172-
acceptedEncodings := strings.Split(req.HttpHeaderValue("Accept-Encoding"), ",")
172+
acceptedEncodings := strings.Split(req.GetHttpHeader("Accept-Encoding"), ",")
173173

174174
largestQ := 0.0
175175
chosenEncoding := len(compressionTypes)

http.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ func (resp *Response) Destroy() {
127127
}
128128
// UserAgent returns the client's User-Agent, if sent in the request.
129129
func (r *Request) UserAgent() string {
130-
return r.HttpHeaderValue("User-Agent")
130+
return r.GetHttpHeader("User-Agent")
131131
}
132132

133133
func (r *Request) Referer() (string) {
134-
return r.HttpHeaderValue("Referer")
134+
return r.GetHttpHeader("Referer")
135135
}
136-
func (r *Request) HttpHeaderValue(key string) (value string) {
136+
func (r *Request) GetHttpHeader(key string) (value string) {
137137
if r.ServerHeader!=nil {
138138
value = r.ServerHeader.Get(key)
139139
}
@@ -143,9 +143,6 @@ func (r *Request) GetValue(key int) (value interface{}) {
143143
value, _ = r.In.Get(key)
144144
return
145145
}
146-
func (r *Request) Header() (ServerHeader) {
147-
return r.ServerHeader
148-
}
149146

150147
// WriteHeader writes the header (for now, just the status code).
151148
// The status may be set directly by the application (c.Response.Status = 501).
@@ -154,20 +151,22 @@ func (resp *Response) WriteHeader(defaultStatusCode int, defaultContentType stri
154151
if resp.ContentType == "" {
155152
resp.ContentType = defaultContentType
156153
}
157-
resp.SetHeader("Content-Type", resp.ContentType)
154+
resp.SetHttpHeader("Content-Type", resp.ContentType)
158155
if resp.Status == 0 {
159156
resp.Status = defaultStatusCode
160157
}
161158
resp.SetStatus(resp.Status)
162159
}
163-
func (resp *Response) SetHeader(key, value string) {
164-
165-
print("Set header **** ", key,value)
166-
160+
func (resp *Response) SetHttpHeader(key, value string) {
167161
if resp.ServerHeader != nil {
168162
resp.ServerHeader.Set(key,value)
169163
}
170164
}
165+
func (resp *Response) AddHttpHeader(key, value string) {
166+
if resp.ServerHeader != nil {
167+
resp.ServerHeader.Add(key,value)
168+
}
169+
}
171170
func (resp *Response) SetCookie(cookie string) {
172171
if resp.ServerHeader != nil {
173172
resp.ServerHeader.SetCookie(cookie)
@@ -206,7 +205,7 @@ func (resp *Response) GetStreamWriter() (writer StreamWriter) {
206205
// If none is specified, returns "text/html" by default.
207206
func ResolveContentType(req *Request) string {
208207

209-
contentType := req.HttpHeaderValue("Content-Type")
208+
contentType := req.GetHttpHeader("Content-Type")
210209
if contentType == "" {
211210
return "text/html"
212211
}
@@ -218,7 +217,7 @@ func ResolveContentType(req *Request) string {
218217
// returning a default of "html" when Accept header cannot be mapped to a
219218
// value above.
220219
func ResolveFormat(req *Request) string {
221-
accept := req.HttpHeaderValue("accept")
220+
accept := req.GetHttpHeader("accept")
222221

223222
switch {
224223
case accept == "",
@@ -277,7 +276,7 @@ func (al AcceptLanguages) String() string {
277276
// See the HTTP header fields specification
278277
// (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4) for more details.
279278
func ResolveAcceptLanguage(req *Request) AcceptLanguages {
280-
header := req.HttpHeaderValue("Accept-Language")
279+
header := req.GetHttpHeader("Accept-Language")
281280
if header == "" {
282281
return nil
283282
}

results.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func (r *RenderTemplateResult) Apply(req *Request, resp *Response) {
214214
}
215215

216216
if !chunked {
217-
resp.SetHeader("ContentBeater-Length", strconv.Itoa(b.Len()))
217+
resp.SetHttpHeader("ContentBeater-Length", strconv.Itoa(b.Len()))
218218
}
219219
resp.WriteHeader(http.StatusOK, "text/html; charset=utf-8")
220220
if _, err := b.WriteTo(out); err != nil {
@@ -359,12 +359,12 @@ func (r *BinaryResult) Apply(req *Request, resp *Response) {
359359
disposition += fmt.Sprintf(`; filename="%s"`, r.Name)
360360
}
361361

362-
resp.SetHeader("Content-Disposition", disposition)
362+
resp.SetHttpHeader("Content-Disposition", disposition)
363363
if resp.ContentType != "" {
364-
resp.SetHeader("Content-Type", resp.ContentType)
364+
resp.SetHttpHeader("Content-Type", resp.ContentType)
365365
} else {
366366
contentType := ContentTypeByFilename(r.Name)
367-
resp.SetHeader("Content-Type", contentType)
367+
resp.SetHttpHeader("Content-Type", contentType)
368368
}
369369
if content,ok:=r.Reader.(io.ReadSeeker);ok && r.Length<0 {
370370
// get the size from the stream
@@ -393,7 +393,7 @@ type RedirectToURLResult struct {
393393
}
394394

395395
func (r *RedirectToURLResult) Apply(req *Request, resp *Response) {
396-
resp.SetHeader("Location", r.url)
396+
resp.SetHttpHeader("Location", r.url)
397397
resp.WriteHeader(http.StatusFound, "")
398398
}
399399

@@ -408,7 +408,7 @@ func (r *RedirectToActionResult) Apply(req *Request, resp *Response) {
408408
ErrorResult{Error: err}.Apply(req, resp)
409409
return
410410
}
411-
resp.SetHeader("Location", url)
411+
resp.SetHttpHeader("Location", url)
412412
resp.WriteHeader(http.StatusFound, "")
413413
}
414414

router.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ var notFound = &RouteMatch{Action: "404"}
9595

9696
func (router *Router) Route(req *Request) *RouteMatch {
9797
// Override method if set in header
98-
if method := req.HttpHeaderValue("X-HTTP-Method-Override"); method != "" && req.Method == "POST" {
98+
if method := req.GetHttpHeader("X-HTTP-Method-Override"); method != "" && req.Method == "POST" {
9999
req.Method = method
100100
}
101101

util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func Equal(a, b interface{}) bool {
195195
func ClientIP(r *Request) string {
196196
if Config.BoolDefault("app.behind.proxy", false) {
197197
// Header X-Forwarded-For
198-
if fwdFor := strings.TrimSpace(r.HttpHeaderValue(hdrForwardedFor)); fwdFor != "" {
198+
if fwdFor := strings.TrimSpace(r.GetHttpHeader(hdrForwardedFor)); fwdFor != "" {
199199
index := strings.Index(fwdFor, ",")
200200
if index == -1 {
201201
return fwdFor
@@ -204,7 +204,7 @@ func ClientIP(r *Request) string {
204204
}
205205

206206
// Header X-Real-Ip
207-
if realIP := strings.TrimSpace(r.HttpHeaderValue(hdrRealIP)); realIP != "" {
207+
if realIP := strings.TrimSpace(r.GetHttpHeader(hdrRealIP)); realIP != "" {
208208
return realIP
209209
}
210210
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy