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

Expose full response headers object #288

Merged
merged 2 commits into from
Jul 8, 2024
Merged

Conversation

slvrtrn
Copy link
Contributor

@slvrtrn slvrtrn commented Jul 5, 2024

Summary

It is now possible to get the entire response headers object from the query/insert/command/exec methods. With query, you can access the ResultSet.response_headers property; other methods (insert/command/exec) return it as parts of their response objects as well.

For example:

const rs = await client.query({
  query: 'SELECT * FROM system.numbers LIMIT 1',
  format: 'JSONEachRow',
})
console.log(rs.response_headers['content-type'])

This will print: application/x-ndjson; charset=UTF-8. It can be used in a similar way with the other methods.

Checklist

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG
  • For significant changes, documentation in https://github.com/ClickHouse/clickhouse-docs was updated with further explanations or tutorials

Copy link

sonarcloud bot commented Jul 5, 2024

@@ -69,15 +71,16 @@ export class WebConnection implements Connection<ReadableStream> {
return {
query_id: result.query_id,
stream: result.stream || new ReadableStream<Uint8Array>(),
response_headers: result.response_headers,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the first HTTP abstraction that leaks in the result set. I'd rather add some generic method to avoid a breaking change once TCP protocol is supported, but your call

Copy link
Contributor Author

@slvrtrn slvrtrn Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is already leaking a bit, as we allow text/json calls, which are not very compatible with Native and even RowBinary format; in time, we will likely have to implement the native version with a new result set flavor (similarly to RowBinary).

@slvrtrn slvrtrn merged commit 30ce583 into main Jul 8, 2024
29 checks passed
@slvrtrn slvrtrn deleted the expose-full-response-headers branch July 8, 2024 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants