[GH-ISSUE #43] mime.types are not recognized properly #21

Closed
opened 2026-02-28 01:20:32 +03:00 by kerem · 1 comment
Owner

Originally created by @puzhengwu on GitHub (Mar 14, 2024).
Original GitHub issue: https://github.com/tufanbarisyildirim/gonginx/issues/43

package main

import (
"fmt"
"log"

"github.com/tufanbarisyildirim/gonginx/parser"

)

func main() {
p, err := parser.NewParser("/etc/nginx/nginx.conf", parser.WithIncludeParsing())
if err != nil {
log.Fatalln("parser", err)
}

c, err := p.Parse()
if err != nil {
	log.Fatalln("parser2", err)
}

directives := c.FindDirectives("server")

for _, block := range directives {
	for _, directive := range block.GetBlock().GetDirectives() {
		if directive.GetName() == "server_name" {
			fmt.Println(directive.GetName(), directive.GetParameters())
		}
	}
}

}

unknown directive 'text/html' on line 3, column 5

nginx.conf
#...
include /etc/nginx/mime.types;
#...

mime.types

types {
text/html html htm shtml;
....

Originally created by @puzhengwu on GitHub (Mar 14, 2024). Original GitHub issue: https://github.com/tufanbarisyildirim/gonginx/issues/43 package main import ( "fmt" "log" "github.com/tufanbarisyildirim/gonginx/parser" ) func main() { p, err := parser.NewParser("/etc/nginx/nginx.conf", parser.WithIncludeParsing()) if err != nil { log.Fatalln("parser", err) } c, err := p.Parse() if err != nil { log.Fatalln("parser2", err) } directives := c.FindDirectives("server") for _, block := range directives { for _, directive := range block.GetBlock().GetDirectives() { if directive.GetName() == "server_name" { fmt.Println(directive.GetName(), directive.GetParameters()) } } } } unknown directive 'text/html' on line 3, column 5 nginx.conf #... include /etc/nginx/mime.types; #... mime.types types { text/html html htm shtml; ....
kerem closed this issue 2026-02-28 01:20:33 +03:00
Author
Owner

@tufanbarisyildirim commented on GitHub (Feb 20, 2026):

Re-checked on current master and this is resolved now.

I reproduced your case with parser.NewParser(..., parser.WithIncludeParsing()) and an included mime.types file containing:

  • types { text/html ...; }

Parsing succeeds (no unknown directive text/html error).

Also verified parser tests pass on current code (go test ./parser).

Closing as fixed in current code. If you still hit this on latest code, please reopen with a minimal repro config and exact version/commit.

<!-- gh-comment-id:3932170475 --> @tufanbarisyildirim commented on GitHub (Feb 20, 2026): Re-checked on current `master` and this is resolved now. I reproduced your case with `parser.NewParser(..., parser.WithIncludeParsing())` and an included `mime.types` file containing: - `types { text/html ...; }` Parsing succeeds (no `unknown directive text/html` error). Also verified parser tests pass on current code (`go test ./parser`). Closing as fixed in current code. If you still hit this on latest code, please reopen with a minimal repro config and exact version/commit.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/gonginx#21
No description provided.