mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-10-30 18:22:49 -04:00 
			
		
		
		
	httpserver: rename context Push action for more general use (#1641)
Signed-off-by: Tw <tw19881113@gmail.com>
This commit is contained in:
		
							parent
							
								
									8e7a36de45
								
							
						
					
					
						commit
						e38921f4a5
					
				| @ -424,12 +424,13 @@ func (c Context) RandomString(minLen, maxLen int) string { | |||||||
| 	return string(result) | 	return string(result) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Push adds a preload link in response header for server push | // AddLink adds a link header in response | ||||||
| func (c Context) Push(link string) string { | // see https://www.w3.org/wiki/LinkHeader | ||||||
|  | func (c Context) AddLink(link string) string { | ||||||
| 	if c.responseHeader == nil { | 	if c.responseHeader == nil { | ||||||
| 		return "" | 		return "" | ||||||
| 	} | 	} | ||||||
| 	c.responseHeader.Add("Link", "<"+link+">; rel=preload") | 	c.responseHeader.Add("Link", link) | ||||||
| 	return "" | 	return "" | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -877,18 +877,18 @@ func TestFiles(t *testing.T) { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestPush(t *testing.T) { | func TestAddLink(t *testing.T) { | ||||||
| 	for name, c := range map[string]struct { | 	for name, c := range map[string]struct { | ||||||
| 		input       string | 		input       string | ||||||
| 		expectLinks []string | 		expectLinks []string | ||||||
| 	}{ | 	}{ | ||||||
| 		"oneLink": { | 		"oneLink": { | ||||||
| 			input:       `{{.Push "/test.css"}}`, | 			input:       `{{.AddLink "</test.css>; rel=preload"}}`, | ||||||
| 			expectLinks: []string{"</test.css>; rel=preload"}, | 			expectLinks: []string{"</test.css>; rel=preload"}, | ||||||
| 		}, | 		}, | ||||||
| 		"multipleLinks": { | 		"multipleLinks": { | ||||||
| 			input:       `{{.Push "/test1.css"}} {{.Push "/test2.css"}}`, | 			input:       `{{.AddLink "</test1.css>; rel=preload"}} {{.AddLink "</test2.css>; rel=meta"}}`, | ||||||
| 			expectLinks: []string{"</test1.css>; rel=preload", "</test2.css>; rel=preload"}, | 			expectLinks: []string{"</test1.css>; rel=preload", "</test2.css>; rel=meta"}, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} { | ||||||
| 		c := c | 		c := c | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user