bootdotdev / bootdev

A CLI used to complete coding challenges and lessons on Boot.dev
https://www.boot.dev
MIT License
421 stars 16 forks source link

Response headers are not displayed #8

Open Demianeen opened 5 months ago

Demianeen commented 5 months ago

When I run bootdev cli I don't see headers. For example for routing lesson: CleanShot 2024-05-01 at 09 53 23@2x

I can see headers in any other rest clients. Also, the lesson submission does work.

CleanShot 2024-05-01 at 09 56 40@2x

cgsdev0 commented 5 months ago

we filter the headers to only show the ones being tested for

the behavior is kinda confusing, I will try to see if I can think of a way to make it more obvious 👍

Demianeen commented 5 months ago

Sure. As an idea, I think you can highlight the headers that are being tested

Waldeedle commented 5 months ago

image

Would something like this make sense? We iterate through the result headers and use lipgloss to style any matches from the expected headers as green otherwise output them as grey. Then we can also loop through the expected headers and output any missing ones as red.

        for k, v := range result.Headers {
            if req.Request.Headers[k] == v {
                fmt.Print(green.Render(fmt.Sprintf("   - %v: %v", k, v)) + "\n")
            } else {
                fmt.Printf(gray.Render(fmt.Sprintf("   - %v: %v", k, v)) + "\n")
            }
        }
        for k, v := range req.Request.Headers {
            if _, found := result.Headers[k]; !found {
                fmt.Printf(red.Render(fmt.Sprintf("   - %v: %v", k, v)) + "\n")
            }
        }
cgsdev0 commented 5 months ago

@Waldeedle that looks nice!

I'm going to rewrite the render functions for the HTTP tests soon to match the fancy ones we have for the commands now, I'll keep this idea in mind