Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display http headers #290

Open
CaptainQuirk opened this issue Feb 27, 2024 · 8 comments · May be fixed by #297
Open

Display http headers #290

CaptainQuirk opened this issue Feb 27, 2024 · 8 comments · May be fixed by #297
Labels
feature New feature or request

Comments

@CaptainQuirk
Copy link

Hi,

Thanks for fx ! It's a great tool to explore json without leaving the terminal.

I guess this is a bit out of scope (and possibly complicated to achieve) but I think it would be great to be able to pipe the result of a curl request with the -i flag to fx and have the headers displayed at the top of the viewport.

Thanks for your time !

@antonmedv
Copy link
Owner

curl -i https://medv.io | fx -rs | fx

@CaptainQuirk
Copy link
Author

Hi,

Thank you for your quick response !

There may have been a misunderstanding because the command you proposed returns a json array of headers, which is not what I had in mind

I was wondering if the current fx viewport could contain :

  • HTTP Headers at the top, possibly with syntax highlighting and the yanking feature
  • Json data right underneath, explorable like it is now

Something like the following :

HTTP/1.1 200 OK
Content-Length: 11910

{
  "result": {      }
}

@antonmedv
Copy link
Owner

I see. I nice idea but I'm not sure how to be able to detect those kinds of headers. It should be integrated into our json parser which will be tricky.

@CaptainQuirk
Copy link
Author

I'm not aware of the component you use for the presentation layer, nor of the global architecture of fx, but maybe it means that the viewport has to be composed of two different parts, one dedicated to json with its attached parser (jq ?) and an optional one for headers ?

@antonmedv
Copy link
Owner

Problem is not with displaying the headers. Problem is with parsing them. How to distinguish them from JSON? Or invalid JSON?

@CaptainQuirk
Copy link
Author

Wouldn't a regular expression help to determine that the given data is the combination of http headers and a body separated by a null line, like it's stipulated in rfc1945 section-4.1 ?
In any case, if the regular expression is not the way to go, wouldn't an additionnal flag do the trick ?
What about an --http flag that instructs fx that the given data is indeed http ?

@antonmedv
Copy link
Owner

I guess we can add a custom parser which checks if a first line is from curl, and starts parsing headers.

HTTP/1.1 200 OK

Would you like to try to implement such a feature? Note parser should be implemented in both Go parser and JS parser:

fx/json.go

Line 20 in 1952074

func parse(data []byte) (head *node, err error) {

fx/npm/index.js

Line 272 in 1952074

function* parseJson(gen) {

@antonmedv antonmedv added the feature New feature or request label Mar 4, 2024
@CaptainQuirk
Copy link
Author

Hi !

I have no notion of Go whatsoever unfortunately

@alexkunin alexkunin linked a pull request Mar 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants