File tree Expand file tree Collapse file tree 3 files changed +61
-8
lines changed Expand file tree Collapse file tree 3 files changed +61
-8
lines changed Original file line number Diff line number Diff line change @@ -15,14 +15,15 @@ export class HttpsCheckHook implements SDKInitHook {
15
15
sdkInit ( opts : SDKInitOptions ) : SDKInitOptions {
16
16
const { baseURL, client } = opts ;
17
17
18
- if (
19
- baseURL &&
20
- BASE_HOSTNAME_REGEX . test ( baseURL . hostname ) &&
21
- baseURL . protocol !== BASE_PROTOCOL
22
- ) {
23
- console . warn ( "Base URL protocol is not HTTPS. Updating to HTTPS." ) ;
24
- const newBaseURL = baseURL . href . replace ( baseURL . protocol , BASE_PROTOCOL ) ;
25
- return { baseURL : new URL ( newBaseURL ) , client : client } ;
18
+ if ( baseURL ) {
19
+ // -- pathname should always be empty
20
+ baseURL . pathname = "/" ;
21
+
22
+ if ( BASE_HOSTNAME_REGEX . test ( baseURL . hostname ) && baseURL . protocol !== BASE_PROTOCOL ) {
23
+ console . warn ( "Base URL protocol is not HTTPS. Updating to HTTPS." ) ;
24
+ const newBaseURL = baseURL . href . replace ( baseURL . protocol , BASE_PROTOCOL ) ;
25
+ return { baseURL : new URL ( newBaseURL ) , client : client } ;
26
+ }
26
27
}
27
28
28
29
return { baseURL : baseURL , client : client } ;
Original file line number Diff line number Diff line change
1
+ import { readFileSync } from "fs" ;
2
+
3
+ import { UnstructuredClient } from "../../src" ;
4
+ import { PartitionResponse } from "../../src/sdk/models/operations" ;
5
+ import { PartitionParameters , Strategy } from "../../src/sdk/models/shared" ;
6
+
7
+ describe ( "HttpsCheckHook integration tests" , ( ) => {
8
+ const FAKE_API_KEY = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ;
9
+
10
+ it . each ( [
11
+ "http://localhost:8000" ,
12
+ "http://localhost:8000/general/v0/general" ,
13
+ ] ) ( "should throw error when given filename is empty" , async ( serverURL ) => {
14
+ const client = new UnstructuredClient ( {
15
+ serverURL : serverURL ,
16
+ security : {
17
+ apiKeyAuth : FAKE_API_KEY ,
18
+ } ,
19
+ } ) ;
20
+
21
+ const file = {
22
+ content : readFileSync ( "test/data/layout-parser-paper-fast.pdf" ) ,
23
+ fileName : "test/data/layout-parser-paper-fast.pdf" ,
24
+ } ;
25
+
26
+ const requestParams : PartitionParameters = {
27
+ files : file ,
28
+ strategy : Strategy . Fast ,
29
+ } ;
30
+
31
+ const res : PartitionResponse = await client . general . partition ( {
32
+ partitionParameters : {
33
+ ...requestParams ,
34
+ splitPdfPage : false ,
35
+ } ,
36
+ } ) ;
37
+
38
+ expect ( res . statusCode ) . toEqual ( 200 ) ;
39
+ } ) ;
40
+ } ) ;
Original file line number Diff line number Diff line change @@ -61,4 +61,16 @@ describe("HttpsCheckHook", () => {
61
61
expect ( result . baseURL ) . toBeNull ( ) ;
62
62
expect ( consoleSpy ) . not . toHaveBeenCalled ( ) ;
63
63
} ) ;
64
+
65
+ it ( "should update the pathname to empty" , ( ) => {
66
+ const baseURL = new URL ( "https://example.unstructuredapp.io/general/v0/general" ) ;
67
+ const client = new HTTPClient ( ) ;
68
+ const opts = { baseURL, client } ;
69
+ const hook = new HttpsCheckHook ( ) ;
70
+
71
+ const result = hook . sdkInit ( opts ) ;
72
+
73
+ expect ( result . baseURL ?. pathname ) . toBe ( "/" ) ;
74
+ expect ( consoleSpy ) . not . toHaveBeenCalled ( ) ;
75
+ } ) ;
64
76
} ) ;
You can’t perform that action at this time.
0 commit comments