File tree Expand file tree Collapse file tree 6 files changed +31
-13
lines changed Expand file tree Collapse file tree 6 files changed +31
-13
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,17 @@ Deno.test('scrapeconfig POST/PUT/PATCH body defaults as content-type text/plain'
65
65
assertEquals ( config . body , 'foo+bar' ) ;
66
66
} ) ;
67
67
68
+ Deno . test ( 'scrapeconfig POST/PUT/PATCH body does not override content-type when set' , async ( ) => {
69
+ const config = new ScrapeConfig ( {
70
+ url : 'http://httpbin.dev/get' ,
71
+ method : 'POST' ,
72
+ body : 'foo+bar' ,
73
+ headers : { 'content-type' : 'application/json' } ,
74
+ } ) ;
75
+ assertEquals ( ( config . headers || { } ) [ 'content-type' ] , 'application/json' ) ;
76
+ assertEquals ( config . body , 'foo+bar' ) ;
77
+ } ) ;
78
+
68
79
Deno . test ( 'scrapeconfig POST/PUT/PATCH data encodes when formdata content-type is set' , async ( ) => {
69
80
const config = new ScrapeConfig ( {
70
81
url : 'http://httpbin.dev/get' ,
Original file line number Diff line number Diff line change 4
4
},
5
5
"name" : " @scrapfly/scrapfly-sdk" ,
6
6
"exports" : " ./src/main.ts" ,
7
- "version" : " 0.6.7 " ,
7
+ "version" : " 0.6.8 " ,
8
8
"description" : " SDK for Scrapfly.io API for web scraping, screenshotting and data extraction" ,
9
9
"tasks" : {
10
10
"start" : " deno run --allow-net --allow-read src/main.ts" ,
Original file line number Diff line number Diff line change @@ -122,12 +122,12 @@ export class ScrapflyClient {
122
122
content = await response . text ( ) ;
123
123
result . format = 'text' ;
124
124
}
125
-
125
+
126
126
if ( format === 'blob' ) {
127
127
content = new Uint8Array ( await response . arrayBuffer ( ) ) ;
128
128
result . format = 'binary' ;
129
129
}
130
-
130
+
131
131
result . content = content ;
132
132
return result ;
133
133
}
Original file line number Diff line number Diff line change @@ -45,9 +45,14 @@ export class ExtractionConfig {
45
45
46
46
constructor ( options : ExtractionConfigOptions ) {
47
47
this . validateOptions ( options ) ;
48
- if ( options . document_compression_format && ! Object . values ( CompressionFormat ) . includes ( options . document_compression_format as CompressionFormat ) ) {
49
- throw new errors . ExtractionConfigError ( `Invalid CompressionFormat param value: ${ options . document_compression_format } ` ) ;
50
- }
48
+ if (
49
+ options . document_compression_format &&
50
+ ! Object . values ( CompressionFormat ) . includes ( options . document_compression_format as CompressionFormat )
51
+ ) {
52
+ throw new errors . ExtractionConfigError (
53
+ `Invalid CompressionFormat param value: ${ options . document_compression_format } ` ,
54
+ ) ;
55
+ }
51
56
this . body = options . body ;
52
57
this . content_type = options . content_type ;
53
58
this . url = options . url ?? this . url ;
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ export enum Format {
38
38
export enum FormatOption {
39
39
NO_LINKS = 'no_links' ,
40
40
NO_IMAGES = 'no_images' ,
41
- ONLY_CONTENT = 'only_content'
41
+ ONLY_CONTENT = 'only_content' ,
42
42
}
43
43
44
44
type ScrapeConfigOptions = {
@@ -70,7 +70,8 @@ type ScrapeConfigOptions = {
70
70
rendering_wait ?: number ;
71
71
wait_for_selector ?: string ;
72
72
screenshots ?: Rec < any > ;
73
- screenshot_flags ?: ( 'load_images' | 'dark_mode' | 'block_banners' | 'print_media_format' | 'high_quality' | ScreenshotFlags ) [ ] ;
73
+ screenshot_flags ?:
74
+ ( 'load_images' | 'dark_mode' | 'block_banners' | 'print_media_format' | 'high_quality' | ScreenshotFlags ) [ ] ;
74
75
session_sticky_proxy ?: boolean ;
75
76
webhook ?: string ;
76
77
timeout ?: number ;
@@ -113,7 +114,8 @@ export class ScrapeConfig {
113
114
wait_for_selector ?: string ;
114
115
session_sticky_proxy = false ;
115
116
screenshots ?: Rec < any > ;
116
- screenshot_flags ?: ( 'load_images' | 'dark_mode' | 'block_banners' | 'print_media_format' | 'high_quality' | ScreenshotFlags ) [ ] ;
117
+ screenshot_flags ?:
118
+ ( 'load_images' | 'dark_mode' | 'block_banners' | 'print_media_format' | 'high_quality' | ScreenshotFlags ) [ ] ;
117
119
webhook ?: string ;
118
120
timeout ?: number ; // in milliseconds
119
121
js_scenario ?: Rec < any > ;
@@ -202,7 +204,7 @@ export class ScrapeConfig {
202
204
) ;
203
205
}
204
206
}
205
- } else if ( this . body && ! this . data ) {
207
+ } else if ( this . body && ! this . data && ! this . headers [ 'content-type' ] ) {
206
208
this . headers [ 'content-type' ] = 'text/plain' ;
207
209
}
208
210
}
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ export enum Format {
34
34
35
35
type ScreenshotConfigOptions = {
36
36
url : string ;
37
- format ?: 'jpg' | 'png' | 'webp' | 'gif' | Format ;
37
+ format ?: 'jpg' | 'png' | 'webp' | 'gif' | Format ;
38
38
capture ?: string ;
39
39
resolution ?: string ;
40
40
country ?: string ;
@@ -52,7 +52,7 @@ type ScreenshotConfigOptions = {
52
52
53
53
export class ScreenshotConfig {
54
54
url : string ;
55
- format ?: 'jpg' | 'png' | 'webp' | 'gif' | Format ;
55
+ format ?: 'jpg' | 'png' | 'webp' | 'gif' | Format ;
56
56
capture ?: string ;
57
57
resolution ?: string ;
58
58
country ?: string = undefined ;
@@ -79,7 +79,7 @@ export class ScreenshotConfig {
79
79
throw new ScreenshotConfigError ( `Invalid Options param value: ${ opt } ` ) ;
80
80
}
81
81
} ) ;
82
- }
82
+ }
83
83
this . url = options . url ;
84
84
this . format = options . format ?? this . format ;
85
85
this . capture = options . capture ?? this . capture ;
You can’t perform that action at this time.
0 commit comments