|
53 | 53 | ExtDeflateThreshold* = 1024 |
54 | 54 | ExtDeflateDecompressLimit* = 10 shl 20 # 10mb |
55 | 55 |
|
| 56 | +proc destroyExt(ext: DeflateExt) = |
| 57 | + if ext.compCtxState != ContextState.Invalid: |
| 58 | + # zlib.deflateEnd somehow return DATA_ERROR |
| 59 | + # when compression succeed some cases. |
| 60 | + # we forget to do something? |
| 61 | + discard ext.compCtx.deflateEnd() |
| 62 | + ext.compCtxState = ContextState.Invalid |
| 63 | + |
| 64 | + if ext.decompCtxState != ContextState.Invalid: |
| 65 | + doAssert(ext.decompCtx.inflateEnd() == Z_OK) |
| 66 | + ext.decompCtxState = ContextState.Invalid |
| 67 | + |
| 68 | +# Need to be declared early and not be generic to work with ARC/ORC |
| 69 | +proc newDeflateExt: DeflateExt = |
| 70 | + result.new(destroyExt) |
| 71 | + |
56 | 72 | proc concatParam(resp: var string, param: string) = |
57 | 73 | resp.add "; " |
58 | 74 | resp.add param |
@@ -327,18 +343,6 @@ method toHttpOptions(ext: DeflateExt): string = |
327 | 343 | # using paramStr here is a bit clunky |
328 | 344 | extID & ext.paramStr |
329 | 345 |
|
330 | | -proc destroyExt(ext: DeflateExt) = |
331 | | - if ext.compCtxState != ContextState.Invalid: |
332 | | - # zlib.deflateEnd somehow return DATA_ERROR |
333 | | - # when compression succeed some cases. |
334 | | - # we forget to do something? |
335 | | - discard ext.compCtx.deflateEnd() |
336 | | - ext.compCtxState = ContextState.Invalid |
337 | | - |
338 | | - if ext.decompCtxState != ContextState.Invalid: |
339 | | - doAssert(ext.decompCtx.inflateEnd() == Z_OK) |
340 | | - ext.decompCtxState = ContextState.Invalid |
341 | | - |
342 | 346 | proc makeOffer( |
343 | 347 | clientNoContextTakeOver: bool, |
344 | 348 | clientMaxWindowBits: int): string = |
@@ -380,8 +384,7 @@ proc deflateFactory*( |
380 | 384 | if resp.isErr: |
381 | 385 | return err(resp.error) |
382 | 386 |
|
383 | | - var ext: DeflateExt |
384 | | - ext.new(destroyExt) |
| 387 | + var ext = newDeflateExt() |
385 | 388 | ext.name = extID |
386 | 389 | ext.paramStr = resp.get() |
387 | 390 | ext.opts = opts |
|
0 commit comments