Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions lib/solr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class Client {
private readonly COLLECTIONS_HANDLER: string;
private readonly SELECT_HANDLER: string;
private readonly undiciClient: UndiciClient;
private readonly url: string;

constructor(options: SolrClientParams = {}) {
this.options = {
Expand Down Expand Up @@ -115,9 +116,12 @@ export class Client {
: this.options.tls
? 'https://'
: 'http://';

// Build url with options provided. Ignore port and colon if options.port is not provided instead of
// creating invalid url. ie. https://solr.example.com:/solr
this.url = `${urlPrefix}${this.options.host}${this.options.port !== '' ? ':' + this.options.port : ''}`

this.undiciClient = new UndiciClient(
`${urlPrefix}${this.options.host}:${this.options.port}`,
this.url,
{
connect: this.options.tls,
}
Expand Down Expand Up @@ -171,8 +175,7 @@ export class Client {
bodyContentType: string | null,
acceptContentType: string
): Promise<T> {
const protocol = this.options.secure ? 'https' : 'http';
const url = `${protocol}://${this.options.host}:${this.options.port}${path}`;
const url = `${this.url}${path}`;
const requestOptions: UndiciRequestOptions = {
...this.options.request,
method,
Expand Down Expand Up @@ -321,11 +324,10 @@ export class Client {
};
if (this.options.authorization) {
headers['authorization'] = this.options.authorization;
}
const protocol = this.options.secure ? 'https' : 'http';
}
const url = `${this.url}${path}`;
const optionsRequest = {
url:
protocol + '://' + this.options.host + ':' + this.options.port + path,
url,
method: 'POST',
headers: headers,
};
Expand Down Expand Up @@ -562,8 +564,8 @@ export class Client {
1 +
Buffer.byteLength(queryString);
const method =
this.options.get_max_request_entity_size === false ||
approxUrlLength <= this.options.get_max_request_entity_size
this.options.get_max_request_entity_size === false ||
(typeof this.options.get_max_request_entity_size === 'number' && approxUrlLength <= this.options.get_max_request_entity_size)
? 'GET'
: 'POST';

Expand Down